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

:root {
    --bg: #F5F3EE;
    --surface: #FFFFFF;
    --primary: #2D5A4A;
    --primary-light: #E8F0EC;
    --accent: #E07B54;
    --text: #1A1A1A;
    --text-secondary: #6B6B6B;
    --error: #C0392B;
    --success: #27AE60;
    --border: #E0DDD7;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 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 12px 32px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.06);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    --transition: 200ms ease-out;
    --font: 'Inter', system-ui, sans-serif;
    --mono: 'JetBrains Mono', monospace;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

#app {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-full); }

/* ─── Page wrapper ─── */
.page {
    flex: 1;
    padding: 24px 16px calc(80px + var(--safe-bottom) + 16px);
    max-width: 640px;
    margin: 0 auto;
    width: 100%;
    animation: fadeIn 300ms ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Auth ─── */
.auth-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 24px 16px;
}

.auth-logo {
    width: 72px;
    height: 72px;
    background: var(--primary);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    box-shadow: var(--shadow-md);
}

.auth-logo svg { width: 40px; height: 40px; color: white; }

.auth-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
    text-align: center;
}

.auth-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 32px;
}

/* ─── Tabs ─── */
.tabs {
    display: flex;
    gap: 0;
    background: var(--surface);
    border-radius: var(--radius-full);
    padding: 4px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    margin-bottom: 24px;
    width: 100%;
    max-width: 320px;
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    border-radius: var(--radius-full);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.tab-btn:active { transform: scale(0.97); }

/* ─── Form ─── */
.form {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text);
}

.form-input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 1rem;
    color: var(--text);
    background: var(--surface);
    transition: var(--transition);
    outline: none;
}

.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-input.error {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.1);
}

.form-input.mono {
    font-family: var(--mono);
    font-size: 0.9375rem;
    letter-spacing: 0.025em;
}

.form-error {
    font-size: 0.75rem;
    color: var(--error);
    display: flex;
    align-items: center;
    gap: 4px;
    animation: slideDown 150ms ease-out;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.password-wrapper {
    position: relative;
}

.password-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.password-toggle:hover { color: var(--text); }

.password-strength {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}

.strength-bar {
    flex: 1;
    height: 3px;
    border-radius: var(--radius-full);
    background: var(--border);
    transition: var(--transition);
}

.strength-bar.filled { background: var(--error); }
.strength-bar.filled.medium { background: var(--accent); }
.strength-bar.filled.good { background: var(--success); }

/* ─── Button ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    min-height: 48px;
    position: relative;
    overflow: hidden;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
    background: #234539;
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1.5px solid var(--border);
}

.btn-secondary:hover:not(:disabled) { background: var(--bg); }

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

.btn-danger:hover:not(:disabled) { background: #a93226; }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
    min-height: auto;
}

.btn-ghost:hover { color: var(--text); background: var(--primary-light); }

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    padding: 4px;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.btn-full { width: 100%; }

.btn .spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ─── Dashboard ─── */
.dashboard-header {
    margin-bottom: 24px;
}

.greeting {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 2px;
}

.greeting-time {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    text-align: center;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ─── Reminder cards ─── */
.reminders-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.reminder-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    transition: var(--transition);
    cursor: pointer;
    position: relative;
}

.reminder-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.reminder-card.status-scheduled { border-left-color: var(--primary); }
.reminder-card.status-called { border-left-color: var(--success); }
.reminder-card.status-failed { border-left-color: var(--error); }

.reminder-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.reminder-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}

.reminder-status {
    flex-shrink: 0;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.reminder-status.scheduled { background: var(--primary-light); color: var(--primary); }
.reminder-status.called { background: rgba(39, 174, 96, 0.1); color: var(--success); }
.reminder-status.failed { background: rgba(192, 57, 43, 0.1); color: var(--error); }

.reminder-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.reminder-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.reminder-row svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.reminder-phone {
    font-family: var(--mono);
    font-size: 0.8125rem;
    color: var(--text);
}

.reminder-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: var(--transition);
}

.reminder-card:hover .reminder-actions { opacity: 1; }

.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
}

.icon-btn:hover { background: var(--border); color: var(--text); }
.icon-btn.danger:hover { background: rgba(192, 57, 43, 0.1); color: var(--error); }

.icon-btn svg { width: 16px; height: 16px; }

/* ─── Empty state ─── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
}

.empty-icon {
    width: 64px;
    height: 64px;
    background: var(--primary-light);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.empty-icon svg { width: 32px; height: 32px; color: var(--primary); }

.empty-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.empty-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* ─── Bottom nav ─── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    padding: 8px 0;
    padding-bottom: calc(8px + var(--safe-bottom));
    box-shadow: 0 -4px 16px rgba(0,0,0,0.06);
    z-index: 100;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.6875rem;
    font-weight: 500;
    transition: var(--transition);
    text-decoration: none;
}

.nav-item svg {
    width: 24px;
    height: 24px;
    transition: var(--transition);
}

.nav-item.active { color: var(--primary); }
.nav-item:hover { color: var(--primary); }

/* ─── Toast ─── */
.toast-container {
    position: fixed;
    bottom: calc(88px + var(--safe-bottom));
    left: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
    pointer-events: none;
    max-width: 640px;
    margin: 0 auto;
}

.toast {
    background: var(--text);
    color: white;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: var(--shadow-lg);
    animation: toastIn 250ms ease-out;
    pointer-events: auto;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--error); }
.toast.info { background: var(--primary); }

.toast-dismiss {
    background: none;
    border: none;
    color: rgba(255,255,255,0.8);
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.toast-dismiss:hover { color: white; }
.toast-dismiss svg { width: 16px; height: 16px; }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 200ms ease-out;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-width: 640px;
    max-height: 90dvh;
    overflow-y: auto;
    padding: 24px 20px calc(24px + var(--safe-bottom));
    box-shadow: var(--shadow-lg);
    animation: slideUp 250ms ease-out;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

/* ─── Select ─── */
.form-select {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 1rem;
    color: var(--text);
    background: var(--surface);
    transition: var(--transition);
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B6B6B' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ─── Settings ─── */
.settings-card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    margin-bottom: 16px;
}

.settings-card-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.session-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.session-row:last-child { border-bottom: none; }

.session-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.session-browser {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
}

.session-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: var(--mono);
}

/* ─── Audio player ─── */
.audio-preview {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

.audio-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
}

.audio-play-btn:hover { background: #234539; }
.audio-play-btn:active { transform: scale(0.95); }
.audio-play-btn svg { width: 16px; height: 16px; }

.audio-progress {
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: var(--radius-full);
    overflow: hidden;
    cursor: pointer;
}

.audio-progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: var(--radius-full);
    transition: width 100ms linear;
    width: 0%;
}

.audio-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: var(--mono);
    min-width: 70px;
    text-align: right;
}

/* ─── Link ─── */
a { color: var(--primary); }

/* ─── Utility ─── */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-sm { font-size: 0.875rem; }
.text-secondary { color: var(--text-secondary); }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

.page-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.back-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    transition: var(--transition);
    flex-shrink: 0;
}

.back-btn:hover { background: var(--bg); }
.back-btn svg { width: 20px; height: 20px; }

.page-nav-title {
    font-size: 1.125rem;
    font-weight: 700;
}

@media (min-width: 640px) {
    .page { padding: 32px 24px calc(100px + 16px)); }
    .bottom-nav { border-radius: var(--radius-lg) var(--radius-lg) 0 0; left: 50%; transform: translateX(-50%); max-width: 640px; width: 100%; }
    .reminder-actions { opacity: 1; }
}
