:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --primary-lighter: #eff6ff;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 8px;
    --radius-sm: 5px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.1), 0 4px 10px rgba(0,0,0,.05);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--gray-800);
    background: var(--gray-50);
    line-height: 1.5;
    min-height: 100vh;
}

/* ---- Login Page ---- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #3b82f6 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
}

.login-card {
    background: white;
    border-radius: 12px;
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -.02em;
}

.login-header p {
    color: var(--gray-500);
    margin-top: .25rem;
    font-size: .9rem;
}

.accent { color: var(--primary); }

/* ---- Form Elements ---- */
.form-group {
    margin-bottom: 1rem;
    flex: 1;
}

.form-group label {
    display: block;
    font-size: .8125rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: .375rem;
    text-transform: uppercase;
    letter-spacing: .02em;
}

input[type="text"],
input[type="password"],
input[type="tel"],
input[type="date"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: .5rem .75rem;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: .875rem;
    font-family: inherit;
    color: var(--gray-800);
    background: white;
    transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.form-display {
    background: var(--gray-50) !important;
    border-color: var(--gray-200) !important;
    cursor: default;
    font-weight: 500;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.error-message {
    background: #fef2f2;
    color: var(--danger);
    padding: .5rem .75rem;
    border-radius: var(--radius);
    font-size: .875rem;
    margin-bottom: 1rem;
    border: 1px solid #fecaca;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .5rem 1rem;
    border: 1.5px solid transparent;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
    gap: .375rem;
    white-space: nowrap;
}

.btn:active { transform: scale(.98); }

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 1px 2px rgba(37,99,235,.3);
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-outline {
    background: white;
    border-color: var(--gray-300);
    color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); }

.btn-sm { padding: .375rem .75rem; font-size: .8125rem; }
.btn-full { width: 100%; }

/* ---- Navbar ---- */
.navbar {
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    height: 56px;
    background: white;
    border-bottom: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-right: 2rem;
    letter-spacing: -.02em;
}

.nav-links {
    display: flex;
    gap: .25rem;
}

.nav-link {
    padding: .5rem 1rem;
    text-decoration: none;
    color: var(--gray-500);
    font-size: .875rem;
    font-weight: 500;
    border-radius: var(--radius);
    transition: all .15s;
}
.nav-link:hover { color: var(--gray-800); background: var(--gray-100); }
.nav-link.active { color: var(--primary); background: var(--primary-light); font-weight: 600; }

.nav-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .75rem;
    font-size: .875rem;
    color: var(--gray-500);
}

/* ---- Main Content ---- */
.main-content {
    padding: 1.25rem 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

/* ---- Calendar ---- */
.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: .75rem;
}

.calendar-nav {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.week-range {
    font-weight: 600;
    color: var(--gray-700);
    margin-left: .75rem;
    font-size: .95rem;
}

.type-tabs {
    display: flex;
    gap: .375rem;
}

.type-tab {
    padding: .5rem 1.25rem;
    border: 1.5px solid var(--gray-200);
    background: white;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: .875rem;
    font-weight: 600;
    font-family: inherit;
    transition: all .15s;
    color: var(--gray-500);
}
.type-tab:hover { border-color: var(--primary); color: var(--primary); }
.type-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 1px 3px rgba(37,99,235,.3);
}

.calendar-grid-wrapper {
    overflow-x: auto;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
}

.calendar-grid {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    min-width: 800px;
}

.calendar-grid th {
    padding: .625rem .5rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    font-size: .75rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .03em;
}

.calendar-grid th .th-date {
    font-weight: 700;
    color: var(--gray-700);
    font-size: .8125rem;
}

.calendar-grid th.today-col {
    background: var(--primary-light);
    color: var(--primary);
}
.calendar-grid th.today-col .th-date { color: var(--primary); }

.calendar-grid th.time-col { width: 65px; }

.calendar-grid td {
    padding: .25rem .375rem;
    border: 1px solid var(--gray-200);
    height: 48px;
    vertical-align: top;
    cursor: pointer;
    transition: background .1s;
    font-size: .75rem;
}

.calendar-grid td:first-child {
    width: 65px;
    text-align: center;
    font-weight: 600;
    color: var(--gray-400);
    cursor: default;
    vertical-align: middle;
    font-size: .8125rem;
    background: var(--gray-50);
}

.calendar-grid td:hover:not(:first-child) {
    background: var(--primary-lighter);
}

.calendar-grid td.has-appointment {
    background: #f0fdf4;
    border-color: #bbf7d0;
    position: relative;
}
.calendar-grid td.has-appointment:hover {
    background: #dcfce7;
}

.slot-content-multi {
    position: relative;
    padding-right: 1.35rem;
}

.slot-count-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 1.125rem;
    height: 1.125rem;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--primary);
    color: white;
    font-size: 0.625rem;
    font-weight: 700;
    line-height: 1.125rem;
    text-align: center;
}

.modal-content-slot-choice {
    max-width: 420px;
}

.slot-choice-hint {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin: 0 0 1rem;
    line-height: 1.45;
}

.slot-choice-list {
    list-style: none;
    margin: 0 0 1rem;
    padding: 0;
    max-height: min(50vh, 320px);
    overflow-y: auto;
}

.slot-choice-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--gray-200);
}

.slot-choice-item:last-child {
    border-bottom: none;
}

.slot-choice-info {
    min-width: 0;
    flex: 1;
}

.slot-choice-name {
    display: block;
    font-size: 0.9375rem;
    color: var(--gray-800);
}

.slot-choice-meta {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

.slot-choice-sms {
    margin-left: 0.35rem;
    color: #166534;
    font-weight: 600;
}

.slot-choice-actions {
    display: flex;
    flex-shrink: 0;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.slot-choice-footer {
    border-top: none;
    padding-top: 0;
    margin-top: 0;
    justify-content: stretch;
}

.slot-choice-footer .btn {
    width: 100%;
}

.slot-content {
    display: flex;
    flex-direction: column;
    gap: 1px;
    line-height: 1.3;
}

.slot-patient {
    font-weight: 600;
    color: var(--gray-800);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.slot-detail {
    color: var(--gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.slot-badges {
    display: flex;
    gap: 3px;
    margin-top: 2px;
}

.badge {
    display: inline-block;
    padding: 0 .375rem;
    border-radius: 3px;
    font-size: .625rem;
    font-weight: 700;
    text-transform: uppercase;
    line-height: 1.6;
    letter-spacing: .02em;
}

.badge-lang { background: #e0e7ff; color: #4338ca; }
.badge-sms-yes { background: #dcfce7; color: #166534; }
.badge-test { background: #f3e8ff; color: #7c3aed; }

/* ---- SMS View ---- */
.sms-header {
    margin-bottom: 1rem;
}

.sms-header h2 {
    margin-bottom: .75rem;
    font-size: 1.25rem;
}

.sms-actions {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.sms-queue-group {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.sms-queue-divider {
    color: var(--gray-400);
    font-size: .8125rem;
    padding: 0 .25rem;
}

.queue-date-input {
    width: auto !important;
    min-width: 150px;
}

.sms-filters {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
}

.sms-filters select,
.sms-filters input {
    width: auto;
    min-width: 130px;
}

.sms-table-wrapper {
    overflow-x: auto;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: .625rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-100);
    font-size: .875rem;
}

.data-table th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-500);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom-color: var(--gray-200);
}

.data-table tbody tr:hover {
    background: var(--gray-50);
}

.data-table code {
    font-size: .8125rem;
    color: var(--gray-600);
}

.data-table .msg-cell {
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--gray-500);
}

.status-badge {
    display: inline-block;
    padding: .125rem .625rem;
    border-radius: 9999px;
    font-size: .6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.status-PENDING { background: var(--warning-light); color: #92400e; }
.status-SENT { background: var(--success-light); color: #166534; }
.status-FAILED { background: #fef2f2; color: #991b1b; }
.status-CANCELLED { background: var(--gray-100); color: var(--gray-400); }

/* ---- Settings ---- */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-top: 1rem;
}

.settings-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
}

.settings-card h3 {
    margin-bottom: 1rem;
    color: var(--gray-700);
    font-size: 1rem;
}

.template-item {
    padding: 1rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    margin-bottom: .75rem;
    background: var(--gray-50);
}

.template-item h4 {
    font-size: .875rem;
    color: var(--gray-600);
    margin-bottom: .5rem;
}

.template-item textarea {
    width: 100%;
    min-height: 60px;
    margin-bottom: .5rem;
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: .375rem;
    margin-bottom: .75rem;
}

.tag-item {
    display: flex;
    align-items: center;
    gap: .375rem;
    padding: .3rem .625rem;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    font-size: .8125rem;
    border: 1px solid var(--gray-200);
}

.tag-item-main {
    font-weight: 500;
    color: var(--gray-800);
}

.tag-item-meta {
    font-size: .6875rem;
    font-weight: 600;
    color: var(--gray-600);
    padding: .1rem .35rem;
    background: var(--gray-200);
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: .02em;
}

.tag-item .tag-delete {
    cursor: pointer;
    color: var(--gray-400);
    font-size: 1rem;
    line-height: 1;
    border: none;
    background: none;
    padding: 0;
}
.tag-item .tag-delete:hover { color: var(--danger); }

.sms-timing-form .form-group {
    margin-bottom: .75rem;
}

.sms-timing-form input[type="number"] {
    width: auto;
    text-align: center;
}

.inline-form {
    display: flex;
    gap: .5rem;
    margin-top: .75rem;
    padding-top: .75rem;
    border-top: 1px solid var(--gray-200);
}

.inline-form input {
    width: auto;
    flex: 1;
}

.inline-form select {
    width: auto;
    min-width: 9rem;
    flex-shrink: 0;
}

/* ---- Modal ---- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.35);
    backdrop-filter: blur(2px);
}

.modal-content {
    position: relative;
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.modal-header h3 { font-size: 1.125rem; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-400);
    line-height: 1;
    padding: .25rem;
    border-radius: var(--radius-sm);
    transition: all .15s;
}
.modal-close:hover { color: var(--gray-700); background: var(--gray-100); }

.modal-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-200);
}

.modal-actions-right {
    display: flex;
    gap: .5rem;
}

/* ---- Toast Notifications ---- */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    padding: .75rem 1.25rem;
    border-radius: var(--radius);
    font-size: .875rem;
    font-weight: 500;
    z-index: 300;
    opacity: 0;
    transition: all .3s ease;
    box-shadow: var(--shadow-lg);
    max-width: 90vw;
}

.toast-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast-success { background: #166534; color: white; }
.toast-error { background: #991b1b; color: white; }
.toast-info { background: var(--gray-700); color: white; }

/* ---- Loading Indicator ---- */
.view-loading {
    position: relative;
    pointer-events: none;
    min-height: 120px;
}

.view-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,.6);
    z-index: 10;
}

.view-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    z-index: 11;
    animation: spin .6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---- Responsive ---- */
@media (min-width: 768px) {
    .settings-grid {
        grid-template-columns: 1fr 1fr;
    }
    .sms-actions {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

@media (min-width: 1024px) {
    .settings-grid {
        grid-template-columns: 1fr 1fr 1fr;
    }
}
