:root {
  --blue: #3B82F6;
  --blue-d: #2563EB;
  --green: #10B981;
  --amber: #F59E0B;
  --red: #EF4444;
  --slate-50: #F8FAFC;
  --slate-100: #F1F5F9;
  --slate-200: #E2E8F0;
  --slate-400: #94A3B8;
  --slate-500: #64748B;
  --slate-700: #334155;
  --slate-900: #0F172A;
  --radius: 14px;
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: var(--slate-50);
  color: var(--slate-900);
  -webkit-font-smoothing: antialiased;
}

.view { display: none; min-height: 100vh; }
.view.active { display: block; }
.hidden { display: none !important; }

/* ───────── Top bar ───────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  background: #fff;
  border-bottom: 1px solid var(--slate-200);
}
.topbar-title { font-weight: 700; font-size: 17px; }
.icon-btn {
  width: 40px; height: 40px; border: none; border-radius: 10px;
  background: var(--slate-100); font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--slate-200); }

.container { max-width: 560px; margin: 0 auto; padding: 16px; padding-bottom: 120px; }

/* ───────── Login ───────── */
.login-wrap {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; gap: 28px;
  background: linear-gradient(160deg, #3B82F6 0%, #2563EB 55%, #1E40AF 100%);
}
.brand { text-align: center; color: #fff; }
.brand-logo {
  width: 76px; height: 76px; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.18); border-radius: 22px; font-size: 38px;
}
.brand h1 { margin: 0 0 6px; font-size: 22px; font-weight: 800; }
.brand p { margin: 0; opacity: 0.85; font-size: 14px; }

.card {
  background: #fff; border: 1px solid var(--slate-200);
  border-radius: 16px; box-shadow: var(--shadow);
}
.login-card { width: 100%; max-width: 360px; padding: 22px; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--slate-500); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 13px 14px; font-size: 16px;
  border: 1px solid var(--slate-200); border-radius: 12px; background: var(--slate-50);
  outline: none; transition: border-color .15s, background .15s;
}
.field input:focus { border-color: var(--blue); background: #fff; }

/* ───────── Buttons ───────── */
.btn {
  width: 100%; padding: 14px; font-size: 16px; font-weight: 700;
  border: none; border-radius: 12px; cursor: pointer; color: #fff;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--blue); }
.btn-success { background: var(--green); }
.btn .spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.4); border-top-color:#fff; border-radius:50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.error-text { color: #fff; background: rgba(239,68,68,.9); padding: 0; margin: 10px 0 0; font-size: 13px; border-radius: 8px; text-align:center; min-height: 0; }
.error-text:not(:empty) { padding: 8px 10px; }

.link-btn { background: none; border: none; color: var(--blue); font-size: 13px; font-weight: 600; cursor: pointer; padding: 4px; }

/* ───────── Search ───────── */
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--slate-200);
  border-radius: 12px; padding: 0 12px; margin-bottom: 14px;
}
.search-box .search-icon { opacity: .5; }
.search-box input { flex: 1; border: none; outline: none; padding: 13px 0; font-size: 15px; background: transparent; }

/* ── Tab bar (By Person / By Day) ── */
.tabbar {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 14px;
  background: var(--slate-100); border-radius: 12px;
}
.tab-btn {
  flex: 1; padding: 10px; border: none; border-radius: 9px; cursor: pointer;
  background: transparent; color: var(--slate-500); font-size: 14px; font-weight: 700;
  transition: background .15s, color .15s;
}
.tab-btn.active { background: var(--blue); color: #fff; box-shadow: 0 2px 6px rgba(59,130,246,.35); }

/* ── Weekday selector ── */
.weekday-row { display: flex; gap: 6px; margin-bottom: 12px; }
.wd-chip {
  flex: 1; padding: 8px 0; border: 1px solid var(--slate-200); border-radius: 10px;
  background: #fff; cursor: pointer; text-align: center; transition: all .15s;
}
.wd-chip .wd-name { font-size: 12px; font-weight: 700; color: var(--slate-700); }
.wd-chip .wd-count { font-size: 10px; color: var(--slate-400); }
.wd-chip.active { background: var(--blue); border-color: var(--blue); }
.wd-chip.active .wd-name, .wd-chip.active .wd-count { color: #fff; }
.wd-chip.weekend .wd-name { color: var(--red); }
.wd-chip.active.weekend { background: var(--red); border-color: var(--red); }
.wd-chip.active.weekend .wd-name { color: #fff; }

.day-stats { font-size: 12px; color: var(--slate-500); margin: 0 4px 12px; font-weight: 600; }

/* time-group header in day view */
.time-group { display: flex; align-items: center; gap: 8px; margin: 14px 2px 8px; }
.time-group .tg-pill {
  background: rgba(59,130,246,.12); color: var(--blue); font-weight: 800;
  font-size: 13px; font-family: monospace; padding: 3px 10px; border-radius: 20px;
}
.time-group .tg-line { flex: 1; height: 1px; background: var(--slate-200); }

.day-row {
  display: flex; align-items: center; gap: 12px;
  background: #fff; border: 1px solid var(--slate-200); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 8px; cursor: pointer; box-shadow: var(--shadow);
}
.day-row:active { transform: scale(.99); }
.day-time {
  font-family: monospace; font-weight: 800; font-size: 14px;
  padding: 6px 10px; border-radius: 8px; background: rgba(59,130,246,.1); color: var(--blue);
  flex-shrink: 0; min-width: 58px; text-align: center;
}
.day-time.empty { background: rgba(100,116,139,.12); color: var(--slate-400); }
.day-time.self { background: rgba(245,158,11,.14); color: var(--amber); }
.day-info { flex: 1; min-width: 0; }
.day-pname { font-weight: 700; font-size: 14px; }
.day-psub { font-size: 11px; color: var(--slate-500); margin-top: 2px; }
.day-edit-ic { color: var(--slate-400); font-size: 16px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 200;
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
.modal-card {
  background: #fff; width: 100%; max-width: 520px; border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.modal-title { font-size: 18px; font-weight: 800; }
.modal-sub { font-size: 12px; color: var(--slate-500); margin-top: 2px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.btn-ghost {
  padding: 14px 18px; border: 1px solid var(--slate-200); border-radius: 12px;
  background: transparent; color: var(--slate-500); font-weight: 700; font-size: 15px; cursor: pointer;
}

/* ── Company / factory filter ── */
.company-filter { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
.company-filter:empty { display: none; }
.cf-chip {
  flex-shrink: 0; padding: 7px 14px; border: 1px solid var(--slate-200);
  border-radius: 20px; background: #fff; font-size: 13px; font-weight: 700;
  color: var(--slate-500); cursor: pointer; white-space: nowrap;
}
.cf-chip.active { background: var(--blue); border-color: var(--blue); color: #fff; box-shadow: 0 2px 6px rgba(59,130,246,.3); }

.people-list { display: flex; flex-direction: column; gap: 8px; }
.person-row {
  display: flex; align-items: center; gap: 12px;
  background: #fff; border: 1px solid var(--slate-200);
  border-radius: var(--radius); padding: 12px 14px; cursor: pointer;
  box-shadow: var(--shadow); transition: border-color .12s, transform .08s;
}
.person-row:active { transform: scale(0.99); border-color: var(--blue); }
.person-avatar {
  width: 42px; height: 42px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px; color: #fff;
}
.person-info { flex: 1; min-width: 0; }
.person-name { font-weight: 700; font-size: 15px; }
.person-sub { font-size: 12px; color: var(--slate-500); margin-top: 2px; }
.person-chevron { color: var(--slate-400); font-size: 20px; }
.person-meta {
  font-size: 11px; font-weight: 700; color: var(--blue);
  background: rgba(59,130,246,.12); padding: 3px 8px; border-radius: 20px;
}
.tag-self { color: var(--amber); background: rgba(245,158,11,.14); margin-left: 4px; }

.loading, .empty { text-align: center; color: var(--slate-400); padding: 40px 0; font-size: 14px; }

/* ───────── Editor ───────── */
.person-head { padding: 14px 16px; margin-bottom: 18px; display: flex; align-items: center; gap: 12px; }
.person-head .ph-avatar { width: 46px; height: 46px; border-radius: 12px; display:flex; align-items:center; justify-content:center; color:#fff; font-weight:800; font-size:18px; flex-shrink:0; }
.person-head .ph-name { font-weight: 800; font-size: 17px; }
.person-head .ph-sub { font-size: 12px; color: var(--slate-500); margin-top: 2px; }

.section-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; font-weight: 700; color: var(--slate-500);
  text-transform: uppercase; letter-spacing: .03em; margin: 0 4px 10px;
}

.day-card {
  background: #fff; border: 1px solid var(--slate-200);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.day-card .day-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; margin-bottom: 12px; }
.day-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--blue); }
.day-dot.weekend { background: var(--red); }

/* ── Day toggle (enable/disable a working day) ── */
.day-toggle { display: flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.day-check {
  width: 22px; height: 22px; flex-shrink: 0;
  border: 2px solid var(--slate-400); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s;
}
.day-check svg { opacity: 0; transition: opacity .15s; }
.day-name { font-weight: 700; font-size: 15px; }
.day-state { margin-left: auto; font-size: 12px; color: var(--slate-400); }

/* enabled state */
.day-card.enabled .day-check { background: var(--blue); border-color: var(--blue); }
.day-card.enabled.weekend-card .day-check { background: var(--red); border-color: var(--red); }
.day-card.enabled .day-check svg { opacity: 1; }
.day-card.enabled .day-state { display: none; }

/* body shown only when the day is enabled */
.day-body { display: none; margin-top: 12px; }
.day-card.enabled .day-body { display: block; }

/* dim disabled cards a touch */
.day-card:not(.enabled) { opacity: .7; }
.day-card:not(.enabled) .day-name, .day-card:not(.enabled) .day-dot { opacity: .6; }

.loc-field { margin-bottom: 10px; }
.loc-field span, .time-field span { display:block; font-size: 11px; font-weight: 600; color: var(--slate-500); margin-bottom: 5px; }

/* Pickup-place dropdown + time inputs — force explicit, high-contrast colors
   so native controls never render white-on-white. */
.loc-field select,
.time-field input[type="time"] {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  background: #ffffff;
  color: #0F172A;
  -webkit-text-fill-color: #0F172A;   /* iOS/Safari fix */
  color-scheme: light;                 /* keep native time text dark */
  outline: none;
}
.time-field input[type="time"] { font-variant-numeric: tabular-nums; }

/* custom chevron for the select */
.loc-field select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.time-row { display: flex; gap: 10px; }
.time-field { flex: 1; }

.loc-field select:focus { border-color: var(--blue); }
.time-field.pickup input:focus { border-color: var(--blue); }
.time-field.drop input:focus { border-color: var(--amber); }

.btn-save { margin-top: 18px; position: sticky; bottom: 16px; box-shadow: 0 6px 18px rgba(16,185,129,.35); }

/* ── Special date overrides ── */
.ov-hint { font-size: 12px; color: var(--slate-500); margin: 0 4px 12px; line-height: 1.45; }
.ov-add { padding: 14px; margin-bottom: 12px; }
.ov-date-input {
  width: 100%; padding: 12px; font-size: 16px;
  border: 1px solid var(--slate-200); border-radius: 10px;
  background: #fff; color: #0F172A; -webkit-text-fill-color: #0F172A;
  color-scheme: light; outline: none;
}
.ov-date-input:focus { border-color: var(--amber); }
.ov-dayinfo { font-size: 13px; color: var(--slate-500); }
.ov-dayinfo b { color: var(--slate-900); }
.ov-warn {
  font-size: 13px; color: #92400E; background: #FEF3C7;
  border: 1px solid #FCD34D; border-radius: 10px; padding: 10px 12px; line-height: 1.45;
}
.ov-item {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border: 1px solid var(--slate-200); border-left: 4px solid var(--amber);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.ov-item-date { font-weight: 700; font-size: 14px; }
.ov-item-day { font-size: 11px; font-weight: 600; color: var(--amber); margin-left: 4px; }
.ov-item-time { font-size: 13px; color: var(--slate-500); margin-top: 2px; font-family: monospace; }
.ov-del {
  width: 34px; height: 34px; border: none; border-radius: 9px; cursor: pointer;
  background: rgba(239,68,68,.1); color: #EF4444; font-size: 15px; flex-shrink: 0;
}

/* ───────── Toast ───────── */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: var(--slate-900); color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 100; max-width: 90vw; text-align:center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: #059669; }
.toast.err { background: #DC2626; }

/* ───────── Dark mode ───────── */
@media (prefers-color-scheme: dark) {
  html, body { background: var(--slate-900); color: #F1F5F9; }
  .topbar { background: #1E293B; border-color: var(--slate-700); }
  .icon-btn { background: var(--slate-700); }
  .card, .person-row, .day-card, .search-box { background: #1E293B; border-color: var(--slate-700); }
  .field input { background: #0F172A; border-color: var(--slate-700); color:#F1F5F9; }
  /* dropdown + time inputs: dark field, light text, dark native picker */
  .loc-field select,
  .time-field input[type="time"],
  .ov-date-input {
    background: #0F172A;
    border-color: var(--slate-700);
    color: #F1F5F9;
    -webkit-text-fill-color: #F1F5F9;
    color-scheme: dark;
  }
  .person-sub, .person-head .ph-sub, .day-card .day-head { color: #CBD5E1; }
  .ov-item { background: #1E293B; border-color: var(--slate-700); border-left-color: var(--amber); }
  .ov-dayinfo b { color: #F1F5F9; }
  .tabbar { background: #1E293B; }
  .cf-chip { background: #1E293B; border-color: var(--slate-700); color: #CBD5E1; }
  .wd-chip, .day-row { background: #1E293B; border-color: var(--slate-700); }
  .wd-chip .wd-name { color: #CBD5E1; }
  .time-group .tg-line { background: var(--slate-700); }
  .modal-card { background: #1E293B; }
  .btn-ghost { border-color: var(--slate-700); color: #CBD5E1; }
  #qm-loc, #qm-pick, #qm-drop { background: #0F172A; border-color: var(--slate-700); color: #F1F5F9; -webkit-text-fill-color: #F1F5F9; color-scheme: dark; }
  /* admin dark */
  .ed-card, .veh-row, .tool-card { background: #1E293B; border-color: var(--slate-700); }
  .ed-input, #vm-name, #vm-seats, #pm-input { background: #0F172A; border-color: var(--slate-700); color: #F1F5F9; -webkit-text-fill-color: #F1F5F9; color-scheme: dark; }
  .ed-card-h, .veh-name, .tool-t, .self-t, .fs-big { color: #F1F5F9; }
  .self-toggle { background: #0F172A; }
  .nav-arrow { background: #1E293B; border-color: var(--slate-700); color: #CBD5E1; }
  .wd-chip .wd-date, .day-date-head, .day-nav-label { color: #F1F5F9; }
  .wd-chip.active .wd-date { color: #fff; }
}

/* ════════ ADMIN-specific ════════ */
.admin-login .login-wrap, .admin-login { background: linear-gradient(160deg,#1E293B 0%,#0F172A 60%,#020617 100%); }

.row-between { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.row-inline { display: flex; align-items: center; gap: 8px; }
.btn-add {
  width: 46px; height: 46px; flex-shrink: 0; border: none; border-radius: 12px;
  background: var(--green); color: #fff; font-size: 24px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; line-height: 1;
  box-shadow: 0 3px 10px rgba(16,185,129,.4);
}
.btn-add.sm { width: 46px; height: 48px; background: var(--blue); box-shadow: none; font-size: 22px; }
.danger-ic { color: #EF4444; }
.tabbar-4 .tab-btn { font-size: 12px; padding: 9px 4px; }

/* editor cards */
.ed-card {
  background: #fff; border: 1px solid var(--slate-200); border-radius: 16px;
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.ed-card-h { font-weight: 800; font-size: 14px; margin-bottom: 12px; color: var(--slate-900); }
.ed-input {
  width: 100%; padding: 12px; font-size: 16px; border: 1px solid var(--slate-200);
  border-radius: 10px; background: #fff; color: #0F172A; -webkit-text-fill-color: #0F172A;
  color-scheme: light; outline: none;
}
.ed-input:focus { border-color: var(--blue); }
.row-inline .ed-input { flex: 1; }

/* self toggle */
.self-toggle {
  display: flex; align-items: center; gap: 12px; margin-top: 14px; cursor: pointer;
  background: var(--slate-50); border-radius: 12px; padding: 12px 14px;
}
.self-toggle > div { flex: 1; }
.self-t { font-weight: 700; font-size: 14px; }
.self-s { font-size: 11px; color: var(--slate-500); margin-top: 2px; }
.self-toggle input { display: none; }
.self-toggle .switch {
  width: 46px; height: 27px; border-radius: 14px; background: var(--slate-300, #cbd5e1);
  position: relative; flex-shrink: 0; transition: background .2s;
}
.self-toggle .switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px;
  border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.self-toggle input:checked + .switch { background: var(--amber); }
.self-toggle input:checked + .switch::after { transform: translateX(19px); }

/* day recommendation */
.day-rec { margin: 0 2px 12px; }
.rec {
  font-size: 12px; font-weight: 700; color: #8B5CF6; background: rgba(139,92,246,.1);
  border: 1px solid rgba(139,92,246,.3); border-radius: 10px; padding: 9px 12px;
}
.rec.warn { color: var(--red); background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.3); }

/* fleet */
.fleet-summary { flex: 1; }
.fs-big { font-size: 17px; font-weight: 800; }
.fs-sub { font-size: 12px; color: var(--slate-500); }
.veh-row {
  display: flex; align-items: center; gap: 12px; background: #fff;
  border: 1px solid var(--slate-200); border-radius: 14px; padding: 12px 14px;
  margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer;
}
.veh-seat {
  width: 52px; height: 52px; border-radius: 12px; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px;
}
.veh-seat span { font-size: 9px; font-weight: 600; }
.veh-info { flex: 1; }
.veh-name { font-weight: 800; font-size: 17px; }
.veh-sub { font-size: 12px; color: var(--slate-500); margin-top: 2px; }
.veh-del { width: 38px; height: 38px; border: none; border-radius: 10px; background: rgba(239,68,68,.1); cursor: pointer; font-size: 15px; flex-shrink: 0; }

/* tools */
.tool-card {
  display: flex; align-items: center; gap: 14px; background: #fff;
  border: 1px solid var(--slate-200); border-radius: 14px; padding: 16px;
  margin-bottom: 10px; box-shadow: var(--shadow); cursor: pointer;
}
.tool-card.danger { border-color: rgba(239,68,68,.3); }
.tool-ic { width: 44px; height: 44px; border-radius: 11px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.tool-info { flex: 1; }
.tool-t { font-weight: 700; font-size: 15px; }
.tool-s { font-size: 12px; color: var(--slate-500); margin-top: 2px; }

/* date-aware day view */
.day-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.day-nav-label { flex: 1; text-align: center; font-weight: 700; font-size: 14px; }
.nav-arrow {
  min-width: 40px; height: 36px; padding: 0 10px; border: 1px solid var(--slate-200);
  border-radius: 10px; background: #fff; color: var(--slate-700); font-size: 16px; font-weight: 700; cursor: pointer;
}
#day-today { font-size: 13px; }
.wd-chip .wd-date { font-size: 14px; font-weight: 800; color: var(--slate-900); margin: 1px 0; }
.wd-chip.active .wd-date { color: #fff; }
.wd-chip.today { border-color: var(--blue); border-width: 2px; }
.wd-chip.today.active { border-color: #fff; }
.day-date-head { font-weight: 800; font-size: 15px; margin: 4px 2px 10px; }
.day-time.ov { background: rgba(245,158,11,.16); color: #B45309; }
