:root {
    color-scheme: light;
    --bg: #f6f7f4;
    --panel: #ffffff;
    --panel-soft: #fbfbf8;
    --ink: #1f2933;
    --muted: #68717f;
    --line: #e1e5dc;
    --primary: #2f6fed;
    --primary-dark: #2255bd;
    --accent: #0f8b78;
    --danger: #c92a2a;
    --success: #087f5b;
    --shadow: 0 12px 28px rgba(32, 38, 46, .07);
    --radius: 10px;
    --calendar-radius: 18px;
    --control: 34px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(180deg, #fbfcfa 0, var(--bg) 260px),
        var(--bg);
    color: var(--ink);
}

body[data-theme="dark"] {
    --bg: #111418;
    --panel: #181c22;
    --panel-soft: #20262e;
    --ink: #edf2f7;
    --muted: #a4afbd;
    --line: #303844;
    --primary: #6ea8ff;
    --primary-dark: #9cc4ff;
    --accent: #45d6bd;
    --shadow: 0 18px 36px rgba(0, 0, 0, .26);
    background:
        linear-gradient(180deg, #171b21 0, var(--bg) 280px),
        var(--bg);
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea {
    font: inherit;
}

button {
    appearance: none;
}

.app-shell {
    display: grid;
    grid-template-columns: 218px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px 12px;
    background: #ffffff;
    color: var(--ink);
    border-right: 1px solid var(--line);
}

body[data-theme="dark"] .sidebar {
    background: #15191f;
}

.brand, .login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    background: #1f2933;
    color: #ffffff;
    font-weight: 800;
    box-shadow: 0 8px 18px rgba(31, 41, 51, .12);
}

body[data-theme="dark"] .brand-mark {
    background: #edf2f7;
    color: #111418;
}

.brand strong, .profile-chip strong { display: block; }
.brand small, .profile-chip small, .login-brand p {
    color: var(--muted);
    display: block;
    margin-top: 2px;
    font-size: 12px;
}

.nav {
    display: grid;
    gap: 6px;
}

.nav a, .logout {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 36px;
    padding: 8px 10px;
    border-radius: var(--radius);
    color: #556170;
    font-weight: 700;
}

body[data-theme="dark"] .nav a,
body[data-theme="dark"] .logout {
    color: #b8c2cf;
}

.nav a.active, .nav a:hover, .logout:hover {
    background: #eef3ff;
    color: var(--primary-dark);
}

body[data-theme="dark"] .nav a.active,
body[data-theme="dark"] .nav a:hover,
body[data-theme="dark"] .logout:hover {
    background: #243049;
    color: #f8fbff;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel-soft);
    color: var(--ink);
    cursor: pointer;
    font-weight: 800;
    font-size: 13px;
    line-height: 1;
    text-align: center;
}

.theme-toggle:hover {
    border-color: var(--primary);
}

.profile-chip {
    margin-top: auto;
    display: grid;
    grid-template-columns: 30px 1fr;
    align-items: center;
    gap: 9px;
    padding: 9px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel-soft);
}

.avatar {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--avatar);
    color: #fff;
    font-weight: 800;
}

.main-panel {
    display: flex;
    flex-direction: column;
    padding: 18px 20px;
    min-width: 0;
}

.page-header, .calendar-toolbar, .modal-head, .modal-actions, .panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.page-header { margin-bottom: 14px; }
.page-header h1, .login-brand h1 {
    margin: 0;
    font-size: 23px;
    line-height: 1.15;
    letter-spacing: 0;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent);
    font-weight: 800;
    text-transform: uppercase;
    font-size: 11px;
}

.button, .icon-button, .segmented button {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: var(--radius);
    min-height: var(--control);
    height: var(--control);
    padding: 0 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 700;
    font-size: 13px;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
}

body[data-theme="dark"] .button,
body[data-theme="dark"] .icon-button,
body[data-theme="dark"] .segmented button {
    background: #20262e;
    color: var(--ink);
}

.icon-button {
    width: var(--control);
    padding: 0;
    color: var(--ink);
}

.icon-button svg,
.button svg,
.nav svg,
.logout svg,
.theme-toggle svg {
    color: currentColor;
    stroke: currentColor;
}

.button.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

body[data-theme="dark"] .button.primary {
    background: #3d7df0;
    border-color: #3d7df0;
    color: #fff;
}

.button.primary:hover { background: var(--primary-dark); }
.button.subtle { background: #f0f3ee; }
body[data-theme="dark"] .button.subtle { background: #252c35; }
.button.danger { color: var(--danger); border-color: #fecaca; }
.button.ghost { background: #fff; }
body[data-theme="dark"] .button.ghost {
    background: #20262e;
    border-color: #57343a;
}
.hidden { display: none !important; }
.spacer { flex: 1; }

svg { width: 16px; height: 16px; }

.calendar-toolbar {
    flex-wrap: wrap;
    margin-bottom: 10px;
    padding: 8px 10px;
    background: rgba(255,255,255,.86);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 8px 20px rgba(32, 38, 46, .04);
}

body[data-theme="dark"] .calendar-toolbar {
    background: rgba(24,28,34,.88);
}

.date-controls, .filters {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.date-controls {
    flex: 1 1 270px;
}

.filters {
    justify-content: flex-end;
    flex: 1 1 480px;
}

.stepper {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

body[data-theme="dark"] .stepper,
body[data-theme="dark"] .toolbar-field,
body[data-theme="dark"] .segmented {
    background: #20262e;
}

.stepper .button,
.stepper .icon-button {
    border-color: transparent;
    min-height: 28px;
    height: 28px;
}

.stepper .icon-button {
    width: 28px;
}

.arrow-symbol {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--ink);
    font-size: 24px;
    font-weight: 900;
    line-height: 1;
    transform: translateY(-1px);
}

body[data-theme="dark"] .arrow-symbol {
    color: #f8fbff;
}

#calendarTitle {
    margin: 0 0 0 6px;
    font-size: 18px;
    min-width: 190px;
}

.toolbar-field {
    display: grid;
    grid-template-columns: auto minmax(145px, 1fr);
    align-items: center;
    gap: 7px;
    min-width: 210px;
    padding: 3px 3px 3px 9px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.toolbar-field span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.toolbar-field select {
    border: 0;
    min-height: 28px;
    padding: 4px 26px 4px 8px;
    box-shadow: none;
}

select, input, textarea {
    width: 100%;
    min-height: var(--control);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 7px 10px;
    background: #fff;
    color: var(--ink);
    outline: none;
    font-size: 13px;
}

input[type="file"] {
    display: flex;
    align-items: center;
    padding: 5px 8px;
    line-height: 1;
}

input[type="file"]::file-selector-button {
    height: 24px;
    margin: 0 9px 0 0;
    padding: 0 10px;
    border: 0;
    border-radius: 7px;
    background: var(--panel-soft);
    color: var(--ink);
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
}

body[data-theme="dark"] input[type="file"]::file-selector-button {
    background: #2b3440;
    color: var(--ink);
}

body[data-theme="dark"] select,
body[data-theme="dark"] input,
body[data-theme="dark"] textarea {
    background: #20262e;
    color: var(--ink);
}

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

.segmented {
    display: inline-flex;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.segmented button {
    min-height: 28px;
    border: 0;
    background: transparent;
}

.segmented button.active {
    background: #1f2933;
    color: #fff;
}

body[data-theme="dark"] .segmented button.active {
    background: #edf2f7;
    color: #111418;
}

.calendar-surface, .admin-panel, .login-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.calendar-surface {
    overflow: hidden;
    border-radius: var(--calendar-radius);
}

.calendar-grid.month {
    display: grid;
    grid-template-columns: repeat(5, minmax(116px, 1fr));
}

.weekday {
    padding: 8px 9px;
    background: #f0f3ee;
    color: #5c6672;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.weekday:first-child {
    border-top-left-radius: var(--calendar-radius);
}

.weekday:nth-child(5) {
    border-top-right-radius: var(--calendar-radius);
}

body[data-theme="dark"] .weekday,
body[data-theme="dark"] .agenda-head {
    background: #20262e;
    color: #c7d0dd;
}

.day-cell {
    min-height: 104px;
    padding: 7px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    cursor: pointer;
}

body[data-theme="dark"] .day-cell,
body[data-theme="dark"] .slot {
    background: #181c22;
}

.day-cell:hover { background: #f8fbff; }
.day-cell.muted { background: #fafaf7; color: #a0a7b0; }
body[data-theme="dark"] .day-cell:hover,
body[data-theme="dark"] .slot:hover { background: #202936; }
body[data-theme="dark"] .day-cell.muted {
    background: #15191f;
    color: #6f7b89;
}
.day-cell.today {
    position: relative;
    background: #edf4ff;
    box-shadow: inset 0 0 0 2px var(--primary), inset 0 1px 0 rgba(255,255,255,.9);
}

body[data-theme="dark"] .day-cell.today {
    background: #1f2d45;
}

.day-cell.today::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--primary);
}

.day-number {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    font-weight: 800;
    font-size: 12px;
    color: var(--ink);
}

.day-cell.today .day-number span {
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
}

.day-cell.today .day-number small {
    color: var(--primary-dark);
    font-weight: 900;
}

.event-pill {
    display: block;
    width: 100%;
    margin: 4px 0;
    padding: 5px 7px;
    border: 0;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    text-align: left;
    line-height: 1.25;
    overflow: hidden;
    font-size: 11px;
    box-shadow: inset 0 -20px 38px rgba(0,0,0,.08);
}

.event-pill strong {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.event-pill small {
    display: block;
    opacity: .9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agenda-view {
    display: grid;
    grid-template-columns: 58px repeat(var(--days), minmax(145px, 1fr));
    min-width: 660px;
}

.agenda-head, .time-label, .slot {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.agenda-view {
    border-radius: var(--calendar-radius);
}

.agenda-head {
    min-height: 42px;
    padding: 8px;
    background: #f0f3ee;
    font-weight: 800;
    font-size: 12px;
}

.agenda-head.today-head {
    background: #edf4ff;
    color: var(--primary-dark);
    box-shadow: inset 0 3px 0 var(--primary);
}

.time-label {
    min-height: 48px;
    padding: 7px;
    color: var(--muted);
    font-size: 12px;
    background: #fbfcff;
}

body[data-theme="dark"] .time-label {
    background: #15191f;
}

.slot {
    position: relative;
    min-height: 48px;
    padding: 3px;
    background: #fff;
    cursor: pointer;
}

.slot:hover { background: #f8fbff; }
.slot .event-pill { margin: 0 0 4px; }

.modal {
    width: min(640px, calc(100vw - 28px));
    border: 0;
    border-radius: var(--radius);
    padding: 0;
    box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
    background: var(--panel);
    color: var(--ink);
}

.modal::backdrop { background: rgba(15, 23, 42, .46); }
.modal form { padding: 18px; }
.modal h2 { margin: 0; }

body[data-theme="dark"] .modal {
    background: #181c22;
    color: var(--ink);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 11px;
    margin: 14px 0;
}

label {
    display: grid;
    gap: 5px;
    color: #344054;
    font-weight: 700;
    font-size: 13px;
}

body[data-theme="dark"] label {
    color: #d7dfeb;
}

.full { grid-column: 1 / -1; }

.alert {
    padding: 10px 12px;
    border-radius: var(--radius);
    margin: 12px 0;
    font-weight: 700;
}

.alert.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert.success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }

.login-body {
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(120deg, rgba(47,111,237,.08), transparent 42%),
        linear-gradient(315deg, rgba(15,139,120,.1), transparent 38%),
        #f5f7fb;
}

body.login-body[data-theme="dark"] {
    background:
        linear-gradient(120deg, rgba(110,168,255,.14), transparent 42%),
        linear-gradient(315deg, rgba(69,214,189,.13), transparent 38%),
        #111418;
}

.login-card {
    width: min(390px, 100%);
    padding: 22px;
}

.login-brand {
    align-items: flex-start;
    margin-bottom: 18px;
}

.login-brand .brand-mark {
    background: #1f2933;
    color: #fff;
}

body[data-theme="dark"] .login-brand .brand-mark {
    background: #edf2f7;
    color: #111418;
}

.login-brand p { color: var(--muted); margin: 6px 0 0; }
.stack { display: grid; gap: 14px; }
.login-hint {
    margin-top: 18px;
    padding: 12px;
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    color: var(--muted);
    font-size: 13px;
}

.admin-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.admin-import {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(320px, .9fr);
    align-items: center;
    gap: 14px;
    margin-bottom: 14px;
    padding: 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.app-footer {
    margin-top: auto;
    padding: 18px 4px 2px;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

.app-footer a {
    color: inherit;
    text-decoration: none;
    font-weight: 800;
}

.app-footer a:hover {
    color: var(--ink);
}

.admin-import h2 {
    margin: 0 0 4px;
    font-size: 17px;
}

.admin-import p {
    margin: 0;
    color: var(--muted);
    line-height: 1.35;
}

.import-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.admin-panel { padding: 14px; }
.admin-panel h2 { margin: 0; }
.compact-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 12px 0;
}

.form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.compact-form .button, .compact-form .check { min-height: var(--control); }
.check {
    display: flex;
    align-items: center;
    gap: 8px;
}
.check input { width: auto; min-height: auto; }

.list-table {
    display: grid;
    gap: 6px;
}

.list-row {
    display: grid;
    grid-template-columns: 12px 1fr;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    text-align: left;
    color: var(--ink);
    cursor: pointer;
}

.list-row strong {
    color: var(--ink);
}

body[data-theme="dark"] .list-row {
    background: #1b2027;
}

.list-row:hover { background: #f8fbff; }
body[data-theme="dark"] .list-row:hover { background: #202936; }
.list-row small {
    grid-column: 2;
    color: var(--muted);
}

.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-height: 34px;
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.pagination-bar .icon-button {
    width: 30px;
    height: 30px;
    min-height: 30px;
}

.pagination-bar .icon-button:disabled {
    cursor: not-allowed;
    opacity: .45;
}

.pagination-bar .arrow-symbol {
    font-size: 22px;
}

.dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
}

@media (max-width: 980px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: static;
        height: auto;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }
    .profile-chip { margin-top: 0; margin-left: auto; }
    .main-panel { padding: 14px; }
    .calendar-surface { overflow-x: auto; }
    .admin-grid { grid-template-columns: 1fr; }
    .admin-import { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .page-header, .calendar-toolbar, .modal-actions { align-items: stretch; flex-direction: column; }
    .page-header h1 { font-size: 21px; }
    .filters, .date-controls { width: 100%; justify-content: stretch; }
    .filters > *, .date-controls h2, .stepper { flex: 1; }
    .toolbar-field { grid-template-columns: 1fr; min-width: 100%; gap: 3px; }
    .calendar-grid.month { grid-template-columns: repeat(5, minmax(96px, 1fr)); min-width: 480px; }
    .form-grid, .compact-form { grid-template-columns: 1fr; }
    .import-form { grid-template-columns: 1fr; }
    .full { grid-column: auto; }
    .profile-chip { width: 100%; margin-left: 0; }
}
