:root { color-scheme: light dark; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; margin: 2rem auto; max-width: 1100px; padding: 0 1rem; line-height: 1.4; }
h1 { margin-bottom: 0.2rem; }
h2 { margin-top: 2rem; border-bottom: 1px solid #8884; padding-bottom: 0.25rem; }
table { border-collapse: collapse; width: 100%; margin-top: 0.5rem; }
th, td { padding: 6px 10px; text-align: left; border-bottom: 1px solid #8884; font-size: 0.92rem; }
th { background: #8881; font-weight: 600; }
tr:hover td { background: #8881; }
a { color: #2966c2; text-decoration: none; }
a:hover { text-decoration: underline; }
.meta { color: #888; font-size: 0.88rem; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.75rem; background: #8882; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 2rem; }
dt { font-weight: 600; color: #666; font-size: 0.85rem; }
dd { margin: 0 0 0.5rem 0; }

.bar { display: flex; height: 10px; border-radius: 4px; overflow: hidden; background: #8881; min-width: 80px; }
.bar > span { display: block; height: 100%; width: var(--w, 0%); }
.bar-cell { min-width: 160px; }
.bar .driving { background: #d24; }
.bar .work    { background: #fa3; }
.bar .available { background: #4af; }
.bar .break   { background: #9c9; }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; }
.swatch.driving { background: #d24; }
.swatch.work { background: #fa3; }
.swatch.available { background: #4af; }
.swatch.break { background: #9c9; }

/* Top navbar + global period filter */
.topnav { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 1rem; padding: 10px 0; margin-bottom: 1rem; border-bottom: 1px solid #8884; background: Canvas; }
.topnav .brand { font-weight: 700; font-size: 1rem; color: inherit; }
.topnav .brand:hover { text-decoration: none; }
.topnav .nav-spacer { flex: 1; }
.topnav .nav-user { font-size: 0.85rem; color: #888; }
.topnav .nav-logout { font-size: 0.85rem; }

/* Login page */
.login-wrap { display: flex; justify-content: center; margin-top: 3rem; }
.login-card { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 320px; background: #8881; border: 1px solid #8883; border-radius: 12px; padding: 24px; }
.login-card h1 { margin: 0 0 0.5rem; }
.login-card label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: #888; margin-top: 8px; }
.login-card input { background: Canvas; border: 1px solid #8884; color: inherit; border-radius: 6px; padding: 8px 10px; font: inherit; }
.login-card button { margin-top: 16px; background: #2966c2; color: #fff; border: none; border-radius: 6px; padding: 9px 12px; cursor: pointer; font: inherit; font-weight: 500; }
.login-card button:hover { background: #1f50a0; }
.login-error { background: #d2422a22; border: 1px solid #d2422a66; color: #d24; border-radius: 6px; padding: 8px 10px; font-size: 0.85rem; margin: 0; }
.period-filter { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; flex-wrap: wrap; }
.period-filter label { color: #888; text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.72rem; }
.period-filter select { background: #8881; border: 1px solid #8884; color: inherit; border-radius: 6px; padding: 3px 8px; font: inherit; cursor: pointer; }
.period-filter select:disabled { opacity: 0.4; cursor: not-allowed; }
.period-filter button { background: #2966c2; color: #fff; border: none; border-radius: 6px; padding: 4px 12px; cursor: pointer; font: inherit; }
.period-filter button:hover { background: #1f50a0; }
.filter-note { font-size: 0.85rem; color: #888; background: #8881; border: 1px solid #8883; border-radius: 8px; padding: 8px 12px; margin: 0 0 1.25rem; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid #8884; margin: 1rem 0 1.5rem; }
.tabs a { padding: 8px 16px; border: 1px solid transparent; border-bottom: none; border-radius: 8px 8px 0 0; font-weight: 500; }
.tabs a.active { background: #8881; border-color: #8884; color: inherit; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi { background: #8881; border: 1px solid #8883; border-radius: 12px; padding: 14px 16px; }
.kpi-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: #888; margin-bottom: 6px; }
.kpi-value { font-size: 1.7rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-value .unit { font-size: 0.95rem; font-weight: 400; color: #888; margin-left: 4px; }
.kpi-sub { font-size: 0.78rem; color: #888; margin-top: 4px; }
.kpi-sub.warn { color: #d24; }
.kpi-sub.good { color: #2a8; }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 1rem; }
.chart-card { background: #8881; border: 1px solid #8883; border-radius: 12px; padding: 14px 16px; }
.chart-card h3 { margin: 0 0 8px 0; font-size: 0.95rem; font-weight: 600; }
.chart-card .chart-sub { font-size: 0.78rem; color: #888; margin-bottom: 10px; }
.chart-card canvas { width: 100% !important; max-height: 280px; }
.chart-card.wide { grid-column: 1 / -1; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 4px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 0.95rem; font-weight: 600; }
.pager { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; }
.pager button { background: #8881; border: 1px solid #8884; color: inherit; border-radius: 6px; padding: 1px 9px; cursor: pointer; font-size: 1rem; line-height: 1.2; }
.pager button:disabled { opacity: 0.3; cursor: not-allowed; }
.pager button:hover:not(:disabled) { background: #8884; }
.pager .label { min-width: 150px; text-align: center; color: #888; font-variant-numeric: tabular-nums; }
.pager select { background: #8881; border: 1px solid #8884; color: inherit; border-radius: 6px; padding: 2px 6px; cursor: pointer; font: inherit; }

/* Activity calendar */
.calendar-wrap { overflow-x: auto; }
.cal-year-grid { display: grid; grid-template-columns: 50px repeat(31, minmax(22px, 1fr)); gap: 2px; min-width: 800px; }
.cal-year-grid .corner, .cal-year-grid .hh, .cal-year-grid .month { font-size: 0.7rem; color: #888; text-align: center; padding: 2px; }
.cal-year-grid .hh { font-weight: 500; }
.cal-year-grid .month { font-weight: 600; align-self: center; text-align: right; padding-right: 8px; }
.cal-day { position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 2px; background: #8881; border: 1px solid #8883; border-radius: 4px; padding: 2px 2px 3px; min-height: 36px; cursor: default; }
.cal-day.weekend { background: rgba(210, 60, 60, 0.10); border-color: rgba(210, 60, 60, 0.25); }
.cal-day.empty { background: transparent; border-color: transparent; }
.cal-day.no-data { opacity: 0.5; }
.cal-day .num { font-size: 0.7rem; text-align: center; line-height: 1; color: #999; }
.cal-day.weekend .num { color: #d24; font-weight: 600; }
.cal-day .marker { width: 7px; height: 7px; border-radius: 50%; margin: 0 auto; background: transparent; border: 1px solid transparent; }
.cal-day .marker.day-driving { background: #d24; }
.cal-day .marker.day-work    { background: #fa3; }
.cal-day .marker.day-standby { background: #4af; }
.cal-day .marker.day-rest    { background: #9c9; }
.cal-day .marker.day-nodata  { border-color: #888; background: transparent; }
.cal-day .strip { display: flex; gap: 0; height: 5px; border-radius: 1px; overflow: hidden; margin-top: auto; background: rgba(128,128,128,0.15); }
.cal-day .strip .seg { flex: 1; }
.cal-day .strip .seg.driving   { background: #d24; }
.cal-day .strip .seg.work      { background: #fa3; }
.cal-day .strip .seg.available { background: #4af; }
.cal-day .strip .seg.break,
.cal-day .strip .seg.none      { background: transparent; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.8rem; color: #888; margin-top: 10px; align-items: center; }
.cal-legend .item { display: flex; align-items: center; gap: 4px; }
.cal-legend .marker { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.cal-legend .marker.day-nodata { border: 1px solid #888; background: transparent; }
.cal-legend .strip-hint { margin-left: auto; }

/* Month view */
.cal-month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; min-width: 600px; }
.cal-month-grid .hh { font-size: 0.75rem; color: #888; font-weight: 600; text-align: center; padding: 4px 0; }
.cal-month-cell { position: relative; min-height: 84px; padding: 4px 6px 6px; background: #8881; border: 1px solid #8883; border-radius: 6px; display: flex; flex-direction: column; gap: 4px; }
.cal-month-cell.weekend { background: rgba(210, 60, 60, 0.10); border-color: rgba(210, 60, 60, 0.25); }
.cal-month-cell.empty { background: transparent; border-color: transparent; }
.cal-month-cell.no-data { opacity: 0.5; }
.cal-month-cell .row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.cal-month-cell .num { font-size: 0.85rem; font-weight: 600; color: #999; }
.cal-month-cell.weekend .num { color: #d24; }
.cal-month-cell .marker { width: 9px; height: 9px; border-radius: 50%; }
.cal-month-cell .marker.day-driving { background: #d24; }
.cal-month-cell .marker.day-work    { background: #fa3; }
.cal-month-cell .marker.day-standby { background: #4af; }
.cal-month-cell .marker.day-rest    { background: #9c9; }
.cal-month-cell .marker.day-nodata  { border: 1px solid #888; background: transparent; }
.cal-month-cell .dist { font-size: 0.75rem; color: #888; font-variant-numeric: tabular-nums; }
.cal-month-cell .strip { display: flex; gap: 0; height: 8px; border-radius: 2px; overflow: hidden; background: rgba(128,128,128,0.15); margin-top: auto; }
.cal-month-cell .strip .seg { flex: 1; }
.cal-month-cell .strip .seg.driving   { background: #d24; }
.cal-month-cell .strip .seg.work      { background: #fa3; }
.cal-month-cell .strip .seg.available { background: #4af; }
.cal-month-cell .strip .seg.break,
.cal-month-cell .strip .seg.none      { background: transparent; }

/* Week view (7 stacked day rows) */
.cal-week-grid { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; align-items: stretch; min-width: 700px; }
.cal-week-grid .day-label { font-size: 0.85rem; line-height: 1.3; padding: 6px 4px; border-radius: 6px; background: #8881; border: 1px solid #8883; }
.cal-week-grid .day-label.weekend { background: rgba(210, 60, 60, 0.10); border-color: rgba(210, 60, 60, 0.25); }
.cal-week-grid .day-label.no-data { opacity: 0.5; }
.cal-week-grid .day-label .wd { font-weight: 600; }
.cal-week-grid .day-label .iso { color: #888; font-size: 0.78rem; }
.cal-week-grid .day-label .stats { color: #888; font-size: 0.78rem; margin-top: 2px; }

/* Day view (full 24-hour timeline) */
.cal-day-stats { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 10px; font-size: 0.9rem; }
.cal-day-stats .stat { display: inline-flex; align-items: center; gap: 6px; color: #888; }
.cal-day-stats .stat b { color: inherit; font-variant-numeric: tabular-nums; }
.cal-day-empty { color: #888; font-style: italic; padding: 12px 0; }

/* Shared day timeline (used by Week and Day views) */
.cal-day-grid { display: grid; grid-template-columns: repeat(24, 1fr); gap: 0; min-width: 600px; }
.cal-day-grid .slot { display: flex; flex-direction: column; align-items: stretch; }
.cal-day-grid .bar { height: 32px; display: flex; border-radius: 2px; overflow: hidden; background: rgba(128,128,128,0.12); border-right: 1px solid rgba(128,128,128,0.18); }
.cal-day-grid .slot:last-child .bar { border-right: none; }
.cal-day-grid .bar > span { display: block; height: 100%; width: var(--w, 0%); }
.cal-day-grid .bar > span.driving   { background: #d24; }
.cal-day-grid .bar > span.work      { background: #fa3; }
.cal-day-grid .bar > span.available { background: #4af; }
.cal-day-grid .bar > span.break     { background: transparent; }
.cal-day-grid .hour-label { font-size: 0.65rem; color: #888; text-align: center; padding-top: 2px; }
.cal-day-grid.big .bar { height: 56px; }
.cal-day-grid.compact .bar { height: 24px; }

.legend-row { margin-top: 0.5rem; }

/* Weekday × hour heatmap */
.heatmap { display: grid; grid-template-columns: 36px repeat(24, 1fr); gap: 2px; align-items: center; }
.heatmap .corner, .heatmap .hh, .heatmap .wd { font-size: 0.7rem; color: #888; text-align: center; }
.heatmap .wd { text-align: right; padding-right: 6px; }
.heatmap .cell {
  aspect-ratio: 1 / 1;
  border-radius: 3px;
  background: rgba(210, 60, 60, var(--i, 0));
  outline: 1px solid rgba(128,128,128,0.15);
  outline-offset: -1px;
  min-height: 14px;
}
.heatmap-scale { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; color: #888; margin-top: 8px; }
.heatmap-scale .gradient { height: 10px; width: 160px; border-radius: 4px; background: linear-gradient(to right, rgba(210,60,60,0.05), rgba(210,60,60,1)); }

/* Country breakdown */
/* position+z-index creates a new stacking context so Leaflet's internal panes
   and controls (z-index up to 1000) stay contained below the sticky topnav. */
.country-map { position: relative; z-index: 0; height: 360px; border-radius: 8px; overflow: hidden; background: #8881; }
.country-table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; font-size: 0.9rem; }
.country-table th { background: #8881; font-weight: 600; padding: 6px 10px; border-bottom: 1px solid #8884; }
.country-table td { padding: 6px 10px; border-bottom: 1px solid #8882; }
.country-table tr:hover td { background: #8881; }
.country-table .flag { font-size: 1.1rem; }
.country-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.country-table tfoot td { font-weight: 600; border-top: 2px solid #8884; background: #8881; }
.rate-input { width: 80px; background: #8881; border: 1px solid #8884; border-radius: 5px; color: inherit; font: inherit; font-size: 0.88rem; padding: 3px 6px; text-align: right; }
.rate-input:focus { outline: 2px solid #2966c2; outline-offset: 1px; border-color: transparent; }
.earnings-cell { font-variant-numeric: tabular-nums; }
.events-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.events-table th { background: #8881; font-weight: 600; padding: 5px 10px; border-bottom: 1px solid #8884; }
.events-table td { padding: 5px 10px; border-bottom: 1px solid #8882; }
.events-table tr:hover td { background: #8881; }
.events-table .etype-begin { color: #2a8; font-weight: 600; }
.events-table .etype-end { color: #888; }
.events-table .etype-begin\/end { color: #2966c2; font-weight: 600; }
.events-table .etype-ferry { color: #fa3; font-weight: 600; }
.country-nodata { color: #888; font-style: italic; padding: 12px 0; }
