:root {
    --bg: #f3f6fb;
    --ink: #0c1b2a;
    --muted: #5f6d7b;
    --line: #d8e0ea;
    --card: #ffffff;
    --brand: #0f8b8d;
    --brand-2: #125b76;
    --accent: #f4a261;
    --danger: #d64545;
    --success: #1f9d55;
    --warning: #b45309;
    --warning-soft: #fef3c7;
    --focus: rgba(15, 139, 141, 0.36);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --radius-xl: 22px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.08);
    --shadow-md: 0 10px 24px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 18px 42px rgba(15, 23, 42, 0.1);
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
    margin: 0;
    font-family: 'Manrope', sans-serif;
    color: var(--ink);
    background: radial-gradient(circle at top right, #e7f7fa 0%, var(--bg) 40%, #eef2f8 100%);
}

a { color: inherit; text-decoration: none; }
a:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 8px; }
small { color: var(--muted); }
img, video, canvas, svg { max-width: 100%; height: auto; }

.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
    background: linear-gradient(190deg, #0f172a 0%, #14253c 100%);
    color: #dfe8f5;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}
.brand { display: flex; gap: 12px; align-items: flex-start; }
.brand-content {
    display: grid;
    gap: 4px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}
.brand-logo { width: auto; object-fit: contain; border-radius: 6px; }
.brand-mark {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: linear-gradient(140deg, var(--brand), var(--brand-2));
    font-weight: 800;
}
.brand h1 { margin: 0; font-size: 1rem; line-height: 1.2; }
.brand p { margin: 0; color: #9fb2cc; font-size: 0.82rem; }

.menu { display: grid; gap: 8px; }
.menu a,
.menu .menu-dropdown > summary {
    padding: 11px 12px;
    border-radius: 10px;
    color: #c9d7ea;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.menu .menu-dropdown > summary {
    list-style: none;
}
.menu .menu-dropdown > summary::after {
    content: "";
    width: 7px;
    height: 7px;
    border-right: 1.7px solid currentColor;
    border-bottom: 1.7px solid currentColor;
    transform: rotate(45deg);
    margin-left: auto;
    opacity: 0.8;
    transition: transform 0.18s ease, opacity 0.18s ease;
}
.menu .menu-dropdown[open] > summary::after {
    transform: rotate(225deg);
    opacity: 1;
}
.menu a.active,
.menu a:hover,
.menu .menu-dropdown[open] > summary,
.menu .menu-dropdown > summary:hover {
    background: rgba(255, 255, 255, 0.09);
    color: #fff;
}
.menu .menu-dropdown > summary::-webkit-details-marker { display: none; }
.menu-icon {
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.72;
}
.menu-icon svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.content { padding: 26px; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.topbar h2 { margin: 0; font-size: 1.6rem; }
.topbar p { margin: 3px 0 0; color: var(--muted); }
.user-chip {
    background: #fff;
    border: 1px solid var(--line);
    padding: 10px 14px;
    border-radius: 999px;
    font-weight: 600;
}

.alert {
    border-radius: var(--radius-md);
    padding: 12px 14px;
    margin: 0 0 14px;
    border: 1px solid transparent;
    box-shadow: var(--shadow-sm);
}
.alert.success { background: #e6f8ee; color: #1b6f41; border: 1px solid #b9e7cc; }
.alert.error { background: #ffecec; color: #8b2e2e; border: 1px solid #f7b7b7; }
.alert.warning { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.alert.info { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.alert ul { margin: 0; padding-left: 18px; }

.grid { display: grid; gap: 16px; }
.cards-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { grid-template-columns: minmax(320px, 0.95fr) minmax(540px, 1.3fr); }

.stat-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow-md);
}
.stat-card p { margin: 0; color: var(--muted); font-weight: 600; }
.stat-card h3 { margin: 8px 0 0; font-size: 2rem; }
.stat-card.warn h3 { color: #b65f20; }

.panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow-md);
}
.panel h3 { margin: 0 0 12px; }
.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
thead th {
    text-align: left;
    color: var(--muted);
    font-size: 0.82rem;
    letter-spacing: .02em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--line);
    padding: 10px 8px;
}
tbody td {
    border-bottom: 1px solid #edf1f5;
    padding: 11px 8px;
    vertical-align: top;
}
tbody tr:hover { background: #f8fafc; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-md); }
.table-wrap table { margin: 0; }
.table-wrap thead th { position: sticky; top: 0; z-index: 1; background: #fff; }

.pill {
    display: inline-block;
    border-radius: 999px;
    background: #ecf4ff;
    color: #305f93;
    font-size: 0.82rem;
    font-weight: 700;
    padding: 4px 10px;
}
.pill.success { background: #dcfce7; color: #166534; }
.pill.warning { background: #fef3c7; color: #92400e; }
.pill.danger { background: #fee2e2; color: #991b1b; }
.pill.neutral { background: #f1f5f9; color: #475569; }

.form-grid { display: grid; gap: 10px; }
.form-grid.compact { gap: 8px; }
label { display: grid; gap: 5px; font-weight: 600; font-size: 0.9rem; color: #304152; }
input, select, textarea {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font: inherit;
    background: #fff;
}
input:hover, select:hover, textarea:hover { border-color: #b8c4d3; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.14);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 10px 14px;
    font: inherit;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    transition: background-color .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}
.btn:disabled,
.btn[disabled],
.btn[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: .62;
    transform: none;
    box-shadow: none;
}
.btn-primary {
    color: #fff;
    background: linear-gradient(140deg, #0f8b8d, #125b76);
}
.btn-primary:hover { background: linear-gradient(140deg, #0b7476, #0f4d65); }
.btn-secondary {
    color: #fff;
    background: #334155;
}
.btn-secondary:hover { background: #1e293b; }
.btn-success {
    color: #fff;
    background: #166534;
}
.btn-success:hover { background: #14532d; }
.btn-danger {
    color: #fff;
    background: #b91c1c;
}
.btn-danger:hover { background: #991b1b; }
.btn-warning {
    color: #451a03;
    background: #fbbf24;
    border-color: #f59e0b;
}
.btn-warning:hover {
    color: #451a03;
    background: #f59e0b;
}
.btn-outline {
    color: #0f172a;
    background: #fff;
    border-color: #94a3b8;
}
.btn-outline:hover {
    color: #0f172a;
    background: #f8fafc;
    border-color: #64748b;
}
.btn-ghost {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #1e293b;
}
.btn-ghost:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
    color: #0f172a;
}
.btn-small {
    min-height: 32px;
    padding: 7px 10px;
    font-size: .85rem;
}
.btn-icon {
    width: 40px;
    min-width: 40px;
    padding-inline: 0;
}
.full { width: 100%; }

.inline-actions,
.inline-grade {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.filter-bar {
    display: flex;
    gap: 10px;
    align-items: end;
    flex-wrap: wrap;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: rgba(255,255,255,.82);
    box-shadow: var(--shadow-sm);
}
.filter-bar > * { min-width: 180px; }
.surface-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}
.chart-shell,
.chart-panel,
.chart-canvas-wrap {
    position: relative;
    height: clamp(260px, 28vw, 320px);
    min-height: 260px;
    max-height: 320px;
    overflow: hidden;
}
.chart-shell canvas,
.chart-panel canvas,
.chart-canvas-wrap canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}
.chart-empty-state {
    min-height: clamp(260px, 28vw, 320px);
}
.icon-safe {
    display: inline-grid;
    width: 1.15em;
    height: 1.15em;
    place-items: center;
    flex: 0 0 auto;
    line-height: 1;
}
.icon-safe svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.empty-state {
    display: grid;
    gap: 6px;
    place-items: center;
    text-align: center;
    min-height: 88px;
    padding: 18px;
    color: var(--muted);
    border: 1px dashed #cbd5e1;
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, #fff, #f8fafc);
}
.empty-state::before {
    content: "";
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: radial-gradient(circle, #4338ca 0 24%, #eef2ff 26% 100%);
}
.loading-skeleton {
    position: relative;
    overflow: hidden;
    background: #e2e8f0;
    border-radius: 999px;
}
.loading-skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.7), transparent);
    animation: skeleton-shimmer 1.25s infinite;
}
@keyframes skeleton-shimmer { 100% { transform: translateX(100%); } }
.fade-in { animation: fade-in .22s ease both; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.inline-actions > form,
.inline-grade > form {
    display: inline-flex;
}
.inline-grade input[type="number"] { width: 90px; }
.inline-grade input[type="text"] { min-width: 180px; }

.pager { margin-top: 14px; }
.pager nav { display: flex; justify-content: center; }
.pagination {
    display: grid;
    gap: 12px;
    margin-top: 14px;
}
.pagination-mobile {
    display: none;
    gap: 8px;
}
.pagination-desktop {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.pagination-summary {
    margin: 0;
    color: var(--muted);
    font-size: .88rem;
}
.pagination-list {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.pagination-link,
.pagination-ellipsis {
    display: inline-flex;
    min-width: 36px;
    min-height: 36px;
    align-items: center;
    justify-content: center;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 8px 11px;
    background: #fff;
    color: #1e293b;
    font-weight: 700;
}
.pagination-link:hover {
    border-color: #94a3b8;
    background: #f8fafc;
}
.pagination-link:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}
.pagination-link.is-active {
    border-color: var(--brand-2);
    background: var(--brand-2);
    color: #fff;
}
.pagination-link.is-disabled {
    cursor: not-allowed;
    opacity: .58;
}
.pagination-ellipsis {
    border-color: transparent;
    background: transparent;
    min-width: auto;
}

.calendar-filters {
    display: flex;
    gap: 10px;
    align-items: center;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 10px;
}

.day-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    background: #fff;
    min-height: 108px;
}

.day-card header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}

.day-card .rate {
    font-size: 1.15rem;
    font-weight: 800;
}

.day-card.status-good {
    border-color: #b6e5c6;
    background: #f2fbf5;
}

.day-card.status-medium {
    border-color: #f5dfb7;
    background: #fffaf0;
}

.day-card.status-low {
    border-color: #f0c1c1;
    background: #fff4f4;
}

.day-card.today {
    box-shadow: 0 0 0 2px rgba(15, 139, 141, 0.18);
}

.muted { color: var(--muted); }

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}
.login-wrap {
    width: min(980px, 100%);
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(21, 36, 61, 0.13);
}
.login-side {
    padding: 44px;
    color: #fff;
    background: linear-gradient(160deg, #0f8b8d 0%, #125b76 55%, #12253e 100%);
}
.login-side h1 { margin: 0; font-size: 2rem; }
.login-side p { margin: 10px 0 0; max-width: 34ch; color: #dcf4f7; }
.login-badges { margin-top: 20px; display: flex; gap: 8px; flex-wrap: wrap; }
.login-badges span {
    border: 1px solid rgba(255,255,255,.34);
    border-radius: 999px;
    font-size: .82rem;
    padding: 6px 10px;
}
.login-card { padding: 34px; }
.login-card h2 { margin: 0; }
.login-card p { margin: 6px 0 16px; color: var(--muted); }
.checkline { display: flex; align-items: center; gap: 8px; }

@media (max-width: 1100px) {
    .calendar-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: relative; top: auto; z-index: 1; padding: 16px 14px; gap: 14px; }
    .brand { gap: 10px; }
    .brand-mark { width: 40px; height: 40px; border-radius: 12px; }
    .menu { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
    .menu a { padding: 10px; text-align: center; font-size: .92rem; }
    .content { padding: 16px; }
    .topbar { align-items: flex-start; gap: 10px; flex-wrap: wrap; }
    .topbar h2 { font-size: 1.3rem; }
    .panel, .stat-card { padding: 14px; border-radius: 14px; }
    .btn { padding: 10px 12px; }
    .drawer { width: 94vw; max-width: 94vw; }
    .cards-4, .split, .login-wrap { grid-template-columns: 1fr; }
    .calendar-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .login-side, .login-card { padding: 22px; }
    table { display: block; overflow-x: auto; white-space: nowrap; }
    thead, tbody, tr { width: 100%; }
}

@media (max-width: 600px) {
    .content { padding: 12px; }
    .menu { grid-template-columns: 1fr; }
    .menu a { text-align: left; }
    .inline-actions, .inline-grade { width: 100%; }
    .inline-actions > *,
    .inline-grade > * { min-width: 0; }
    .inline-actions .btn, .inline-grade .btn,
    .inline-actions > form, .inline-grade > form { width: 100%; }
    .user-chip { padding: 8px 12px; font-size: .9rem; }
    .topbar h2 { font-size: 1.15rem; }
    .topbar p { font-size: .85rem; }
    .login-wrap { border-radius: 14px; }
    .login-side h1 { font-size: 1.4rem; }
    .login-side, .login-card { padding: 16px; }
    .form-grid { gap: 8px; }
    input, select, textarea { padding: 9px 10px; font-size: 16px; } /* prevent iOS zoom */
    .calendar-grid { grid-template-columns: 1fr; }
    .calendar-filters { flex-direction: column; align-items: stretch; }
    .pagination-mobile { display: flex; }
    .pagination-mobile .pagination-link { flex: 1; }
    .pagination-desktop { display: none; }
    .filter-bar { align-items: stretch; }
    .filter-bar > * { min-width: 100%; }
    .chart-shell,
    .chart-panel,
    .chart-canvas-wrap {
        height: clamp(220px, 62vw, 260px);
        min-height: 220px;
        max-height: 260px;
    }
    .chart-empty-state {
        min-height: clamp(220px, 62vw, 260px);
    }
}
