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

:root {
    --bg: #f0f2f5;
    --card: #ffffff;
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --radius: 12px;
    --nav-height: 64px;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100%;
    -webkit-tap-highlight-color: transparent;
}

body { overflow: hidden; }

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

.view { display: flex; flex-direction: column; height: 100%; }
.hidden { display: none !important; }

/* Auth */
.auth-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}
.auth-logo { margin-bottom: 16px; }
.auth-container h1 { font-size: 28px; margin-bottom: 4px; }
.subtitle { color: var(--muted); margin-bottom: 24px; font-size: 14px; }
.auth-tabs { display: flex; gap: 0; margin-bottom: 20px; width: 100%; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.auth-tab {
    flex: 1; padding: 10px; border: none; background: var(--card); cursor: pointer;
    font-size: 14px; font-weight: 500; color: var(--muted); transition: all .15s;
}
.auth-tab.active { background: var(--primary); color: white; }

form { width: 100%; display: flex; flex-direction: column; gap: 12px; }

input[type="text"], input[type="password"], input[type="date"], select, textarea {
    width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 15px; background: var(--card); color: var(--text); outline: none;
    transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
.readonly { background: var(--bg); color: var(--muted); }

.btn-primary {
    padding: 12px 20px; background: var(--primary); color: white; border: none;
    border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer;
    transition: background .15s;
}
.btn-primary:hover { background: #4338ca; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-secondary {
    padding: 12px 20px; background: var(--bg); color: var(--text); border: 1px solid var(--border);
    border-radius: 8px; font-size: 15px; cursor: pointer;
}

.btn-danger { padding: 6px 12px; background: none; color: var(--danger); border: 1px solid var(--danger); border-radius: 6px; font-size: 13px; cursor: pointer; }

.error { color: var(--danger); font-size: 13px; text-align: center; padding: 8px; }

/* Header */
header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
header h1 { font-size: 18px; }
.header-right { display: flex; align-items: center; gap: 12px; }
#header-user { font-size: 13px; color: var(--muted); }
#logout-btn { padding: 6px 12px; background: none; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; cursor: pointer; color: var(--muted); }

/* Main content */
main {
    flex: 1; overflow-y: auto; padding: 16px; padding-bottom: calc(var(--nav-height) + 16px);
}

.tab-content { display: flex; flex-direction: column; gap: 16px; }

/* Mic button */
#mic-area { display: flex; flex-direction: column; align-items: center; padding: 24px 0; }

#mic-btn {
    width: 100px; height: 100px; border-radius: 50%; border: none;
    background: var(--primary); color: white; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all .2s; position: relative;
}
#mic-btn:hover { transform: scale(1.05); }
#mic-btn.recording {
    background: var(--danger);
    animation: pulse 1.5s ease-in-out infinite;
}
#mic-btn.processing { background: var(--warning); cursor: wait; }
#mic-btn.success-state { background: var(--success); }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .4); }
    50% { box-shadow: 0 0 0 20px rgba(239, 68, 68, 0); }
}

.spinner {
    width: 32px; height: 32px; border: 3px solid rgba(255,255,255,.3);
    border-top-color: white; border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#mic-status { margin-top: 12px; color: var(--muted); font-size: 14px; }

/* Cards */
.card {
    background: var(--card); border-radius: var(--radius); padding: 16px;
    border: 1px solid var(--border);
}

.card h3 { font-size: 16px; margin-bottom: 12px; }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .5px; }
.field-row { display: flex; gap: 8px; }
.field-row > * { flex: 1; }

.actions { display: flex; gap: 8px; margin-top: 12px; }
.actions > * { flex: 1; }

/* Success message */
.success {
    display: flex; align-items: center; gap: 12px; padding: 16px;
    border-color: var(--success); background: #ecfdf5;
}

/* Stats */
#stats-area { display: flex; gap: 8px; }
.stat-card {
    flex: 1; background: var(--card); border-radius: var(--radius);
    padding: 16px; text-align: center; border: 1px solid var(--border);
}
.stat-number { display: block; font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; margin-top: 4px; }

/* Advanced fields toggle */
.advanced-toggle {
    background: none; border: none; color: var(--primary); font-size: 13px;
    cursor: pointer; padding: 4px 0; font-weight: 500;
}

/* History */
.filter-bar { margin-bottom: 8px; }
.filter-bar select { max-width: 200px; }

.history-item {
    background: var(--card); border-radius: var(--radius); padding: 12px 14px;
    border: 1px solid var(--border); margin-bottom: 8px;
}
.history-item .hi-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.history-item .hi-type {
    font-size: 11px; font-weight: 600; text-transform: uppercase; padding: 2px 8px;
    border-radius: 4px; background: #ede9fe; color: #7c3aed;
}
.history-item .hi-type.encounter { background: #e0f2fe; color: #0369a1; }
.history-item .hi-date { font-size: 12px; color: var(--muted); }
.history-item .hi-name { font-weight: 600; font-size: 15px; }
.history-item .hi-details { font-size: 13px; color: var(--muted); margin-top: 2px; }
.hi-status { font-size: 11px; margin-top: 4px; }
.hi-status.submitted { color: var(--success); }
.hi-status.failed { color: var(--danger); }
.hi-status.pending { color: var(--warning); }

.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Settings */
.settings-section { margin-bottom: 16px; }
.settings-section p { margin-bottom: 8px; }

.rotation-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 0; border-bottom: 1px solid var(--border);
}
.rotation-item:last-child { border: none; }
.ri-info { font-size: 14px; }
.ri-dates { font-size: 12px; color: var(--muted); }

/* Supervisor search results */
.sup-results { list-style: none; max-height: 120px; overflow-y: auto; }
.sup-results li {
    padding: 8px 10px; cursor: pointer; border-radius: 6px; font-size: 14px;
}
.sup-results li:hover { background: var(--bg); }
.sup-results li.selected { background: #ede9fe; color: var(--primary); font-weight: 500; }

/* Bottom Nav */
#bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--nav-height); background: var(--card);
    border-top: 1px solid var(--border); z-index: 100;
}
.nav-btn {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 2px; background: none; border: none;
    color: var(--muted); font-size: 11px; cursor: pointer; transition: color .15s;
}
.nav-btn.active { color: var(--primary); }
.nav-btn svg { stroke: currentColor; }

/* Mobile adjustments */
@media (min-width: 480px) {
    main { max-width: 480px; margin: 0 auto; width: 100%; }
}
