/* === 1CO Dashboard — Dark Theme === */

:root {
    --bg-primary: #0f1419;
    --bg-secondary: #1a2332;
    --bg-card: #1e293b;
    --bg-card-hover: #253347;
    --border-color: #2d3d50;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --green: #22c55e;
    --green-bg: rgba(34, 197, 94, 0.15);
    --yellow: #eab308;
    --yellow-bg: rgba(234, 179, 8, 0.15);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.15);
    --radius: 8px;
    --radius-lg: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
h1:focus, h2:focus, h3:focus { outline: none; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* === Layout === */
.page { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem 0 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow: hidden;
    z-index: 100;
}

.sidebar-brand {
    padding: 0 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.sidebar-logo {
    max-width: 180px;
    width: 100%;
    height: auto;
    display: block;
    border-radius: var(--radius-lg);
}

.sidebar {
    display: flex;
    flex-direction: column;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 0.5rem;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s;
}

.sidebar nav a:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.sidebar nav a.active {
    background: var(--accent-blue);
    color: white;
}

.sidebar nav a .nav-icon { font-size: 1.1rem; width: 1.5rem; text-align: center; }

/* === Sidebar Footer === */
.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-user {
    margin-bottom: 0.5rem;
}

.sidebar-user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-user-role {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-footer-links {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.sidebar-footer-links a {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.2rem 0;
    transition: color 0.15s;
}

.sidebar-footer-links a:hover {
    color: var(--accent-blue);
}

.main-content {
    margin-left: 240px;
    flex: 1;
    padding: 2rem;
    max-width: 1400px;
}

/* === Page Header === */
.page-header {
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.page-header .subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* === Cards === */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

/* === GYR Badges === */
.gyr-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.gyr-badge.green { background: var(--green-bg); color: var(--green); }
.gyr-badge.yellow { background: var(--yellow-bg); color: var(--yellow); }
.gyr-badge.red { background: var(--red-bg); color: var(--red); }

.gyr-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.gyr-dot.green { background: var(--green); }
.gyr-dot.yellow { background: var(--yellow); }
.gyr-dot.red { background: var(--red); }

/* === Alert Items === */
.alert-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    margin-bottom: 0.5rem;
    transition: background 0.15s;
    cursor: pointer;
}

.alert-item:hover { background: var(--bg-card-hover); }

.alert-item.severity-red { border-left: 3px solid var(--red); }
.alert-item.severity-yellow { border-left: 3px solid var(--yellow); }

.alert-item .patient-info { flex: 1; }

.alert-item .patient-name {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.15rem;
}

.alert-item .alert-detail {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.alert-item .alert-time {
    color: var(--text-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}

.alert-item .alert-actions {
    display: flex;
    gap: 0.5rem;
}

/* === Tables === */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 0.625rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
}

.data-table td {
    padding: 0.75rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.data-table tr:hover td { background: var(--bg-card-hover); }
.data-table tr { cursor: pointer; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s;
}

.btn:hover { background: var(--bg-card-hover); }
.btn-primary { background: var(--accent-blue); border-color: var(--accent-blue); color: white; }
.btn-primary:hover { background: var(--accent-blue-hover); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }

/* === Forms === */
.form-input, .form-select {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus { border-color: var(--accent-blue); }
.form-input::placeholder { color: var(--text-muted); }

/* === Filter Bar === */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

/* === Date Range Filter === */
.date-range-filter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.date-range-presets {
    display: flex;
    gap: 2px;
}

.date-range-filter input[type="date"] {
    width: 140px;
}

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -1px;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0.25rem;
}

.stat-card.green .stat-value { color: var(--green); }
.stat-card.yellow .stat-value { color: var(--yellow); }
.stat-card.red .stat-value { color: var(--red); }
.stat-card.blue .stat-value { color: var(--accent-blue); }

/* === Timeline === */
.timeline { position: relative; padding-left: 2rem; }

.timeline::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-color);
}

.timeline-item {
    position: relative;
    margin-bottom: 1.25rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -1.75rem;
    top: 1rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background: var(--bg-primary);
}

.timeline-item.green::before { border-color: var(--green); background: var(--green); }
.timeline-item.yellow::before { border-color: var(--yellow); background: var(--yellow); }
.timeline-item.red::before { border-color: var(--red); background: var(--red); }
.timeline-item.pending::before { border-color: var(--text-muted); background: var(--bg-primary); }
.timeline-item.sent::before { border-color: var(--accent-blue); background: var(--accent-blue); }

.timeline-item .timepoint {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.timeline-item .message-text {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 0.35rem;
}

.timeline-item .timeline-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* === GYR Distribution Bar === */
.gyr-bar {
    display: flex;
    height: 24px;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-secondary);
}

.gyr-bar .segment { transition: width 0.3s; }
.gyr-bar .segment.green { background: var(--green); }
.gyr-bar .segment.yellow { background: var(--yellow); }
.gyr-bar .segment.red { background: var(--red); }

/* === Benchmark Bars === */
.benchmark-row { display: flex; flex-direction: column; gap: 1rem; }

.benchmark-item {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.benchmark-label {
    width: 160px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.benchmark-bar-container {
    flex: 1;
    height: 24px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    overflow: hidden;
}

.benchmark-bar {
    height: 100%;
    border-radius: var(--radius);
    transition: width 0.4s ease;
}

.benchmark-bar.accent { background: var(--accent-blue); }
.benchmark-bar.muted { background: var(--text-muted); opacity: 0.5; }

.benchmark-value {
    width: 50px;
    text-align: right;
    font-weight: 700;
    font-size: 0.95rem;
}

.stat-good { color: var(--green); font-weight: 600; }
.stat-warn { color: var(--yellow); font-weight: 600; }
.stat-bad { color: var(--red); font-weight: 600; }

/* === Loading === */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-muted);
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-state .icon { font-size: 2.5rem; margin-bottom: 0.75rem; }

/* === Sidebar Sections === */
.sidebar-separator {
    height: 1px;
    background: var(--border-color);
    margin: 0.75rem 1rem;
}

.sidebar-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    padding: 0.25rem 1.25rem 0.35rem;
}

/* === Admin Forms === */
.admin-form {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.admin-form h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.form-error {
    color: var(--red);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* === Toggle Switch === */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    cursor: pointer;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border-color);
    border-radius: 22px;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider { background: var(--accent-blue); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

/* === Status Badge === */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge.active { background: var(--green-bg); color: var(--green); }
.status-badge.inactive { background: var(--red-bg); color: var(--red); }

/* === JSON Display === */
.json-display {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.75rem;
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
    line-height: 1.5;
}

/* === Cohort Group === */
.cohort-group-header {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    padding: 0.75rem 0 0.5rem;
    margin-top: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

/* === Expandable Row === */
.expandable-row {
    cursor: pointer;
}

.expandable-row:hover td {
    background: var(--bg-card-hover);
}

.expand-detail {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1rem;
    margin: 0.5rem 0;
}

.expand-detail h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

/* === Inline Edit === */
.inline-edit-input {
    background: var(--bg-secondary);
    border: 1px solid var(--accent-blue);
    border-radius: var(--radius);
    padding: 0.3rem 0.5rem;
    color: var(--text-primary);
    font-size: 0.85rem;
    width: 100%;
    outline: none;
}

/* === Drilldown / Child Rows === */
.drilldown-row td {
    background: var(--bg-secondary);
    font-size: 0.825rem;
}

.drilldown-row:hover td {
    background: var(--bg-card-hover);
}

/* === Hamburger Button === */
.hamburger-btn {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 200;
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 8px;
}

.hamburger-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all 0.2s;
}

.hamburger-btn:hover {
    background: var(--bg-card-hover);
}

/* === Sidebar Overlay === */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
}

/* === Responsive === */
@media (max-width: 768px) {
    .hamburger-btn { display: flex; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-open .sidebar-overlay {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: 4rem; /* Space for hamburger button */
    }

    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
