/* ===== CSS Variables ===== */
:root {
    --color-bg:          #f8fafc;
    --color-surface:     #ffffff;
    --color-border:      #e2e8f0;
    --color-border-dark: #cbd5e1;
    --color-text:        #1e293b;
    --color-text-muted:  #64748b;
    --color-primary:     #3b82f6;
    --color-primary-dk:  #2563eb;

    --color-inhouse:     #008080;
    --color-inhouse-dk:  #059669;
    --color-reservation: #9ca3af;
    --color-reservation-dk: #6b7280;
    --color-normal:      #4169e1;
    --color-normal-dk:   #2563eb;

    --header-height: 52px;
    --sidebar-width: 248px;
    --slot-height:   20px;
    --time-col-w:    56px;
}

/* ===== Reset / Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 14px;
    color: var(--color-text);
    background: var(--color-bg);
    min-height: 100vh;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Site Header ===== */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.site-header__inner {
    display: flex;
    align-items: center;
    gap: 24px;
    height: 100%;
    padding: 0 16px;
}
.site-header__logo {
    font-weight: 700;
    font-size: 16px;
    color: var(--color-text);
    text-decoration: none;
    white-space: nowrap;
}
.site-header__nav {
    display: flex;
    gap: 4px;
    flex: 1;
}
.site-header__nav a {
    padding: 6px 12px;
    border-radius: 6px;
    color: var(--color-text-muted);
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, color .15s;
}
.site-header__nav a:hover,
.site-header__nav a.active {
    background: #eff6ff;
    color: var(--color-primary);
}
.site-header__user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--color-text-muted);
    white-space: nowrap;
}
.btn-logout {
    padding: 4px 10px;
    border: 1px solid var(--color-border-dark);
    border-radius: 5px;
    color: var(--color-text-muted);
    font-size: 12px;
    text-decoration: none;
    transition: background .15s;
}
.btn-logout:hover { background: #f1f5f9; text-decoration: none; }

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    padding: 7px 14px;
    border: 1px solid var(--color-border-dark);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, border-color .15s;
}
.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn--primary {
    background: var(--color-primary);
    border-color: var(--color-primary-dk);
    color: #fff;
}
.btn--primary:hover { background: var(--color-primary-dk); }
.btn--danger  { background: #ef4444; border-color: #dc2626; color: #fff; }
.btn--danger:hover { background: #dc2626; }
.btn--sm { padding: 4px 9px; font-size: 12px; }
.btn--full { width: 100%; text-align: center; }

/* ===== Alerts ===== */
.alert {
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 13px;
}
.alert--error { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }

/* ===== Login page ===== */
.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--header-height));
    padding: 32px 16px;
}
.login-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 36px 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 4px 12px rgba(0,0,0,.06);
}
.login-card__title {
    font-size: 22px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 24px;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--color-text);
}
.form-control {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--color-border-dark);
    border-radius: 6px;
    font-size: 14px;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.form-control[readonly] { background: #f8fafc; color: var(--color-text-muted); }

.required { color: #ef4444; }

.form-fieldset {
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 16px;
}
.form-fieldset legend {
    padding: 0 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.radio-label,
.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 16px;
    cursor: pointer;
    font-size: 13px;
}
.flags-row { display: flex; gap: 8px; flex-wrap: wrap; }
.repeat-row { display: flex; align-items: center; gap: 8px; }
.repeat-input { width: 70px; }
.repeat-label { font-size: 13px; color: var(--color-text-muted); }
.user-checkboxes { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.time-row { display: flex; gap: 16px; }
.time-row .form-group { flex: 1; }
.form-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 24px;
    flex-wrap: wrap;
}

/* ===== Page wrap ===== */
.page-wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h1 { font-size: 20px; font-weight: 700; }

/* ===== Year filter ===== */
.year-nav { display: flex; align-items: center; gap: 6px; }
.year-nav__label { font-size: 14px; font-weight: 600; min-width: 64px; text-align: center; }
.btn-nav--disabled { opacity: .3; cursor: default; pointer-events: none; }

/* ===== Events list table ===== */
.events-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.events-table th,
.events-table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    vertical-align: middle;
}
.events-table th {
    background: #f1f5f9;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--color-text-muted);
}
.events-table__row:hover { background: #f8fafc; }
.row--inhouse     td:first-child { border-left: 3px solid var(--color-inhouse); }
.row--reservation td:first-child { border-left: 3px solid var(--color-reservation); }
.td-center { text-align: center; }
.td-nowrap { white-space: nowrap; min-width: max-content; }
.td-actions { white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.empty-state { padding: 32px 0; text-align: center; color: var(--color-text-muted); }

/* ===== Calendar layout ===== */
.cal-layout {
    display: flex;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

/* ===== Sidebar ===== */
.cal-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    overflow-y: auto;
    padding: 12px 8px;
    border-right: 1px solid var(--color-border);
    background: var(--color-surface);
}

/* ===== Sidebar year nav ===== */
.sidebar-year-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 4px 10px;
}
.sidebar-year {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
}

/* ===== Mini calendar ===== */
.mini-cal { margin-bottom: 16px; }
.mini-cal__head {
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: 4px 0 6px;
}
.mini-cal__table {
    width: 100%;
    border-collapse: collapse;
}
.mini-cal__table th {
    font-size: 10px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-align: center;
    padding: 2px 0;
}
.mini-cal__table td {
    text-align: center;
    padding: 1px;
}
.mini-cal__table td a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 11px;
    color: var(--color-text);
    text-decoration: none;
    transition: background .12s;
}
.mini-cal__table td a:hover { background: #eff6ff; }
.mini-cal__table td.is-today a { background: #dbeafe; color: var(--color-primary-dk); font-weight: 700; }
.mini-cal__table td.is-selected a {
    background: var(--color-primary);
    color: #fff;
    font-weight: 700;
}
.mini-cal__wk-head { opacity: .5; }
.mini-cal__wk { padding-right: 3px; }
.mini-cal__table td.mini-cal__wk a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 3px;
    font-size: 10px;
    color: var(--color-primary);
    text-decoration: none;
    transition: background .12s, color .12s;
}
.mini-cal__table td.mini-cal__wk a:hover { background: #eff6ff; color: var(--color-primary-dk); }
.mini-cal__dot {
    display: block;
    width: 4px; height: 4px;
    border-radius: 50%;
    background: #93c5fd;
    margin: 1px auto 0;
}

/* ===== Day view ===== */
.cal-day {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--color-surface);
}
.cal-day__nav {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    flex-shrink: 0;
}
.cal-day__title { font-size: 16px; font-weight: 700; flex: 1; }
.btn-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--color-border-dark);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 18px;
    text-decoration: none;
    transition: background .15s;
}
.btn-nav:hover { background: #f1f5f9; text-decoration: none; }
.btn-today {
    padding: 5px 12px;
    border: 1px solid var(--color-border-dark);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    background: var(--color-surface);
    color: var(--color-text-muted);
    text-decoration: none;
    transition: background .15s;
}
.btn-today:hover { background: #f1f5f9; text-decoration: none; }

.cal-day__scroll {
    flex: 1;
    overflow: auto;
    scrollbar-gutter: stable;
}

/* ===== Day table ===== */
.day-table {
    border-collapse: separate;
    border-spacing: 0;
    min-width: 100%;
    table-layout: fixed;
}

/* Fixed thead — sticky within the scroll container. */
.cal-day__fixed-head {
    position: sticky;
    top: 0;
    z-index: 10;
}

/* User names header row */
.day-table thead th {
    background: #f8fafc;
    border-bottom: 2px solid var(--color-border-dark);
    border-right: 1px solid var(--color-border);
    padding: 8px 6px;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
}
.day-table__time-col { width: var(--time-col-w); }
.day-table__user-col { min-width: 160px; }
.day-table__user-col--me { color: var(--color-primary); font-weight: 700; }

/* All-day row */
.day-table__slot--allday { height: auto; min-height: var(--slot-height); }
.day-table__slot--allday td {
    border-bottom: 1px solid var(--color-border-dark);
}
.day-table__slot--allday td:not(.day-table__cell--event) {
    background: var(--color-surface);
}

/* Slot rows — border-top on <td> because border-collapse:separate ignores <tr> borders */
.day-table__slot { height: var(--slot-height); }
.day-table__slot td { border-top: 1px solid #f0f4f8; }
.day-table__slot--hour td { border-top: 1px solid var(--color-border); }
/* First body row: suppress top border (all-day bottom border already acts as separator) */
.day-table tbody tr:first-child td { border-top: none; }
/* All-day cells never get a slot top border (higher specificity than slot rules above) */
tr.day-table__slot--allday td { border-top: none; }

.day-table__time {
    width: var(--time-col-w);
    text-align: right;
    padding-right: 8px;
    font-size: 11px;
    color: var(--color-text-muted);
    vertical-align: top;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    position: sticky;
    left: 0;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
}
.day-table__slot--hour .day-table__time { font-weight: 600; color: var(--color-text); }
.time-minor { font-size: 10px; opacity: .6; }

/* Empty slot cell */
.day-table__cell {
    border-right: 1px solid var(--color-border);
    padding: 0;
    vertical-align: top;
    position: relative;
}
.day-table__cell--empty { cursor: pointer; }
.slot-link {
    display: flex;
    align-items: flex-start;
    padding: 2px 4px;
    height: 100%;
    width: 100%;
    color: var(--color-text-muted);
    font-size: 10px;
    text-decoration: none;
    transition: background .1s, color .1s;
}
.slot-link:hover {
    background: #eff6ff;
    color: var(--color-primary);
    text-decoration: none;
}
.slot-time { line-height: 1.4; }
/* Event cell */
.day-table__cell--event {
    padding: 3px 5px;
    vertical-align: top;
    overflow: hidden;
    cursor: pointer;
}
.event--inhouse     { background: var(--color-inhouse);     color: #fff; }
.event--reservation { background: var(--color-reservation); color: #fff; }
.event--normal      { background: var(--color-normal);      color: #fff; }

.event-inner {
    display: flex;
    flex-direction: column;
    gap: 1px;
    text-decoration: none;
    color: inherit;
    height: 100%;
    overflow: hidden;
}
.event-inner:hover { text-decoration: none; opacity: .9; }
.day-table__slot--allday .event-inner,
.day-table__slot--allday .slot-link { height: auto; }
.event-title { font-size: 12px; font-weight: 600; line-height: 1.3; overflow: hidden; overflow-wrap: break-word; }
.event-time  { font-size: 10px; opacity: .85; white-space: nowrap; }
.event-desc-dot {
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: rgba(255,255,255,0.75);
    margin-left: 4px;
    vertical-align: middle;
    flex-shrink: 0;
}

/* All-day pill in allday row */
.event-pill {
    display: block;
    padding: 2px 7px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    white-space: normal;
    word-break: break-word;
    max-width: 100%;
    text-decoration: none;
}
.event-pill + .event-pill { margin-top: 2px; }
.event-pill:hover { opacity: .9; text-decoration: none; }
.event-pill.event--inhouse     { background: var(--color-inhouse); }
.event-pill.event--reservation { background: var(--color-reservation); }
.event-pill.event--normal      { background: var(--color-normal); }

/* ===== Week calendar ===== */
.day-table__day-col { min-width: 110px; }
.day-table thead th.day-col--today { background: #dbeafe; color: var(--color-primary-dk); }
.day-table thead th.day-col--weekend { color: var(--color-text-muted); }
.day-col-date { font-size: 11px; font-weight: 400; }

/* ===== Event form ===== */
.event-form { max-width: 600px; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .cal-sidebar { display: none; }
}
