/**
 * SaazMed – Sdílený designový základ
 * Verze 2.0 | Tablet-first (landscape)
 * Jeden zdroj pravdy pro barvy, komponenty, formuláře, modály.
 */

/* ═══════════════════════════════════════════════════
   DESIGN TOKENY
   ═══════════════════════════════════════════════════ */
:root {
    /* Barvy */
    --c-bg:         #F2F2F7;
    --c-card:       #FFFFFF;
    --c-border:     #D1D1D6;
    --c-input-bg:   #F2F2F7;

    --c-blue:       #007AFF;
    --c-blue-light: #E8F3FF;
    --c-green:      #34C759;
    --c-green-light:#E7F9EB;
    --c-red:        #FF3B30;
    --c-orange:     #FF9500;
    --c-purple:     #5856D6;

    --c-text:       #1C1C1E;
    --c-text-sec:   #8E8E93;
    --c-text-tert:  #AEAEB2;

    /* Typografie */
    --font:         -apple-system, system-ui, sans-serif;

    /* Zaoblení */
    --r-card:       16px;
    --r-input:      10px;
    --r-btn:        10px;

    /* Výška inputů – větší pro dotyk na tabletu */
    --h-input:      48px;
    --h-input-sm:   40px;

    /* Stíny */
    --shadow-card:  0 2px 10px rgba(0,0,0,0.06);
    --shadow-modal: 0 20px 50px rgba(0,0,0,0.25);
}


/* ═══════════════════════════════════════════════════
   LAYOUT – WRAPPER MODULŮ
   ═══════════════════════════════════════════════════ */

/* Každý modul dostane tento wrapper */
.sm-module {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: calc(100vh - 140px);
    padding: 8px 0 12px 0;
    box-sizing: border-box;
    overflow-y: auto;
    overflow-x: hidden;
}

.sm-module::-webkit-scrollbar { width: 4px; }
.sm-module::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 4px; }

/* Karta – bílý blok s okraji */
.sm-card {
    background: var(--c-card);
    border-radius: var(--r-card);
    padding: 16px 20px;
    box-shadow: var(--shadow-card);
    flex-shrink: 0;
}

/* Karta která se roztáhne na zbývající výšku */
.sm-card.grow {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}


/* ═══════════════════════════════════════════════════
   NADPIS SEKCE
   ═══════════════════════════════════════════════════ */
.sm-title {
    margin: 0 0 14px 0;
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--c-blue);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1.5px solid var(--c-blue-light);
    padding-bottom: 10px;
    flex-shrink: 0;
}

.sm-title i {
    font-size: 0.85rem;
    opacity: 0.8;
}

/* Červený nadpis (alergie apod.) */
.sm-title.danger {
    color: var(--c-red);
    border-bottom-color: #FFE5E3;
}


/* ═══════════════════════════════════════════════════
   FORMULÁŘOVÉ PRVKY
   ═══════════════════════════════════════════════════ */

.sm-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sm-label {
    font-size: 0.65rem;
    font-weight: 800;
    color: var(--c-text-sec);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Wrapper pro input + mazací křížek */
.sm-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

/* Základní input */
.sm-input,
.sm-select,
.sm-textarea {
    width: 100%;
    height: var(--h-input);
    background: var(--c-input-bg);
    border: 1.5px solid var(--c-border);
    border-radius: var(--r-input);
    padding: 0 42px 0 14px; /* místo pro křížek vpravo */
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 500;
    color: var(--c-text);
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
}

.sm-input:focus,
.sm-select:focus,
.sm-textarea:focus {
    border-color: var(--c-blue);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
}

/* Textarea – výška se řídí flexem rodiče */
.sm-textarea {
    height: 100%;
    padding: 12px 42px 12px 14px;
    resize: none;
    line-height: 1.5;
}

/* Select – šipka vlastní */
.sm-select {
    padding-right: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238E8E93' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    cursor: pointer;
}

/* Input bez pravého paddingu (pokud křížek není) */
.sm-input.no-clear,
.sm-select.no-clear {
    padding-right: 14px;
}

/* Malá varianta inputu */
.sm-input.sm,
.sm-select.sm {
    height: var(--h-input-sm);
    font-size: 0.9rem;
}


/* ═══════════════════════════════════════════════════
   MAZACÍ KŘÍŽEK – JEDNOTNÝ PRO CELOU APLIKACI
   ═══════════════════════════════════════════════════ */
.sm-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--c-text-tert);
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    font-size: 1.1rem;
    /* Větší touch target pro tablet */
    padding: 4px;
    margin-right: -4px;
    z-index: 5;
}

.sm-clear:hover,
.sm-clear:active {
    color: var(--c-red);
    background: #FFF0EF;
}

/* Křížek pro select – trochu víc vlevo kvůli šipce */
.sm-input-wrap .sm-clear.for-select {
    right: 28px;
}


/* ═══════════════════════════════════════════════════
   TLAČÍTKA
   ═══════════════════════════════════════════════════ */
.sm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: var(--h-input);
    padding: 0 20px;
    border: none;
    border-radius: var(--r-btn);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 800;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.sm-btn:active { opacity: 0.8; transform: scale(0.97); }

.sm-btn.blue   { background: var(--c-blue);   color: #fff; }
.sm-btn.green  { background: var(--c-green);  color: #fff; }
.sm-btn.red    { background: var(--c-red);    color: #fff; }
.sm-btn.gray   { background: #E5E5EA;         color: var(--c-text); }
.sm-btn.purple { background: var(--c-purple); color: #fff; }

.sm-btn.sm {
    height: var(--h-input-sm);
    font-size: 0.8rem;
    padding: 0 14px;
}

.sm-btn.icon-only {
    width: var(--h-input);
    padding: 0;
}

.sm-btn.icon-only.sm {
    width: var(--h-input-sm);
}


/* ═══════════════════════════════════════════════════
   MODÁL – POTVRZOVACÍ DIALOG (MAZÁNÍ ATPD.)
   ═══════════════════════════════════════════════════ */
.sm-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
    animation: smOverlayIn 0.2s ease;
}

@keyframes smOverlayIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.sm-modal-box {
    background: var(--c-card);
    width: 300px;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: var(--shadow-modal);
    animation: smBoxIn 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes smBoxIn {
    from { transform: scale(0.88); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

.sm-modal-body {
    padding: 28px 22px 20px;
    text-align: center;
}

.sm-modal-icon {
    font-size: 2.2rem;
    color: var(--c-red);
    margin-bottom: 14px;
}

.sm-modal-body h3 {
    margin: 0 0 8px;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--c-text);
}

.sm-modal-body p {
    margin: 0;
    font-size: 0.88rem;
    color: var(--c-text-sec);
    line-height: 1.45;
}

.sm-modal-footer {
    display: flex;
    border-top: 1.5px solid var(--c-border);
}

.sm-modal-footer button {
    flex: 1;
    padding: 16px;
    border: none;
    background: none;
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.1s;
}

.sm-modal-footer button:active { background: var(--c-bg); }

.sm-modal-btn-cancel {
    color: var(--c-blue);
    border-right: 1.5px solid var(--c-border) !important;
}

.sm-modal-btn-confirm {
    color: var(--c-red);
    font-weight: 800 !important;
}


/* ═══════════════════════════════════════════════════
   GRID HELPERS
   ═══════════════════════════════════════════════════ */
.sm-grid-2 { display: grid; grid-template-columns: 1fr 1fr;       gap: 12px; }
.sm-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr;   gap: 12px; }
.sm-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.sm-row    { display: flex; gap: 12px; align-items: flex-end; }


/* ═══════════════════════════════════════════════════
   UTILITY
   ═══════════════════════════════════════════════════ */
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
.no-scrollbar::-webkit-scrollbar { display: none; }

/* Skrytí datepicker ikony + vlastní oblast */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
    opacity: 0.4;
    cursor: pointer;
}

/* ═══════════════════════════════════════════════════
   GLOBÁLNÍ DOPLŇKY v2.1
   ═══════════════════════════════════════════════════ */

/* Importovací tlačítka – vždy zelená */
.p-addr-btn.green,
[class*="import-btn"],
button[onclick*="import"],
button[onclick*="Import"] {
    background: var(--c-green-light) !important;
    color: var(--c-green) !important;
    border: 1.5px solid var(--c-green) !important;
}

/* Checkboxy – označené = zelené podbarvení (třída .check-row, .pr-check-row, .cen-item) */
.pr-check-row:has(input[type="checkbox"]:checked) {
    border-color: var(--c-green) !important;
    background: var(--c-green-light) !important;
}
.cen-item:has(input[type="checkbox"]:checked) {
    border-color: var(--c-green) !important;
    background: var(--c-green-light) !important;
}

/* Pojišťovny – označené = modré */
.p-pojist-btn.active {
    border-color: var(--c-blue) !important;
    background: var(--c-blue-light) !important;
}

/* ═══════════════════════════════════════════════════
   TABLET / TOUCH OPTIMALIZACE
   ═══════════════════════════════════════════════════ */

/* Odstraní 300ms zpoždění na všech prvcích */
* {
    touch-action: manipulation;
}

/* Minimum 44px touch target pro všechna tlačítka a interaktivní prvky */
button,
.btn-pill,
.sm-btn,
.strip-btn,
.vz-nav-btn,
.pr-tab,
.terapie-tab,
.p-pojist-btn,
.p-unit-btn,
.dg-numer-btn,
.kl-now-btn,
.kl-clear-btn,
input[type="checkbox"],
input[type="radio"],
select {
    min-height: 44px;
    min-width: 44px;
}

/* Checkboxy a radio – větší touch area bez změny vizuálu */
input[type="checkbox"],
input[type="radio"] {
    width: 22px;
    height: 22px;
    cursor: pointer;
}

/* Inputy – větší výška pro pohodlné klepnutí */
.sm-input,
.sm-select,
.sm-textarea,
.ios-input-text,
.ios-select-main {
    min-height: 48px;
}

/* Zabránit zoom při focusu na input (iOS) –
   font-size musí být alespoň 16px */
input, select, textarea {
    font-size: 16px !important;
}

/* Výjimka pro tiskový náhled – tam chceme malé písmo */
#print-preview-frame input,
#print-preview-frame select,
#print-preview-frame textarea {
    font-size: inherit !important;
}

/* Větší mezery mezi položkami v listech (terapie, statistiky) */
.item-row,
.cen-item,
.pr-check-row,
.stat-check-row,
.stat-radio-row {
    min-height: 52px;
}

/* Sidebar tlačítka – trochu větší pro dotyk */
.vz-nav-btn {
    padding: 16px 14px !important;
}

/* Aktivní stav bez hover efektů (hover na touch zaostane) */
@media (hover: none) {
    .sm-clear:hover { color: var(--c-text-tert); background: transparent; }
    .kl-clear-btn:hover { background: #F2F2F7; color: var(--c-text-sec); }
    button:hover { opacity: 1; }
}

/* ── AUTOCAPITALIZE – první písmeno velké ── */
.sm-input:not([inputmode="numeric"]):not([inputmode="decimal"]):not([inputmode="tel"]):not([type="date"]):not([type="time"]):not([type="email"]),
.sm-textarea,
.ios-input-text:not([inputmode="numeric"]):not([inputmode="decimal"]):not([type="date"]),
.ios-textarea {
    text-transform: sentence; /* nefunguje v CSS, ale signalizuje intent */
}

/* Oprava: textarea nepřetéká přes wrapper při font-size:16px */
textarea.ios-input-text,
textarea.sm-textarea {
    font-size: 0.95rem !important;
    box-sizing: border-box;
    width: 100%;
}

/* ── IMPORT TLAČÍTKA – malá, nepodléhají touch min-height ── */
.p-addr-btn,
button[onclick*="import"],
button[onclick*="Import"],
button[onclick*="importFrom"] {
    min-height: unset !important;
    height: auto !important;
    font-size: 0.68rem !important;
    padding: 4px 8px !important;
}

/* ── STAT-COL-TITLE a CLEAR-BTN nepodléhají touch min-height ── */
.stat-col-title,
.stat-clear-btn,
.field-label,
.lbl,
.sm-label {
    min-height: unset !important;
    height: auto !important;
}

/* ── Textarea nepodléhají 16px fontu z touch pravidla ── */
textarea {
    font-size: 0.92rem !important;
}

/* ── POVINNÁ POLE – červené zvýraznění ── */
.field-required .ios-input-text:not([value]):not(:focus),
.field-required .sm-input:not(:focus),
.field-required .sm-select:not(:focus),
.field-required .ios-select-main:not(:focus) {
    border-color: #FF3B30 !important;
    background: #FFF5F5 !important;
}

/* Třída přidána JavaScriptem na prázdná povinná pole */
.input-missing {
    border-color: #FF3B30 !important;
    background: #FFF5F5 !important;
    box-shadow: 0 0 0 2px rgba(255,59,48,0.15) !important;
}

.input-missing:focus {
    border-color: #FF3B30 !important;
    background: white !important;
    box-shadow: 0 0 0 3px rgba(255,59,48,0.2) !important;
}

/* Label u povinného nevyplněného pole */
.label-missing {
    color: #FF3B30 !important;
}

/* ── Přepis input-missing na výraznější styl (jako způsob ukončení) ── */
.input-missing,
.sm-input.input-missing,
.sm-select.input-missing,
.ios-input-text.input-missing {
    border-color: #FF3B30 !important;
    border-width: 2px !important;
    background: #FFF2F2 !important;
    box-shadow: 0 0 0 3px rgba(255,59,48,0.18) !important;
}
