@import url('https://fonts.googleapis.com/css2?family=Audiowide&display=swap');

* { box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background: #f6f7f9;
    color: #1f2328;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background: #fff;
    border-bottom: 1px solid #e3e6ea;
}

header h1 { font-size: 1.1rem; margin: 0; display: flex; align-items: baseline; gap: 0.75rem; }
header h1 .brand {
    font-family: 'Audiowide', system-ui, sans-serif;
    font-size: 1.5rem;
    font-style: italic;
    letter-spacing: 0.04em;
    color: #c8102e;
}
header h1 .subtitle {
    font-weight: 400;
    color: #666;
    font-size: 0.95rem;
}

main { padding: 2rem; max-width: 960px; margin: 0 auto; }
main.wide { max-width: 1400px; }

main.login {
    max-width: 360px;
    margin: 4rem auto;
    background: #fff;
    padding: 2rem;
    border: 1px solid #e3e6ea;
    border-radius: 8px;
}
main.login > h1 { font-size: 1.1rem; margin: 0 0 1rem; }

label {
    display: block;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

input {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    padding: 0.5rem 0.6rem;
    border: 1px solid #cdd2d8;
    border-radius: 4px;
    font: inherit;
}

button {
    padding: 0.55rem 1rem;
    background: #1f6feb;
    color: #fff;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
}

button:hover { background: #1858c4; }

pre {
    background: #fff;
    border: 1px solid #e3e6ea;
    padding: 1rem;
    border-radius: 4px;
    overflow: auto;
}

.error { color: #b3261e; margin-top: 0.5rem; }

.message { margin: 0.75rem 0; padding: 0.75rem; border-radius: 4px; font-size: 0.9rem; }
.message:empty { display: none; }
.message.success { background: #e6f4ea; color: #1e4620; border: 1px solid #b7dcc2; }
.message.error   { background: #fdecea; color: #5f2120; border: 1px solid #f5c2c0; }

.info-box    { background: #fff3cd; color: #856404; border: 1px solid #ffc107; border-radius: 4px; padding: 0.75rem; margin-bottom: 1rem; }
.pending-box { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; border-radius: 4px; padding: 0.75rem; margin-bottom: 1rem; }
.muted       { color: #666; font-size: 0.85rem; }
.auth-links  { margin-top: 1rem; font-size: 0.9rem; }
.auth-links a { color: #1f6feb; text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }

.spinner {
    display: inline-block; width: 16px; height: 16px;
    border: 2px solid #ccc; border-top-color: #1f6feb; border-radius: 50%;
    animation: spin 0.8s linear infinite; vertical-align: middle; margin-right: 0.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

.phase { display: none; }
.phase.active { display: block; }

nav { display: flex; align-items: center; gap: 1rem; }
nav a { color: #1f6feb; text-decoration: none; }
nav a:hover { text-decoration: underline; }

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #e3e6ea;
    border-radius: 4px;
}

th, td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #eef0f3;
    vertical-align: top;
    font-size: 0.9rem;
}

th { background: #f6f7f9; font-weight: 600; }

#messages td:nth-child(4) { max-width: 32rem; word-break: break-word; white-space: pre-wrap; }

.thumb {
    max-width: 160px;
    max-height: 160px;
    border-radius: 4px;
    object-fit: cover;
}

.section { margin-bottom: 2.5rem; }
.section h2 { font-size: 1rem; margin: 0 0 0.75rem; }

.admin-sub { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; }
.admin-form {
    display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end;
    margin-bottom: 0.75rem; font-size: 0.9rem;
}
.admin-form label { display: flex; flex-direction: column; gap: 0.2rem; }
.admin-form input, .admin-form select { padding: 0.3rem 0.5rem; font-size: 0.9rem; }
.reset-pwd { padding: 0.25rem 0.4rem; font-size: 0.85rem; width: 12rem; }
.sec-check { display: inline-flex; align-items: center; gap: 0.2rem; margin-right: 0.6rem; font-size: 0.85rem; }
.sec-check input { width: auto; display: inline-block; margin: 0; }
.sec-status { margin-left: 0.4rem; font-size: 0.8rem; }

.activity-wrap { overflow-x: auto; }
#activity-table { font-size: 0.85rem; min-width: 800px; }
#activity-table .act-ua {
    max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.act-login         { color: #1e4620; }
.act-login_failed  { color: #b3261e; font-weight: 600; }
.act-logout        { color: #444; }

.schedule-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}
.schedule-controls input { width: auto; display: inline-block; margin: 0; }
.schedule-controls #schedule-year { width: 6em; }
.schedule-controls #schedule-week { width: 5em; }

.schedule-wrap { overflow-x: auto; }

#schedule { font-size: 0.85rem; min-width: 1200px; }
#schedule .no-slot { color: #999; }
#schedule th { text-align: center; }
#schedule .date-sub { font-weight: 400; color: #666; font-size: 0.78rem; }
#schedule .holiday-tag { font-weight: 400; color: #8a5a00; font-size: 0.72rem; }
#schedule th.holiday { background: #fff8e1; }

/* Visually group rows by Rit: the Route cell spans 3 rows (centered, bold,
   light tint), and the start of each group gets a thicker top border. The
   first group's top border falls outside the tbody so no special-case needed. */
#schedule td.route {
    text-align: center;
    vertical-align: middle;
    font-weight: 600;
    background: #f6f7f9;
    border-right: 1px solid #e3e6ea;
}
#schedule tbody tr.rit-start:not(:first-child) > td {
    border-top: 2px solid #cdd2d8;
}
#schedule th, #schedule td { white-space: nowrap; }
#schedule td.day { white-space: normal; }
#schedule .slot-entry { display: block; }
#schedule .slot-entry a { color: #1f6feb; text-decoration: none; }
#schedule .slot-entry a:hover { text-decoration: underline; }
/* Color rules target both the entry text (manual entries — no <a>) and the
   link inside (auto pins — wrapped in <a href> to the Maps URL). */
#schedule .slot-entry.late,
#schedule .slot-entry.late a       { color: #b3261e; font-weight: 600; }
#schedule .slot-entry.in-window,
#schedule .slot-entry.in-window a  { color: #1e4620; }
#schedule .slot-entry.manual { font-style: italic; }
#schedule .slot-entry.manual::before { content: "✎ "; opacity: 0.6; }

/* Admin-only inline controls. The buttons are hidden by default; the script
   reveals them by toggling the .can-edit class on the schedule table once the
   /api/me response confirms an admin role. */
#schedule .cell-btn {
    display: none;
    background: none;
    border: 1px solid transparent;
    color: #888;
    font: inherit;
    cursor: pointer;
    padding: 0 0.25rem;
    margin-left: 0.25rem;
    border-radius: 3px;
    font-size: 0.78rem;
    line-height: 1.1;
}
#schedule .cell-btn:hover { border-color: #cdd2d8; color: #333; }
#schedule.can-edit .cell-btn { display: inline-block; }
#schedule .cell-add {
    display: none;
    color: #888;
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
    background: none;
    border: 1px dashed #d0d4d9;
    border-radius: 3px;
    padding: 0.1rem 0.4rem;
}
#schedule.can-edit .cell-add { display: inline-block; }
#schedule .cell-add:hover { color: #1f6feb; border-color: #1f6feb; }
#schedule .cell-edit-form { display: inline-flex; gap: 0.25rem; align-items: center; }
#schedule .cell-edit-form input[type="time"] {
    width: 6em; padding: 0.05rem 0.2rem; font-size: 0.8rem; margin: 0;
}
#schedule .car-select {
    font-size: 0.78rem; color: #555; display: inline-flex; gap: 0.2rem; align-items: center;
}
#schedule .car-select input[type="checkbox"] { margin: 0; }

/* Car badge: visible inline next to a pin/manual entry when it's not the
   main car. car-2 stands out in orange to be scannable across the grid. */
#schedule .car-badge {
    display: inline-block;
    margin-left: 0.3rem;
    padding: 0 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.3;
    border-radius: 9px;
    background: #fff;
    border: 1px solid currentColor;
}
#schedule .car-badge.car-2 { color: #c2410c; background: #fff7ed; }
/* The "2?" affordance on car-1 pins is admin-only; hidden by default and
   shown via .can-edit. Buttons inherit cell-btn baseline styling. */
#schedule .car-badge.car-set { display: none; color: #888; font-weight: 400; }
#schedule.can-edit .car-badge.car-set { display: inline-block; }
button.car-badge { cursor: pointer; font-family: inherit; }
button.car-badge:hover { filter: brightness(0.92); }

.chart-legend {
    display: flex;
    gap: 1.25rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: #444;
}
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend-item::before {
    content: ""; width: 12px; height: 12px; border-radius: 2px;
}
.legend-early::before  { background: #1f6feb; }
.legend-ontime::before { background: #1e4620; }
.legend-late::before   { background: #b3261e; }

#weekly-stats-chart svg {
    width: 100%; height: auto;
    background: #fff;
    border: 1px solid #e3e6ea;
    border-radius: 4px;
    padding: 0.5rem;
}
#weekly-stats-svg .grid    { stroke: #eef0f3; stroke-width: 1; }
#weekly-stats-svg .axis    { stroke: #cdd2d8; stroke-width: 1; }
#weekly-stats-svg .y-label { font-size: 11px; fill: #666; text-anchor: end; }
#weekly-stats-svg .x-label { font-size: 11px; fill: #666; text-anchor: start; }
#weekly-stats-svg polyline { fill: none; stroke-width: 2; }
#weekly-stats-svg .series-early  { stroke: #1f6feb; }
#weekly-stats-svg .series-ontime { stroke: #1e4620; }
#weekly-stats-svg .series-late   { stroke: #b3261e; }
#weekly-stats-svg .dot-early  { fill: #1f6feb; }
#weekly-stats-svg .dot-ontime { fill: #1e4620; }
#weekly-stats-svg .dot-late   { fill: #b3261e; }

/* Backups section on App.html. One card per /backups subfolder, with an
   expandable log tail underneath. */
.small-btn {
    padding: 0.2rem 0.55rem; font-size: 0.78rem;
    background: #eef0f3; color: #1f2328;
    border: 1px solid #cdd2d8; border-radius: 4px;
    margin-left: 0.5rem; vertical-align: middle;
}
.small-btn:hover { background: #d9e6f7; }
.small-btn:disabled { opacity: 0.6; cursor: default; }

#backups-section h2 { display: flex; align-items: center; }
.backup-card {
    background: #fff;
    border: 1px solid #e3e6ea;
    border-radius: 4px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}
.backup-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.backup-meta {
    display: grid;
    grid-template-columns: max-content 1fr;
    column-gap: 1rem; row-gap: 0.25rem;
    margin: 0.5rem 0 0;
    font-size: 0.88rem;
}
.backup-meta dt { color: #666; }
.backup-meta dd { margin: 0; }
.backup-log {
    margin-top: 0.6rem; max-height: 24rem; overflow: auto;
    font-size: 0.78rem; line-height: 1.35;
    background: #1f2328; color: #e6edf3;
    border-radius: 4px; padding: 0.75rem 1rem;
}
