*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --red: #a9151a;
  --dark: #1a1a1a;
  --bg: #f0f0f0;
  --card: #fff;
  --text: #1a1a1a;
  --muted: #888;
  --border: #ddd;
  --header-h: 56px;
  --marquee-h: 28px;
  --top-h: calc(var(--header-h) + var(--marquee-h));
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}


/* ── Header ─────────────────────────────────── */

.dt-header {
  background: var(--dark);
  color: #fff;
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.dt-logo-img {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  animation: dt-logo-wobble 1s linear infinite;
}

@keyframes dt-logo-wobble {
  0%   { transform: rotate(0deg) translateY(0); }
  50%  { transform: rotate(4deg) translateY(2px); }
  100% { transform: rotate(0deg) translateY(0); }
}

.dt-logo-text {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.dt-subtitle {
  font-size: 13px;
  color: #fff;
  opacity: 0.9;
  white-space: nowrap;
}

.dt-header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.dt-update-time {
  font-size: 12px;
  color: #fff;
  opacity: 0.9;
  white-space: nowrap;
}

.dt-header-link {
  font-size: 13px;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity 0.15s;
}

.dt-header-link:hover {
  opacity: 0.75;
}


/* ── Marquee bar ─────────────────────────────── */

.dt-marquee-bar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  height: var(--marquee-h);
  background: var(--red);
  overflow: hidden;
  z-index: 99;
  display: flex;
  align-items: center;
}

.dt-marquee-bar p {
  display: inline-block;
  white-space: nowrap;
  color: #fff;
  font-size: 13px;
  padding-left: 100vw;
  letter-spacing: 0.3px;
}

@keyframes dt-marquee-scroll {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-100%); }
}

body.dt-no-marquee .dt-marquee-bar  { display: none; }
body.dt-no-marquee .dt-main         { margin-top: var(--header-h); height: calc(100vh - var(--header-h)); }



/* ── Main layout ─────────────────────────────── */

.dt-main {
  display: flex;
  margin-top: var(--top-h);
  height: calc(100vh - var(--top-h));
}


/* ── Left: shops panel ───────────────────────── */

.dt-shops-panel {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  min-width: 0;
}

.dt-initial-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  gap: 16px;
  opacity: 0.4;
}

.dt-loading-sushi {
  width: 48px;
  height: 48px;
  animation: dt-spin 1.8s linear infinite;
}

@keyframes dt-spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.dt-loading-text {
  font-size: 14px;
  color: var(--muted);
}

/* Region section */
.dt-region {
  margin-bottom: 28px;
}

.dt-region-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 12px;
  padding-left: 10px;
  border-left: 2px solid var(--red);
  line-height: 1;
}

.dt-shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

/* Shop card */
.dt-shop-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 6px 12px;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.1s;
  user-select: none;
}

.dt-shop-card:hover {
  border-color: #bbb;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  transform: translateY(-1px);
}

.dt-shop-card.selected {
  border-color: var(--red);
  box-shadow: 0 0 0 1px var(--red), 0 2px 10px rgba(169,21,26,0.12);
}

.dt-shop-card.selected .dt-shop-name {
  color: var(--red);
}

.dt-shop-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  line-height: 1.4;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dt-shop-status {
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center; /* centres single-span rows (收工 / 停飛) */
}

/* Open shops: each side takes equal width so separator is at card centre */
.dt-wait-ok,
.dt-wait-warn,
.dt-wait-danger {
  flex: 1;
  text-align: right;
  padding-right: 8px;
  font-weight: 600;
}

.dt-shop-groups {
  flex: 1;
  text-align: left;
  color: #035;
  font-weight: 600;
  padding-left: 8px;
  position: relative;
  display: flex;
  align-items: center;
}

.dt-shop-groups::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 1px;
  height: 12px;
  background: #ccc;
}

.dt-wait-ok      { color: #035; }
.dt-wait-warn    { color: #d9824f; }
.dt-wait-danger  { color: #d9534f; }
.dt-wait-closed  { color: #b48855; font-weight: 600; }
.dt-wait-off     { color: #d9534f; font-weight: 600; }


/* ── Right: detail panel ─────────────────────── */

.dt-detail-panel {
  width: 360px;
  min-width: 360px;
  background: var(--card);
  border-left: 1px solid var(--border);
  height: 100%;
  display: flex;
  flex-direction: column;
}

.dt-detail-scrollable {
  flex: 1;
  overflow-y: auto;
  padding-top: 16px;
  padding-bottom: 8px;
}

.dt-address-bar {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  background: var(--card);
}

.dt-address-link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
  color: var(--dark);
  line-height: 1.5;
  transition: color 0.15s;
}

.dt-address-link:hover {
  color: var(--red);
}

.dt-address-action {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}

.dt-address-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.dt-address-pin {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  margin-top: 2px;
  color: #d9534f;
}

.dt-address-text {
  font-size: 14px;
  flex: 1;
  line-height: 1.4;
}

.dt-detail-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 14px;
  color: var(--muted);
}

.dt-placeholder-icon {
  width: 56px;
  height: 56px;
  opacity: 0.18;
  filter: grayscale(1);
}

.dt-placeholder-text {
  font-size: 14px;
  text-align: center;
  line-height: 1.7;
  opacity: 0.6;
}

/* Detail panel content */
.dt-detail-content {
  padding: 20px 20px 32px;
}

.dt-detail-shop-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dt-view-toggle {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.dt-view-toggle:hover {
  background: var(--dark);
  color: #fff;
  border-color: var(--dark);
}

.dt-view-toggle.hist-active {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}


/* ── History view ────────────────────────────── */

.dt-hist-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.dt-hist-date-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--dark);
  letter-spacing: 0.3px;
}

.dt-hist-arrow {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  color: var(--dark);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.dt-hist-arrow:hover:not(:disabled) {
  background: var(--bg);
}

.dt-hist-arrow:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.dt-hist-days {
  display: flex;
  justify-content: space-around;
  margin-bottom: 14px;
}

.dt-hist-day {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  width: 28px;
  text-align: center;
  padding: 4px 0;
  border-radius: 50%;
}

.dt-hist-day.active {
  background: var(--red);
  color: #fff;
}

.dt-hist-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.dt-hist-table th {
  text-align: center;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.dt-hist-table td {
  padding: 7px 4px;
  border-bottom: 1px solid #f4f4f4;
  color: var(--dark);
  vertical-align: middle;
  font-size: 12px;
  text-align: center;
}

.dt-hist-table tr:last-child td { border-bottom: none; }

.dt-hist-warn   { color: #d9824f; font-weight: 600; }
.dt-hist-danger { color: #d9534f; font-weight: 600; }
.dt-hist-off    { color: #d9534f; font-weight: 600; }

.dt-hist-empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 0;
  font-size: 13px;
}

.dt-section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}


/* ── Ticket boxes (next 3 numbers) ───────────── */

.dt-tickets {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.dt-ticket {
  flex: 1;
  height: 54px;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: #003355;
  background: #fafafa;
  transition: border-color 0.15s, color 0.15s;
}

.dt-ticket .dt-ticket-placeholder {
  color: #ccc;
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 0;
}

.dt-ticket.on-queue {
  border-color: var(--red);
  color: var(--red);
}

.dt-ticket.loading {
  background: url(../images/loading.gif) no-repeat center;
  background-size: 24px;
  opacity: 0.3;
}


/* ── Keypad + Result row ─────────────────────── */

.dt-keypad-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

/* Keypad (left side) */
.dt-keypad {
  flex: 1;
}

.dt-keypad-display {
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #003355;
  margin-bottom: 8px;
  letter-spacing: 6px;
  transition: border-color 0.15s;
}

.dt-keypad-display .dt-keypad-placeholder {
  color: #ccc;
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 0;
}

.dt-keypad-display.digits-completed {
  border-color: var(--red);
  color: var(--red);
}

.dt-keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.dt-digit-btn,
.dt-reset-btn {
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.dt-digit-btn:hover,
.dt-reset-btn:hover {
  background: #f5f5f5;
  border-color: #bbb;
}

.dt-digit-btn:active,
.dt-reset-btn:active {
  background: #ececec;
}

.dt-digit-btn.disable,
.dt-reset-btn.disable {
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}

.dt-reset-btn {
  grid-column: span 2;
}

.dt-reset-btn svg {
  width: 18px;
  height: 18px;
}


/* Result panel (right side) */
.dt-result {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color 0.15s;
}

.dt-result.completed {
  border-color: var(--red);
}

.dt-result-group {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  color: #003355;
  border-bottom: 1px solid var(--border);
  min-height: 70px;
}

.dt-result.completed .dt-result-group {
  border-bottom-color: var(--red);
}

.dt-result-time {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  color: #003355;
  min-height: 62px;
}

.dt-result-group.loading,
.dt-result-time.loading {
  background: url(../images/loading.gif) no-repeat center;
  background-size: 24px;
  opacity: 0.3;
  font-size: 0;
}


/* Manual refresh link */
.dt-manual-refresh {
  color: #0070E0;
  font-size: 11px;
  font-weight: 400;
  cursor: pointer;
  letter-spacing: 0;
  text-transform: none;
}

.dt-manual-refresh:hover {
  text-decoration: underline;
}


/* ── Toast ───────────────────────────────────── */

#dt-toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.dt-toast {
  background: rgba(30,30,30,0.9);
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  backdrop-filter: blur(8px);
}


/* ── Responsive: narrow window ───────────────── */

@media (max-width: 900px) {
  .dt-main {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - var(--header-h));
  }

  .dt-shops-panel {
    overflow-y: unset;
  }

  #dt-list-view {
    padding: 16px 16px 24px;
  }

  #dt-map-view {
    padding: 10px 12px 12px;
  }

  #dt-leaflet-map {
    height: 60vw;
    min-height: 280px;
  }

  .dt-detail-panel {
    width: 100%;
    min-width: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    height: auto;
  }

  .dt-detail-scrollable {
    overflow-y: unset;
  }

  .dt-shop-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
}

@media (max-width: 600px) {
  .dt-subtitle { display: none; }
  .dt-shop-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}


/* ── View toggle (列表 / 地圖) ──────────────────── */

#dt-list-view {
  padding: 24px 24px 40px;
}

.dt-view-toggle-bar {
  display: flex;
  gap: 8px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 1;
}

.dt-toggle-btn {
  padding: 5px 18px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: #fff;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.dt-toggle-btn:hover {
  background: #f5f5f5;
  border-color: #bbb;
}

.dt-toggle-btn.active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}


/* ── Map container ───────────────────────────────── */

#dt-map-view {
  padding: 12px 16px 16px;
}

#dt-leaflet-map {
  width: 100%;
  /* fills viewport: subtract header + toggle bar (51px) + view padding top+bottom (28px) */
  height: calc(100vh - var(--top-h) - 79px);
  min-height: 300px;
  border-radius: 8px;
  overflow: hidden;
}

body.dt-no-marquee #dt-leaflet-map {
  height: calc(100vh - var(--header-h) - 79px);
}

/* Override Leaflet font */
.leaflet-container {
  font-family: 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
  font-size: 13px;
}


/* ── Map legend (bottom-right control) ──────────── */

.dt-map-legend {
  background: rgba(255,255,255,0.92);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1;
  box-shadow: 0 1px 5px rgba(0,0,0,0.2);
}

.dt-legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
}

.dt-legend-item:last-child {
  margin-bottom: 0;
}

.dt-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,0.7);
}


/* ── Div-icon map markers ────────────────────── */

.dt-map-marker-outer {
  background: transparent !important;
  border: none !important;
  overflow: visible !important;
}

.dt-map-marker {
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-sizing: border-box;
  white-space: nowrap;
  transition: width 0.2s ease, height 0.2s ease, border-radius 0.2s ease,
              padding 0.2s ease, font-size 0.2s ease, min-width 0.2s ease;
}

.dt-marker-label {
  display: none;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  pointer-events: none;
  letter-spacing: 0.3px;
}

/* ── Zoom breakpoints ──────────────────────── */

/* zoom ≤ 11: small dot */
#dt-leaflet-map.dt-mz-xs .dt-map-marker { width: 16px; height: 16px; }

/* zoom 12: medium dot */
#dt-leaflet-map.dt-mz-sm .dt-map-marker { width: 22px; height: 22px; }

/* zoom 13: pill appears, label visible */
#dt-leaflet-map.dt-mz-md .dt-map-marker {
  width: auto; min-width: 38px; height: 28px;
  border-radius: 14px; padding: 0 10px;
}
#dt-leaflet-map.dt-mz-md .dt-marker-label { display: block; font-size: 12px; }

/* zoom 14: pill grows */
#dt-leaflet-map.dt-mz-lg .dt-map-marker {
  width: auto; min-width: 48px; height: 34px;
  border-radius: 17px; padding: 0 13px;
  border-width: 2.5px;
}
#dt-leaflet-map.dt-mz-lg .dt-marker-label { display: block; font-size: 14px; }

/* zoom 15+: largest pill */
#dt-leaflet-map.dt-mz-xl .dt-map-marker {
  width: auto; min-width: 58px; height: 40px;
  border-radius: 20px; padding: 0 16px;
  border-width: 3px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.35);
}
#dt-leaflet-map.dt-mz-xl .dt-marker-label { display: block; font-size: 16px; }

/* Selected marker */
.dt-marker-selected {
  border-color: #a9151a !important;
  border-width: 3px !important;
  box-shadow: 0 0 0 2px rgba(169,21,26,0.3), 0 2px 8px rgba(0,0,0,0.35) !important;
}
