*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #1a6fc4;
    --primary-dark: #155ea8;
    --accent: #7c3aed;
    --success: #15803d;
    --warning: #b45309;
    --error: #dc2626;
    --info: #0369a1;
    --neutral: #6b7280;
    --bg: #f3f4f6;
    --surface: #ffffff;
    --border: #e5e7eb;
    --text: #111827;
    --text-muted: #6b7280;
    --sidebar-w: 240px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

/* ── App Shell ── */
.app-shell { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: #0d4f8c;
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-logo {
    display: flex; align-items: center; gap: 8px;
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
}
.logo-icon { font-size: 22px; }
.logo-name { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }

.nav-list { list-style: none; padding: 8px 0; }
.nav-link {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 16px;
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    border-radius: 0;
    transition: background 0.12s;
    font-size: 13.5px;
}
.nav-link:hover { background: rgba(255,255,255,0.12); color: #fff; }
.nav-icon { width: 16px; height: 16px; vertical-align: -3px; filter: brightness(0) invert(1); opacity: 0.85; }
.icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    vertical-align: -3px;
    background-color: currentColor;
    -webkit-mask: var(--icon) no-repeat center / contain;
    mask: var(--icon) no-repeat center / contain;
}
.btn-sm .icon { width: 14px; height: 14px; vertical-align: -2px; }
.icon-lg { width: 22px; height: 22px; vertical-align: -4px; }

.nav-section-title {
    padding: 16px 16px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.45);
}

.sidebar-bottom { margin-top: auto; border-top: 1px solid rgba(255,255,255,0.12); }
.logout-link { color: rgba(255,255,255,0.7) !important; font-size: 13px; }

/* ── Main Content ── */
.main-content {
    margin-left: var(--sidebar-w);
    padding: 24px;
    flex: 1;
    min-height: 100vh;
}

/* ── Page Card ── */
.page-card {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 1px 8px rgba(0,0,0,0.06);
    padding: 24px;
    max-width: 100%;
}

.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
}
.page-header h2 { font-size: 20px; font-weight: 700; }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: #374151; margin-bottom: 5px; }
.form-control {
    width: 100%;
    height: 36px;
    padding: 8px 10px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 13.5px;
    line-height: 1.2;
    background: #fff;
    transition: border-color 0.15s;
    outline: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,111,196,0.12); }
select.form-control { appearance: none; -webkit-appearance: none; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, #6b7280 50%), linear-gradient(135deg, #6b7280 50%, transparent 50%); background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
textarea.form-control { height: auto; min-height: 70px; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.form-section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 16px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.form-hint { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.required-mark { color: var(--error); font-weight: 600; }
.anamnese-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin-bottom: 10px; }
.check-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.check-row label { display: flex; align-items: center; gap: 6px; font-size: 13px; flex-shrink: 0; cursor: pointer; }
.check-row label input[type="checkbox"] { width: 15px; height: 15px; }
.check-row .form-control-sm { height: 28px; padding: 4px 8px; font-size: 12.5px; flex: 1; min-width: 80px; }
.form-check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.form-check input { width: 15px; height: 15px; cursor: pointer; }
.form-check label { font-size: 13px; color: #374151; cursor: pointer; }

.search-bar { margin-bottom: 16px; }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all 0.12s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-danger { background: transparent; color: var(--error); border: 1.5px solid var(--error); }
.btn-danger:hover { background: var(--error); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; padding: 11px; font-size: 15px; font-weight: 600; }
.btn-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); padding: 4px 8px; }

/* ── Tables ── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table th {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid var(--border);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    white-space: nowrap;
}
.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f9fafb; }
.data-table .col-id { width: 1%; white-space: nowrap; }
.actions { display: flex; gap: 6px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 16px; }
.pagination-info { color: var(--text-muted); font-size: 13px; }
.pagination .btn[disabled] { opacity: 0.4; pointer-events: none; }
.actions .btn { border: none; background: transparent; padding: 4px 6px; }
.actions .btn-outline { color: var(--primary); }
.actions .btn-outline:hover { background: rgba(26,111,196,0.10); color: var(--primary); }
.actions .btn-danger { color: var(--error); }
.actions .btn-danger:hover { background: rgba(220,38,38,0.10); color: var(--error); }
.actions .icon { width: 18px; height: 18px; vertical-align: -4px; }

/* ── Badges ── */
.badge {
    display: inline-flex; align-items: center;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-accent { background: #ede9fe; color: #6d28d9; }
.badge-info { background: #e0f2fe; color: #0369a1; }
.badge-neutral { background: #f3f4f6; color: #6b7280; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef9c3; color: #b45309; }
.badge-error { background: #fee2e2; color: #dc2626; }

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}
.modal-dialog {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    width: 60vw;
    max-width: calc(100vw - 40px);
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.modal-lg { max-width: calc(100vw - 40px); }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h4 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px; flex: 1; overflow-y: auto; }
.modal-footer {
    display: flex; gap: 10px; justify-content: flex-end;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
    .modal-dialog {
        width: 100%;
    }
}

/* ── Login Page ── */
.login-bg {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1a6fc4 0%, #0d4f8c 40%, #082d52 100%);
}
.login-card {
    background: #fff;
    padding: 40px 36px;
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.25);
    width: 100%;
    max-width: 400px;
    margin: 16px;
}
.login-logo { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 20px; }
.login-logo .logo-icon { font-size: 28px; }
.login-logo .logo-name { font-size: 18px; font-weight: 700; color: #0d4f8c; }
.login-title { text-align: center; font-size: 17px; font-weight: 600; color: #374151; margin-bottom: 24px; }

/* ── Alerts ── */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13.5px; }
.alert-error { background: #fee2e2; color: #dc2626; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }

/* ── Dashboard ── */
.clinic-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-top: 8px;
    color: var(--text-muted);
    font-size: 13px;
}
.clinic-summary strong { color: var(--text); }
.clinic-info {
    margin-top: 24px;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
}
.clinic-info h3 { font-size: 16px; font-weight: 700; margin-bottom: 12px; color: var(--text); }
.info-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.info-table th {
    text-align: left;
    padding: 8px 10px;
    width: 180px;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.info-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
.info-table tr:last-child th, .info-table tr:last-child td { border-bottom: none; }
.dashboard-calendar {
    margin-top: 24px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
}
.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    background: #f9fafb;
}
.calendar-header h3 { font-size: 16px; margin-bottom: 2px; }
.calendar-header form { width: 260px; }
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(140px, 1fr));
    overflow-x: auto;
}
.calendar-day {
    min-height: 180px;
    padding: 10px;
    border-right: 1px solid var(--border);
}
.calendar-day:last-child { border-right: none; }
.calendar-day-header {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 12px;
    color: var(--text-muted);
}
.calendar-day-header strong { color: var(--text); }
.calendar-appointment {
    display: grid;
    gap: 3px;
    padding: 8px;
    margin-bottom: 8px;
    border-left: 3px solid var(--primary);
    background: #eef6ff;
    border-radius: 6px;
    font-size: 12px;
}
.appointment-time { color: var(--primary-dark); font-weight: 700; }
.calendar-empty {
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
}

/* ── Token Debug ── */
.token-debug {
    background: #1e1e2e;
    color: #cdd6f4;
    border-radius: 10px;
    padding: 20px;
    font-family: 'Consolas', 'Menlo', monospace;
    font-size: 13px;
    margin-top: 20px;
}
.token-debug h5 { color: #89b4fa; margin-bottom: 12px; font-size: 13px; text-transform: uppercase; }
.token-table { width: 100%; border-collapse: collapse; }
.token-table tr:nth-child(even) { background: #181825; }
.claim-key { color: #f38ba8; padding: 5px 10px; width: 180px; }
.claim-value { color: #a6e3a1; padding: 5px 10px; }

/* ── Features Grid ── */
.feature-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.feature-item { display: flex; align-items: center; gap: 6px; }
.feature-item label { font-size: 12.5px; }
.availability-row { display: grid; grid-template-columns: 1fr 140px 140px; gap: 10px; align-items: center; margin-bottom: 10px; }
.availability-day { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; }
.appointment-context-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0 16px; }
.appointment-context-panel { border: 1px solid var(--border); border-radius: 8px; background: #f9fafb; padding: 12px; min-height: 96px; }
.appointment-context-panel h5 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 8px; }
.appointment-context-panel p { font-size: 13px; margin-bottom: 6px; }
.scheduled-item { display: grid; gap: 2px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.scheduled-item:last-child { border-bottom: none; }

/* ── Misc ── */
.loading { color: var(--text-muted); padding: 20px; text-align: center; }
.empty-state { color: var(--text-muted); padding: 20px; text-align: center; font-style: italic; }
.text-muted { color: var(--text-muted); }
