/* ═══════════════════════════════════════════════
   콜드체인 실시간 모니터링 Dashboard — style.css
   ═══════════════════════════════════════════════ */

:root {
  --bg:          #0a0e1a;
  --bg-card:     #111827;
  --bg-hover:    #1a2235;
  --border:      #1f2937;
  --text:        #f9fafb;
  --dim:         #9ca3af;
  --muted:       #4b5563;
  --green:       #10b981;
  --yellow:      #f59e0b;
  --red:         #ef4444;
  --gray:        #6b7280;
  --blue:        #3b82f6;
  --purple:      #8b5cf6;
  --hdr-h:       56px;
  --kpi-h:       88px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR', sans-serif;
  font-size: 14px;
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ─── Header ─────────────────────────────────────── */
#header {
  height: var(--hdr-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 10;
}
.header-left  { display: flex; align-items: center; gap: 10px; }
.header-icon  { font-size: 22px; }
h1            { font-size: 17px; font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 12px; color: var(--dim); font-size: 12px; }

.conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--gray); transition: background .3s;
  flex-shrink: 0;
}
.conn-dot.ok    { background: var(--green); }
.conn-dot.error { background: var(--red); }

.icon-btn {
  background: none; border: none; cursor: pointer;
  font-size: 17px; padding: 4px 6px; border-radius: 4px;
  color: var(--dim); transition: background .15s;
}
.icon-btn:hover { background: var(--border); color: var(--text); }

/* ─── KPI Bar ────────────────────────────────────── */
#kpi-bar {
  height: var(--kpi-h);
  display: flex; gap: 8px; padding: 8px 14px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.kpi-card {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
}
.kpi-val  { font-size: 30px; font-weight: 700; line-height: 1; }
.kpi-lbl  { font-size: 11px; color: var(--dim); font-weight: 500; }

.kpi-total   .kpi-val { color: var(--text); }
.kpi-normal  { border-color: var(--green);  } .kpi-normal  .kpi-val { color: var(--green); }
.kpi-caution { border-color: var(--yellow); } .kpi-caution .kpi-val { color: var(--yellow); }
.kpi-danger  { border-color: var(--red);    } .kpi-danger  .kpi-val { color: var(--red); }
.kpi-nosignal{ border-color: var(--gray);   } .kpi-nosignal .kpi-val{ color: var(--gray); }

/* ─── Main Layout ────────────────────────────────── */
#main {
  flex: 1; display: flex; overflow: hidden;
  height: calc(100vh - var(--hdr-h) - var(--kpi-h));
}

/* Left Panel */
#left-panel {
  width: 54%; display: flex; flex-direction: column;
  border-right: 1px solid var(--border); overflow: hidden;
}

/* Section header */
.section-hdr {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sec-title { font-size: 12px; font-weight: 700; letter-spacing: .3px; }

.badge {
  background: var(--border); color: var(--dim);
  border-radius: 10px; padding: 1px 8px; font-size: 11px; font-weight: 600;
}
.badge-red { background: rgba(239,68,68,.18); color: var(--red); }

/* Box list */
#box-section { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#box-scroll  { flex: 1; overflow-y: auto; }

#box-tbl { width: 100%; border-collapse: collapse; }
#box-tbl thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg); color: var(--muted);
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  padding: 7px 12px; text-align: left; border-bottom: 1px solid var(--border);
}
#box-tbl tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .1s;
}
#box-tbl tbody tr:hover          { background: var(--bg-hover); }
#box-tbl tbody tr.selected       { background: rgba(59,130,246,.13); }
#box-tbl tbody tr.row-danger     { background: rgba(239,68,68,.05); }
#box-tbl tbody tr.row-danger:hover{ background: rgba(239,68,68,.11); }
#box-tbl tbody td                { padding: 9px 12px; vertical-align: middle; }

.empty-row td { text-align: center; color: var(--muted); padding: 40px !important; cursor: default; }

/* Status dot */
.sdot {
  width: 10px; height: 10px; border-radius: 50%; display: inline-block;
}
.sdot.normal    { background: var(--green); }
.sdot.caution   { background: var(--yellow); }
.sdot.danger    { background: var(--red); box-shadow: 0 0 6px var(--red); animation: blink 1.4s infinite; }
.sdot.no_signal { background: var(--gray); }

@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.35} }

/* Box ID cell */
.bid { font-family: 'SF Mono','Fira Code',monospace; font-size: 12px; font-weight: 600; }
.bid-order { color: var(--text); }
.bid-mac   { display: block; font-size: 10px; color: var(--muted); margin-top: 1px; }

/* Temp coloring */
.t-ok  { color: var(--green);  font-weight: 600; }
.t-wn  { color: var(--yellow); font-weight: 600; }
.t-bad { color: var(--red);    font-weight: 600; }

/* Battery bar */
.batt-wrap { display: flex; align-items: center; gap: 6px; }
.batt-track { width: 38px; height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.batt-fill  { height: 100%; border-radius: 3px; transition: width .5s; }
.batt-ok  { background: var(--green); }
.batt-wn  { background: var(--yellow); }
.batt-bad { background: var(--red); }

.loc-txt { font-size: 10px; color: var(--dim); font-family: monospace; }

.ago { font-size: 11px; color: var(--muted); white-space: nowrap; }
.ago.fresh { color: var(--green); }
.ago.stale { color: var(--red); }

/* ─── Alerts ────────────────────────────────────── */
#alert-section {
  height: 210px; display: flex; flex-direction: column;
  border-top: 1px solid var(--border); flex-shrink: 0;
}
#alert-scroll { flex: 1; overflow-y: auto; }
#alert-list  { padding: 2px 0; }

.alert-item {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 8px 14px; border-bottom: 1px solid var(--border); font-size: 12px;
}
.alert-item:last-child { border-bottom: none; }

.atag {
  font-size: 10px; font-weight: 700; padding: 2px 6px;
  border-radius: 4px; white-space: nowrap; flex-shrink: 0; margin-top: 1px;
}
.atag-danger  { background: rgba(239,68,68,.2);  color: var(--red); }
.atag-caution { background: rgba(245,158,11,.2); color: var(--yellow); }

.abody { flex: 1; }
.abid  { font-weight: 600; color: var(--text); margin-bottom: 2px; }
.amsg  { color: var(--dim); }
.atime { color: var(--muted); font-size: 10px; margin-top: 2px; }

.empty-msg { text-align: center; padding: 30px; color: var(--muted); font-size: 13px; }

/* ─── Right Panel ────────────────────────────────── */
#right-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

#map-wrap { flex: 1; display: flex; flex-direction: column; }
#map      { flex: 1; }

/* ─── Detail Panel ───────────────────────────────── */
#detail-panel {
  display: none; flex: 1; flex-direction: column; overflow: hidden;
}
#detail-panel.visible { display: flex; }

.detail-hdr {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; background: var(--bg-card);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.back-btn {
  background: none; border: 1px solid var(--border);
  color: var(--dim); padding: 4px 10px; border-radius: 4px;
  cursor: pointer; font-size: 12px; transition: all .12s;
}
.back-btn:hover { background: var(--border); color: var(--text); }
.detail-title { font-size: 14px; font-weight: 700; font-family: monospace; flex: 1; }

.status-pill {
  font-size: 11px; font-weight: 700; padding: 3px 10px;
  border-radius: 12px; flex-shrink: 0;
}
.pill-normal    { background: rgba(16,185,129,.2);  color: var(--green); }
.pill-caution   { background: rgba(245,158,11,.2);  color: var(--yellow); }
.pill-danger    { background: rgba(239,68,68,.2);   color: var(--red); }
.pill-no_signal { background: rgba(107,114,128,.2); color: var(--gray); }

/* Detail metrics grid */
#detail-metrics {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  padding: 12px 14px; flex-shrink: 0;
}
.metric-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px;
}
.metric-lbl { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.metric-val { font-size: 24px; font-weight: 700; }

/* Detail info rows */
#detail-info {
  display: flex; flex-wrap: wrap; gap: 6px 20px;
  padding: 0 14px 10px; font-size: 12px; flex-shrink: 0;
}
.info-item   { display: flex; gap: 5px; }
.info-lbl    { color: var(--muted); }
.info-val    { color: var(--dim); font-family: monospace; }

/* Temp chart */
#chart-wrap {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  padding: 0 14px 12px; min-height: 0;
}
.chart-label { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
#temp-chart  { flex: 1; min-height: 0; }

/* ─── Scrollbars ─────────────────────────────────── */
#box-scroll::-webkit-scrollbar,
#alert-scroll::-webkit-scrollbar { width: 4px; }
#box-scroll::-webkit-scrollbar-track,
#alert-scroll::-webkit-scrollbar-track { background: var(--bg); }
#box-scroll::-webkit-scrollbar-thumb,
#alert-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ─── Modal ──────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: none; align-items: center; justify-content: center; z-index: 1000;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 24px; width: 360px;
}
.modal h2    { font-size: 15px; margin-bottom: 16px; }
.modal label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; }
.modal input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); padding: 8px 12px;
  font-size: 13px; outline: none; margin-bottom: 16px;
}
.modal input:focus { border-color: var(--blue); }
.modal-row { display: flex; gap: 8px; justify-content: flex-end; }

.btn-primary {
  background: var(--blue); color: #fff; border: none;
  border-radius: 6px; padding: 8px 16px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.btn-ghost {
  background: var(--border); color: var(--dim); border: none;
  border-radius: 6px; padding: 8px 14px; cursor: pointer; font-size: 13px;
}

/* ─── Leaflet overrides ──────────────────────────── */
.leaflet-container { background: #0d1117; }
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important; color: var(--text) !important;
  border: 1px solid var(--border) !important; box-shadow: none !important;
  border-radius: 8px !important; font-size: 12px !important;
}
.leaflet-popup-tip { background: var(--bg-card) !important; }
.leaflet-tile-pane { filter: brightness(.85) saturate(.6) hue-rotate(200deg); }

/* ─── Toast ──────────────────────────────────────── */
.toast {
  position: fixed; bottom: 16px; right: 16px;
  background: rgba(239,68,68,.92); color: #fff;
  padding: 10px 16px; border-radius: 8px; font-size: 13px;
  z-index: 9999; animation: fadeUp .3s;
}
@keyframes fadeUp { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }
