/* ==========================================================================
   Ovaj plugin ne namece sopstvene boje/font - koristi CSS varijable koje
   izlaze Blocksy tema (--theme-palette-color-1, -2, -3...), sa fallback
   vrednostima u slucaju da tema/varijable nisu dostupne (npr. druga tema).
   Font se nasledjuje (inherit) od teme.

   CSS je organizovan "mobile-first": osnovna pravila vaze za mali ekran,
   a media query na kraju (min-width: 640px) dodaje raspored za desktop/tablet.
   ========================================================================== */

.tl-app,
.tl-app * {
    box-sizing: border-box;
}

.tl-app {
    max-width: 720px;
    margin: 0 auto;
    font-family: inherit;
    color: inherit;
    width: 100%;
}

.tl-heading {
    margin-top: 1.3em;
    margin-bottom: 0.6em;
    font-family: inherit;
    color: inherit;
}

.tl-heading-log {
    border-top: 1px solid var(--theme-border-color, rgba(0, 0, 0, 0.12));
    padding-top: 1.2em;
}

.tl-filter-bar {
    display: flex;
    flex-direction: column;
    gap: 0.7em;
    margin-bottom: 1.2em;
    padding: 0.8em;
    background: var(--theme-palette-color-8, rgba(0, 0, 0, 0.02));
    border: 1px solid var(--theme-border-color, rgba(0, 0, 0, 0.12));
    border-radius: var(--theme-input-border-radius, 6px);
}

.tl-filter-field {
    display: flex;
    flex-direction: column;
}

.tl-filter-field label {
    font-weight: 600;
    font-size: 0.85em;
    margin-bottom: 0.3em;
}

.tl-filter-field input[type="date"] {
    padding: 0.6em;
    border: 1px solid var(--theme-border-color, rgba(0, 0, 0, 0.2));
    border-radius: var(--theme-input-border-radius, 4px);
    font-family: inherit;
    font-size: 16px;
    color: inherit;
    background: transparent;
    width: 100%;
    box-sizing: border-box;
}

.tl-filter-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.6em;
}

.tl-filter-actions .tl-btn {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    white-space: nowrap;
    text-align: center;
    box-sizing: border-box;
}

.tl-intro-help {
    margin: 0 0 1.2em;
    padding: 0.7em 0.9em;
    font-size: 0.9em;
    line-height: 1.5;
    background: var(--theme-palette-color-8, rgba(0, 0, 0, 0.03));
    border-left: 3px solid var(--theme-palette-color-3, var(--theme-palette-color-1, #2271b1));
    border-radius: 0 var(--theme-input-border-radius, 4px) var(--theme-input-border-radius, 4px) 0;
}

.tl-editing-notice {
    margin: 0 0 1.2em;
    padding: 0.7em 0.9em;
    font-size: 0.9em;
    font-weight: 600;
    line-height: 1.5;
    background: rgba(255, 193, 7, 0.15);
    border-left: 3px solid #b8860b;
    border-radius: 0 var(--theme-input-border-radius, 4px) var(--theme-input-border-radius, 4px) 0;
}

.tl-field {
    margin-bottom: 1em;
    display: flex;
    flex-direction: column;
    max-width: 100%;
}

.tl-field label {
    font-weight: 600;
    margin-bottom: 0.4em;
}

.tl-field input[type="date"] {
    padding: 0.7em 0.6em;
    border: 1px solid var(--theme-border-color, rgba(0, 0, 0, 0.2));
    border-radius: var(--theme-input-border-radius, 4px);
    font-family: inherit;
    font-size: 16px; /* sprečava automatski zoom na iPhone-u pri fokusu */
    color: inherit;
    background: transparent;
    width: 100%;
    max-width: 260px;
}

.tl-exercise-block {
    border: 1px solid var(--theme-border-color, rgba(0, 0, 0, 0.12));
    border-left: 4px solid #6b7280;
    border-radius: var(--theme-input-border-radius, 6px);
    padding: 0.9em;
    margin-bottom: 1em;
    background: var(--theme-palette-color-8, rgba(0, 0, 0, 0.02));
}

.tl-exercise-index {
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    opacity: 0.55;
    margin-bottom: 0.5em;
}

.tl-exercise-header {
    display: flex;
    flex-direction: column;
    gap: 0.5em;
    margin-bottom: 0.8em;
    align-items: stretch;
}

.tl-exercise-name-wrap {
    position: relative;
    width: 100%;
}

.tl-exercise-name {
    width: 100%;
    padding: 0.7em 0.6em;
    border: 2px solid var(--theme-border-color, rgba(0, 0, 0, 0.2));
    border-radius: var(--theme-input-border-radius, 4px);
    font-size: 16px;
    font-family: inherit;
    color: inherit;
    background: var(--theme-palette-color-8, #fff);
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.tl-exercise-name-status {
    display: none;
    margin-top: 0.35em;
    font-size: 0.85em;
    font-weight: 600;
}

.tl-exercise-name-wrap.tl-exercise-name-matched .tl-exercise-name {
    border-color: #2a7a2a;
    background: rgba(42, 122, 42, 0.06);
}

.tl-exercise-name-wrap.tl-exercise-name-matched .tl-exercise-name-status {
    display: block;
    color: #2a7a2a;
}

.tl-exercise-name-wrap.tl-exercise-name-new .tl-exercise-name {
    border-color: #1a56db;
    background: rgba(26, 86, 219, 0.06);
}

.tl-exercise-name-wrap.tl-exercise-name-new .tl-exercise-name-status {
    display: block;
    color: #1a56db;
}

/* Prilagođeni padajući meni sa pretragom za izbor vežbe (zamena za native
   <datalist>, koji se nepouzdano prikazuje kao pravi popup na mobilnim
   uređajima). Ponaša se isto na telefonu i na desktopu. */
.tl-exercise-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 50;
    margin-top: 4px;
    max-height: 280px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--theme-palette-color-8, #fff);
    border: 1px solid var(--theme-border-color, rgba(0, 0, 0, 0.2));
    border-radius: var(--theme-input-border-radius, 4px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.tl-exercise-dropdown.tl-exercise-dropdown-open {
    display: block;
}

.tl-exercise-dropdown-item {
    padding: 0.8em;
    min-height: 44px;
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 16px;
    border-bottom: 1px solid var(--theme-border-color, rgba(0, 0, 0, 0.06));
}

.tl-exercise-dropdown-item:last-child {
    border-bottom: none;
}

.tl-exercise-dropdown-item:hover,
.tl-exercise-dropdown-item.tl-exercise-dropdown-item-active {
    background: rgba(0, 0, 0, 0.07);
}

.tl-exercise-dropdown-empty {
    padding: 0.8em;
    font-size: 0.9em;
    opacity: 0.7;
    font-style: italic;
}

/* Tabela serija - na uskom ekranu dozvoljavamo horizontalno skrolovanje
   umesto stiskanja kolona, tako da polja za unos ostanu dovoljno velika
   za dodir prstom. */
.tl-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0.6em;
}

.tl-exercise-type-field {
    margin-bottom: 0.8em;
    max-width: 100%;
}

.tl-exercise-type-field > label {
    font-weight: 600;
    display: block;
    margin-bottom: 0.4em;
    font-size: 0.9em;
}

.tl-type-pills {
    display: flex;
    gap: 0.5em;
}

.tl-type-pill {
    flex: 1 1 0;
    min-width: 0;
    position: relative;
    cursor: pointer;
    margin: 0;
}

.tl-type-pill input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    margin: 0;
}

.tl-type-pill span {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 48px;
    padding: 0.4em 0.3em;
    border: 2px solid var(--theme-border-color, rgba(0, 0, 0, 0.2));
    border-radius: var(--theme-input-border-radius, 4px);
    font-size: 0.82em;
    font-weight: 600;
    line-height: 1.25;
    color: inherit;
    background: var(--theme-palette-color-8, #fff);
    transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

@media (max-width: 380px) {
    .tl-type-pill span {
        font-size: 0.72em;
        padding: 0.4em 0.15em;
    }

    .tl-filter-actions .tl-btn {
        font-size: 0.85em;
        padding: 0.6em 0.4em;
    }
}

.tl-type-pill input[type="radio"]:checked + span {
    border-color: var(--theme-palette-color-3, var(--theme-palette-color-1, #2271b1));
    background: var(--theme-palette-color-3, var(--theme-palette-color-1, #2271b1));
    color: var(--theme-palette-color-8, #fff);
}

.tl-type-pill input[type="radio"]:focus-visible + span {
    outline: 2px solid var(--theme-palette-color-3, var(--theme-palette-color-1, #2271b1));
    outline-offset: 2px;
}

.tl-sets-table {
    width: 100%;
    min-width: 360px;
    border-collapse: collapse;
    font-family: inherit;
    color: inherit;
}

.tl-sets-table th,
.tl-sets-table td {
    text-align: left;
    padding: 0.45em 0.4em;
    border-bottom: 1px solid var(--theme-border-color, rgba(0, 0, 0, 0.08));
}

.tl-sets-table th {
    font-size: 0.85em;
    opacity: 0.75;
    white-space: nowrap;
}

.tl-sets-table input {
    width: 100%;
    min-width: 70px;
    box-sizing: border-box;
    padding: 0.55em 0.4em;
    border: 1px solid var(--theme-border-color, rgba(0, 0, 0, 0.2));
    border-radius: var(--theme-input-border-radius, 4px);
    font-family: inherit;
    font-size: 16px;
    color: inherit;
    background: transparent;
}

.tl-set-number {
    text-align: center;
    font-weight: 600;
    white-space: nowrap;
}

/* --------------------------------------------------------------------
   Dugmad koriste Blocksy CSS varijable za akcentnu boju (fallback plava
   ako varijable nisu dostupne - npr. druga tema). Minimalna visina 44px
   radi lakšeg dodira na telefonu.
   -------------------------------------------------------------------- */
.tl-btn {
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: var(--theme-button-border-radius, 4px);
    padding: 0.7em 1em;
    font-size: 0.95em;
    font-family: inherit;
    min-height: 44px;
    width: 100%;
}

.tl-btn-small {
    padding: 0.5em 0.8em;
    font-size: 0.85em;
    min-height: 38px;
    width: auto;
    margin-left: 0;
}

.tl-btn-primary {
    background: var(--theme-palette-color-3, var(--theme-palette-color-1, #2271b1));
    color: var(--theme-palette-color-8, #fff);
}

.tl-btn-secondary {
    background: transparent;
    color: inherit;
    border-color: var(--theme-border-color, rgba(0, 0, 0, 0.25));
}

/* "Dodaj vežbu" - ista boja kao akcentna leva ivica bloka vežbe, da se
   vizuelno jasno razlikuje od "Dodaj seriju" (koje ostaje standardno/sivo). */
.tl-btn-accent {
    background: #6b7280;
    color: #fff;
    border-color: #6b7280;
}

.tl-btn-danger {
    background: transparent;
    color: #d63638;
    border-color: #d63638;
}

.tl-actions {
    margin-top: 1em;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.7em;
}

#tl-save-status {
    font-style: italic;
    opacity: 0.75;
    text-align: center;
}

.tl-log-card {
    border: 1px solid var(--theme-border-color, rgba(0, 0, 0, 0.12));
    border-radius: var(--theme-input-border-radius, 6px);
    margin-bottom: 0.8em;
    overflow: hidden;
}

.tl-log-card-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.6em;
    padding: 0.8em 1em;
    background: var(--theme-palette-color-8, rgba(0, 0, 0, 0.02));
}

.tl-log-card-actions {
    display: flex;
    gap: 0.5em;
    white-space: nowrap;
}

.tl-log-card-actions .tl-btn-small {
    flex: 1;
}

.tl-log-card-details {
    padding: 1em;
    border-top: 1px solid var(--theme-border-color, rgba(0, 0, 0, 0.08));
}

.tl-log-card-details .tl-table-wrap {
    margin-bottom: 1em;
}

.tl-summary {
    font-size: 0.9em;
}

.tl-muted {
    opacity: 0.65;
}

.tl-notice {
    padding: 1em;
    background: rgba(255, 193, 7, 0.15);
    border: 1px solid rgba(255, 193, 7, 0.5);
    border-radius: var(--theme-input-border-radius, 4px);
}

/* ==========================================================================
   Od ovde na dalje - raspored za veće ekrane (tablet/desktop). Ispod ove
   širine sve ostaje puna širina i naslagano jedno ispod drugog (mobile-first
   pravila iznad), što je najčitljivije na telefonu.
   ========================================================================== */
@media (min-width: 640px) {
    .tl-exercise-header {
        flex-direction: row;
        align-items: flex-start;
    }

    .tl-exercise-header .tl-exercise-name-wrap {
        flex: 1;
    }

    .tl-exercise-header .tl-remove-exercise,
    .tl-exercise-block .tl-add-set {
        width: auto;
    }

    .tl-btn {
        width: auto;
    }

    .tl-actions {
        flex-direction: row;
        align-items: center;
    }

    .tl-actions #tl-save {
        width: auto;
    }

    #tl-save-status {
        text-align: left;
    }

    .tl-log-card-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .tl-log-card-actions {
        white-space: nowrap;
    }

    .tl-filter-bar {
        flex-direction: row;
        align-items: flex-end;
    }

    .tl-filter-field {
        flex: 1;
    }

    .tl-filter-actions {
        flex: 1;
    }

    .tl-log-card-actions .tl-btn-small {
        flex: none;
    }
}

/* ------------------------------------------------------------------
 * Dashboard: header with key numbers, tabs, filters, progress, switches
 * ------------------------------------------------------------------ */
.tl-dash { --tl-primary: var(--theme-palette-color-1, #2872fa); --tl-hero: var(--theme-palette-color-4, #173963); --tl-accent: #4ade80; --tl-line: var(--theme-border-color, rgba(0,0,0,.12)); --tl-soft: var(--theme-palette-color-8, rgba(0,0,0,.03)); --tl-muted: var(--theme-text-color-muted, #6b7280); --tl-focus: 0 0 0 3px color-mix(in srgb, var(--tl-primary) 35%, transparent); }
.tl-dash :focus-visible { outline: none; box-shadow: var(--tl-focus); border-radius: 6px; }
.tl-dash .screen-reader-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tl-dash .is-hidden, .tl-dash [hidden] { display: none !important; }
.tl-hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 18px; padding: 22px 24px; border-radius: var(--theme-card-border-radius, 14px); background: var(--tl-hero); color: #fff; margin-bottom: 16px; position: relative; overflow: hidden; }
.tl-hero::after { content: ""; position: absolute; right: -70px; top: -90px; width: 240px; height: 240px; border-radius: 50%; background: var(--tl-accent); opacity: .14; pointer-events: none; }
.tl-hero__main { position: relative; z-index: 1; display: flex; flex-direction: column; justify-content: center; }
.tl-hero__number { font-size: 3em; font-weight: 800; line-height: 1; color: var(--tl-accent); }
.tl-hero__label { opacity: .9; margin-top: 4px; }
.tl-hero__last { font-size: .88em; opacity: .85; margin-top: 8px; }
.tl-hero__stats { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; align-content: center; }
.tl-hero__stat { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.16); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; min-width: 0; }
.tl-hero__stat strong { font-size: 1.4em; line-height: 1.1; }
.tl-hero__stat span { font-size: .78em; opacity: .85; line-height: 1.3; }
.tl-tabs { display: flex; gap: 6px; padding: 6px; margin: 0 0 14px; border: 1px solid var(--tl-line); border-radius: 12px; background: var(--theme-background-color, #fff); overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tl-tabs::-webkit-scrollbar { display: none; }
.tl-tab { flex: 0 0 auto; appearance: none; border: 0; background: transparent; color: inherit; font: inherit; font-weight: 600; font-size: .95em; padding: 9px 16px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.tl-tab:hover { background: var(--tl-soft); }
.tl-tab.is-active { background: var(--tl-primary); color: #fff; }
.tl-panel { animation: tl-fade .18s ease; }
@keyframes tl-fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.tl-dash .tl-heading { margin-top: 0; }
.tl-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin: 0 0 10px; }
.tl-toolbar .tl-filter-field { margin: 0; }
.tl-search { flex: 1 1 200px; }
.tl-search--wide { display: block; max-width: 340px; margin-bottom: 12px; }
.tl-search input, .tl-select select { width: 100%; font: inherit; font-size: .95em; padding: 9px 12px; border: 1px solid var(--tl-line); border-radius: 999px; background: var(--theme-background-color, #fff); color: inherit; min-height: 42px; }
.tl-select select { width: auto; }
.tl-summary { font-size: .9em; color: var(--tl-muted); margin: 0 0 10px; }
.tl-pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.tl-pager__info { font-size: .88em; color: var(--tl-muted); }
.tl-pager .tl-btn[disabled] { opacity: .45; cursor: default; }
.tl-log-card--compact .tl-summary { display: none; }
.tl-switch { display: flex; align-items: center; gap: 12px; cursor: pointer; position: relative; padding: 12px 0; border-bottom: 1px solid var(--tl-line); }
.tl-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tl-switch__track { width: 40px; height: 22px; border-radius: 999px; background: rgba(0,0,0,.25); position: relative; flex: 0 0 auto; transition: background .2s; }
.tl-switch__track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.tl-switch input:checked + .tl-switch__track { background: var(--tl-primary); }
.tl-switch input:checked + .tl-switch__track::after { transform: translateX(18px); }
.tl-switch input:focus-visible + .tl-switch__track { box-shadow: var(--tl-focus); }
.tl-prefs__save { margin-top: 14px; display: flex; align-items: center; gap: 12px; }
.tl-progress-table { width: 100%; border-collapse: collapse; }
.tl-progress-table th, .tl-progress-table td { padding: 10px 12px; border-bottom: 1px solid var(--tl-line); text-align: left; }
.tl-progress-table th { font-size: .85em; }
.tl-sort { appearance: none; border: 0; background: transparent; font: inherit; font-weight: 700; color: inherit; cursor: pointer; padding: 0; }
.tl-sort.is-active { color: var(--tl-primary); }
.tl-progress-table .tl-up { color: #15803d; font-weight: 700; }
@media (max-width: 640px) {
    .tl-hero { grid-template-columns: 1fr; padding: 18px; gap: 14px; }
    .tl-hero__number { font-size: 2.6em; }
    .tl-hero__stats { gap: 6px; }
    .tl-hero__stat { padding: 8px 10px; }
    .tl-hero__stat strong { font-size: 1.2em; }
    .tl-toolbar > * { flex: 1 1 100%; }
    .tl-toolbar .tl-select select { width: 100%; }
    .tl-progress-table thead { display: none; }
    .tl-progress-table, .tl-progress-table tbody, .tl-progress-table tr, .tl-progress-table td { display: block; width: 100%; }
    .tl-progress-table tr { padding: 8px 0; border-bottom: 1px solid var(--tl-line); }
    .tl-progress-table td { padding: 3px 0; border: 0; }
    .tl-progress-table td::before { content: attr(data-title) ": "; color: var(--tl-muted); font-size: .85em; }
    .tl-progress-table td:first-child::before { content: none; }
}
@media (prefers-reduced-motion: reduce) { .tl-dash * { transition: none !important; animation: none !important; } }
