:root {
  --primary: #0f766e;
  --primary-hover: #0d9488;
  --primary-light: #ccfbf1;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --success: #16a34a;
  --success-bg: #f0fdf4;
}

* { box-sizing: border-box; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", -apple-system, BlinkMacSystemFont, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* Header & Global Navigation */
header.top-nav {
  background: linear-gradient(135deg, #0f172a 0%, #0f766e 100%);
  color: #fff;
  padding: 0.65rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.15);
  position: sticky;
  top: 0;
  z-index: 1000;
}
.brand-box {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: #fff;
}
.brand-logo {
  background: #14b8a6;
  color: #0f172a;
  font-weight: 900;
  font-size: 0.95rem;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  letter-spacing: 0.03em;
}
.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
  white-space: nowrap;
}
.brand-sub {
  font-size: 0.72rem;
  color: #99f6e4;
  display: block;
}

.clinic-switcher {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 255, 255, 0.12);
  padding: 0.25rem 0.6rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
}
.clinic-switcher label {
  font-size: 0.78rem;
  color: #ccfbf1;
  white-space: nowrap;
}
.clinic-switcher select {
  background: #fff;
  color: #0f172a;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  border-radius: 5px;
  border: none;
  cursor: pointer;
}

nav.main-links {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
nav.main-links a {
  color: #e2e8f0;
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
}
nav.main-links a:hover, nav.main-links a.active {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}
nav.main-links a.highlight-nav {
  background: #f59e0b;
  color: #0f172a;
  font-weight: 800;
}
nav.main-links a.highlight-nav:hover {
  background: #fbbf24;
}

header .spacer { flex: 1; }

/* Main Container */
main {
  max-width: 1440px;
  margin: 1.25rem auto;
  padding: 0 1.25rem 3rem;
}

/* Flow Stepper Bar */
.workflow-stepper {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.step-item {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 5px solid var(--primary);
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  transition: transform 0.12s, box-shadow 0.12s;
}
.step-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}
.step-item .step-num {
  font-size: 0.73rem;
  font-weight: 800;
  color: var(--primary);
  text-transform: uppercase;
}
.step-item .step-title {
  font-size: 0.92rem;
  font-weight: 700;
}
.step-item .step-desc {
  font-size: 0.76rem;
  color: var(--muted);
}

/* Cards & KPIs */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.1rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}
.cards .card { margin-bottom: 0; }
.card .big {
  font-size: 1.75rem;
  font-weight: 800;
  margin: 0.25rem 0;
}
.card .label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

/* 2-Pane Route Builder Layout */
.route-workspace {
  display: grid;
  grid-template-columns: 1.25fr 0.95fr;
  gap: 1.1rem;
  align-items: start;
}
@media (max-width: 1024px) {
  .route-workspace { grid-template-columns: 1fr; }
  .workflow-stepper { grid-template-columns: 1fr 1fr; }
}

.sticky-map-pane {
  position: sticky;
  top: 4.5rem;
}

#route-map {
  width: 100%;
  height: 440px;
  border-radius: 8px;
  border: 1px solid var(--border);
  z-index: 1;
}

/* Stop Card & Dr->4m->DH Timeline Visualization */
.stop-card {
  background: #fff;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  margin-bottom: 0.9rem;
  overflow: hidden;
  transition: border-color 0.15s;
}
.stop-card.pinned {
  border-color: #0f766e;
}
.stop-header {
  background: #f8fafc;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.stop-order-badge {
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 0.88rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
}
.stay-formula-badge {
  background: #e0f2fe;
  color: #0369a1;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  border: 1px solid #bae6fd;
}
.pickup-alert-banner {
  background: #fef3c7;
  border-bottom: 1px solid #fde68a;
  color: #92400e;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.travel-connector {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.4rem 0 0.4rem 1.5rem;
  color: #475569;
  font-size: 0.84rem;
  font-weight: 600;
}

.patient-timeline-row {
  padding: 0.65rem 1rem;
  border-bottom: 1px dashed #e2e8f0;
  display: grid;
  grid-template-columns: 190px 1fr auto;
  gap: 0.75rem;
  align-items: center;
}
@media (max-width: 720px) {
  .patient-timeline-row { grid-template-columns: 1fr; }
}
.patient-timeline-row:last-child { border-bottom: none; }

.relay-flow-Track {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.pill-dr {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 700;
}
.pill-gap {
  background: #fef3c7;
  color: #92400e;
  border: 1px dashed #f59e0b;
  padding: 0.15rem 0.45rem;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 700;
}
.pill-dh {
  background: #fce7f3;
  color: #9d174d;
  border: 1px solid #f9a8d4;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 700;
}
.pill-total {
  background: #f1f5f9;
  color: #334155;
  padding: 0.2rem 0.5rem;
  border-radius: 5px;
  font-size: 0.78rem;
  font-weight: 700;
}
.inter-patient-gap {
  background: #f8fafc;
  color: #64748b;
  font-size: 0.76rem;
  text-align: center;
  padding: 0.2rem;
  border-bottom: 1px dashed #e2e8f0;
}

/* Tables & Badges */
table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 0.88rem;
}
th, td {
  border: 1px solid #e2e8f0;
  padding: 0.5rem 0.65rem;
  text-align: left;
}
th {
  background: #f8fafc;
  font-weight: 700;
  color: #334155;
  white-space: nowrap;
}
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.overdue td { background: #fef2f2; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge.waiting { background: #fef3c7; color: #92400e; }
.badge.partial { background: #ffedd5; color: #9a3412; }
.badge.confirming { background: #dbeafe; color: #1e40af; }
.badge.paid { background: #dcfce7; color: #166534; }
.badge.overdue { background: #fee2e2; color: #991b1b; }
.badge.pickup { background: #fef9c3; color: #854d0e; border: 1px solid #fde047; }
.badge.counter { background: #e0e7ff; color: #3730a3; }
.badge.bank { background: #f3e8ff; color: #6b21a8; }

/* Buttons & Forms */
input, select, button, textarea {
  font: inherit;
  padding: 0.4rem 0.6rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
}
button, a.button {
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s;
}
button.primary, a.button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--primary);
  border: 1px solid var(--primary);
  color: #fff;
  text-decoration: none;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  font-size: 0.88rem;
}
button.primary:hover, a.button:hover { background: var(--primary-hover); }
a.button.secondary, button.secondary {
  background: #475569;
  border-color: #475569;
  color: #fff;
}
a.button.accent, button.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.small, a.button.small {
  padding: 0.25rem 0.55rem;
  font-size: 0.78rem;
}

form.filter {
  display: flex;
  gap: 0.75rem;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  background: #fff;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}
form.filter label {
  display: flex;
  flex-direction: column;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  gap: 0.25rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 11rem 1fr;
  gap: 0.7rem 1rem;
  align-items: center;
  max-width: 680px;
}
.form-grid label { color: #334155; font-size: 0.88rem; font-weight: 600; }

.error {
  color: #991b1b;
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-weight: 600;
}
.notice {
  color: #166534;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-weight: 600;
}
.muted { color: var(--muted); font-size: 0.84rem; }
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

/* Print Layout for A4 Route Sheet & Invoice Template */
@media print {
  header.top-nav, .no-print, .workflow-stepper { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  main { max-width: 100%; margin: 0; padding: 0; }
  .card, .stop-card { box-shadow: none; border: 1px solid #000; break-inside: avoid; }
}
