/* Amcharge AI Roof Planner — demo UI */
:root {
  --bg: #0f172a;            /* slate 900 */
  --panel: #ffffff;
  --panel-2: #f1f5f9;       /* slate 100 */
  --ink: #0f172a;
  --ink-soft: #475569;      /* slate 600 */
  --line: #e2e8f0;          /* slate 200 */
  --accent: #0ea5a4;        /* teal 500 (พลังงาน) */
  --amc: #4a8ba3;           /* Amcharge steel-teal (โลโก้) */
  --accent-dark: #0f766e;   /* teal 700 */
  --accent-soft: #ccfbf1;   /* teal 100 */
  --warn: #b45309;          /* amber 700 */
  --warn-soft: #fef3c7;     /* amber 100 */
  --danger: #b91c1c;
  --ok: #15803d;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.08);
  --r: 10px;
  font-family: 'Sarabun', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column; height: 100%;
  background: var(--panel-2); color: var(--ink);
  font-size: 14px; line-height: 1.5;
}

/* ---- Top bar ---- */
header {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; background: var(--bg); color: #e2e8f0;
  box-shadow: var(--shadow); z-index: 500;
}
header .brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo-img { height: 40px; width: auto; display: block; background: #fff; padding: 5px 9px; border-radius: 8px; }
.logo-mark { width: 40px; height: 24px; color: var(--amc); flex-shrink: 0; }
header .brand-sub { font-size: 11px; color: #94a3b8; align-self: center; }
@media (max-width: 780px) { header .brand-sub { display: none; } }
header .search { flex: 1; display: flex; gap: 6px; min-width: 0; }
header .search input {
  flex: 1; min-width: 0; padding: 9px 14px; border-radius: 8px; font-size: 15px;
  border: 1px solid #334155; background: #1e293b; color: #e2e8f0; font-family: inherit;
}
header .search input::placeholder { color: #64748b; }
.hdr-btn { color: #e2e8f0 !important; border-color: #334155 !important; background: #1e293b; flex-shrink: 0; }
.hdr-btn:hover { background: #334155; }
.lang-seg { display: inline-flex; background: #1e293b; border: 1px solid #334155; border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.lang-seg button { border: none; background: transparent; color: #94a3b8; font: inherit; font-weight: 700; padding: 8px 14px; cursor: pointer; }
.lang-seg button.active { background: var(--amc); color: #fff; }
.lang-seg button:not(.active):hover { background: #334155; color: #e2e8f0; }

/* ---- Layout ---- */
main { flex: 1; display: flex; min-height: 0; }
#map { flex: 1; min-width: 0; background: #1e293b; }
aside {
  width: 360px; max-width: 42vw; overflow-y: auto; background: var(--panel);
  border-left: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 14px;
}

/* ---- Cards ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.card h3 { margin: 0 0 10px; font-size: 16px; font-weight: 700; letter-spacing: .01em; color: var(--accent-dark); border-left: 3px solid var(--accent); padding-left: 8px; }
.sub-title { margin: 0 0 6px; font-weight: 700; color: var(--ink); font-size: 13px; }
.active-tag { display: inline-block; margin: -4px 0 10px; font-size: 11px; font-weight: 800; color: #c2410c; background: #ffedd5; border: 1px solid #fed7aa; border-radius: 999px; padding: 2px 10px; }
.active-tag:empty { display: none; }

/* ---- Project name ---- */
.proj-bar { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.proj-bar input { font-weight: 700; font-size: 15px; }

/* ---- Sticky active-roof bar ---- */
.roof-bar { position: sticky; top: 0; z-index: 6; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; box-shadow: 0 2px 8px rgba(15,23,42,.05); }
.rb-top { display: flex; align-items: center; gap: 8px; }
.rb-label { font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.rb-active { font-size: 15px; font-weight: 800; color: #fff; background: var(--amc); border: 1px solid var(--amc); border-radius: 999px; padding: 2px 14px; }
.rb-active.none { color: var(--ink-soft); background: var(--panel-2); border-color: var(--line); font-size: 12.5px; font-weight: 600; }

/* ---- Accordion (หัวข้อ 1-4) ---- */
.acc-wrap { display: flex; flex-direction: column; gap: 10px; }
.acc { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); overflow: hidden; }
.acc-head { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--panel); border: none; border-radius: 0; padding: 13px 14px; cursor: pointer; font: inherit; }
.acc-head:hover { background: var(--panel-2); }
.acc.open .acc-head { background: var(--accent-soft); }
.acc-no { flex-shrink: 0; width: 26px; height: 26px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.acc.open .acc-no { background: var(--accent-dark); }
.acc-title { font-size: 15px; font-weight: 700; color: var(--ink); flex-shrink: 0; }
.acc-sum { flex: 1; text-align: right; font-size: 12px; font-weight: 700; color: #2c6b82; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc.open .acc-sum { display: none; }
.acc-chev { flex-shrink: 0; color: var(--accent-dark); font-size: 20px; line-height: 1; font-weight: 700; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; border-radius: 7px; background: var(--panel-2); transition: transform .18s; }
.acc-head:hover .acc-chev { background: #dbeafe; }
.acc.open .acc-chev { transform: rotate(180deg); background: #fff; }
.acc-body { display: none; padding: 4px 14px 16px; border-top: 1px solid var(--line); }
.acc.open .acc-body { display: block; }

/* add-roof inline + destructive link */
.draw-inline { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
button.sm { padding: 6px 10px; font-size: 13px; }
.link-btn { background: none; border: none; color: var(--danger); font-size: 12px; padding: 8px 0 0; cursor: pointer; }
.link-btn:hover { background: none; text-decoration: underline; }

/* ---- Sticky bottom action bar ---- */
.action-bar { position: sticky; bottom: 0; z-index: 6; display: flex; gap: 10px; padding: 12px 0 4px; background: linear-gradient(to top, var(--panel) 70%, rgba(255,255,255,0)); }
.big-btn { flex: 1; padding: 15px 10px; font-size: 16px; font-weight: 800; border-radius: 12px; border: none; cursor: pointer; box-shadow: var(--shadow); }
.big-btn.add { background: #ecfdf5; color: var(--accent-dark); border: 2px solid var(--accent); }
.big-btn.add:hover { background: #d1fae5; }
.big-btn.done { background: var(--accent); color: #fff; }
.big-btn.done:hover { background: var(--accent-dark); }
.big-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Summary modal ---- */
.modal-lg { width: 640px; max-width: 94vw; max-height: 90vh; display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 18px; color: var(--accent-dark); }
.modal-x { background: var(--panel-2); border: none; border-radius: 8px; width: 32px; height: 32px; font-size: 15px; cursor: pointer; color: var(--ink-soft); }
.modal-x:hover { background: #e2e8f0; }
.modal-scroll { overflow-y: auto; padding: 18px 20px; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.foot-left { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.modal-foot .big-btn.done { flex: 0 0 auto; padding: 11px 20px; font-size: 15px; box-shadow: none; }
.cmp-title { margin: 0 0 8px; font-size: 14px; font-weight: 700; color: var(--accent-dark); }

/* ---- Controls ---- */
.row { display: flex; gap: 8px; align-items: center; }
.row + .row { margin-top: 8px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-soft); flex: 1; }
select, input[type=number], input[type=text] {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; font: inherit; color: var(--ink); background: #fff; width: 100%;
}
input[type=range] { width: 100%; accent-color: var(--accent); }
.checkbox { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-soft); }

button {
  font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 8px;
  padding: 8px 12px; cursor: pointer; background: var(--panel-2); color: var(--ink);
  transition: background .12s, border-color .12s;
}
button:hover { background: #e2e8f0; }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-dark); }
button.ghost { background: transparent; border-color: var(--line); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ยืนยัน/ล็อกแผน */
.btn-pending { background: var(--warn-soft); color: var(--warn); border: 1px solid #fcd34d; font-weight: 700; }
.btn-pending:hover { background: #fde68a; }
.btn-confirmed { background: var(--ok); color: #fff; border: 1px solid var(--ok); font-weight: 700; }
.btn-confirmed:hover { background: #166534; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Results ---- */
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric { background: var(--panel-2); border-radius: 8px; padding: 10px; }
.metric .k { font-size: 11px; color: var(--ink-soft); }
.metric .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric .u { font-size: 11px; color: var(--ink-soft); font-weight: 500; }
.metric-formula { font-size: 10px; color: var(--ink-soft); margin-top: 4px; line-height: 1.35; font-variant-numeric: tabular-nums; }
.metric.hero { grid-column: 1 / -1; background: var(--accent-soft); }
.metric.hero .v { color: var(--accent-dark); }

.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.badge { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--panel-2); color: var(--ink-soft); border: 1px solid var(--line); }
.badge.good { background: var(--accent-soft); color: var(--accent-dark); border-color: transparent; }

.warn-box { margin-top: 10px; background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; }
.warn-box b { display: block; margin-bottom: 2px; }
.warn-box ul { margin: 4px 0 0; padding-left: 18px; }

/* ---- Draw-mode pencil cursor (hotspot = pencil tip, precise) ---- */
.leaflet-container.drawing,
.leaflet-container.drawing .leaflet-interactive {
  cursor: url('data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2224%22 height=%2224%22 viewBox=%220 0 24 24%22%3E%3Cpath d=%22M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25z%22 fill=%22%23f59e0b%22 stroke=%22white%22 stroke-width=%221.2%22/%3E%3Cpath d=%22M20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34a1 1 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z%22 fill=%22%23334155%22 stroke=%22white%22 stroke-width=%221.2%22/%3E%3C/svg%3E') 3 21, crosshair !important;
}

/* ---- Walkway / obstacle list chips ---- */
.wk-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.wk-item { display: inline-flex; align-items: center; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 4px 2px 4px; font-size: 12px; }
.wk-item.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.wk-chip { border: none; background: transparent; color: #a16207; font: inherit; font-weight: 800; cursor: pointer; padding: 2px 8px; border-radius: 999px; }
.wk-chip:hover { background: #e2e8f0; }
.wk-item.ob .wk-chip { color: #b91c1c; }
.wk-del { border: none; background: #e2e8f0; color: var(--ink-soft); border-radius: 999px; width: 18px; height: 18px; padding: 0; font-size: 11px; line-height: 1; cursor: pointer; }
.wk-del:hover { background: #fca5a5; color: #7f1d1d; }
.detail-box { margin-top: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 12.5px; }

/* ---- Map tags (ท1 / อ1) ---- */
.tag-label span { position: absolute; transform: translate(-50%, -50%); white-space: nowrap; font-size: 11px; font-weight: 800; padding: 1px 7px; border-radius: 6px; border: 1.5px solid #fff; }
.wk-tag span { background: #eab308; color: #1c1917; }   /* ทางเดิน = เหลืองสด */
.ob-tag span { background: #dc2626; color: #fff; }      /* สิ่งกีดขวาง = แดง */
.roof-tag span { background: var(--amc); color: #fff; } /* หลังคา = โทน Amcharge (teal) */
.roof-tag.sel span { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--amc); }
.roof-chip { color: #2c6b82 !important; }

/* ---- Per-roof breakdown ---- */
.breakdown { margin-top: 10px; background: var(--panel-2); border-radius: 8px; padding: 10px 12px; }
.bd-title { font-size: 11px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.bd-row { display: flex; gap: 12px; align-items: center; font-size: 12.5px; padding: 4px 0; border-top: 1px solid var(--line); }
.bd-tag { font-weight: 800; color: #2c6b82; min-width: 28px; }

/* ---- Compass ---- */
.compass { cursor: pointer; text-align: center; filter: drop-shadow(0 2px 4px rgba(0,0,0,.3)); }
.compass svg { display: block; }
.compass-cap { font-size: 10px; font-weight: 700; color: #fff; background: rgba(15,23,42,.82); border-radius: 6px; margin-top: 2px; padding: 1px 0; }

/* ---- Edge-length labels (meters) ---- */
.len-label span {
  position: absolute; transform: translate(-50%, -50%); white-space: nowrap;
  background: rgba(15,23,42,.82); color: #fff; font-size: 11px; font-weight: 700;
  padding: 1px 6px; border-radius: 6px; font-variant-numeric: tabular-nums;
}
/* ---- Leaflet scale bar (make it readable) ---- */
.leaflet-control-scale-line {
  background: rgba(255,255,255,.9); color: var(--ink); font-weight: 700; font-size: 12px;
  border: 2px solid var(--ink-soft); border-top: none; padding: 2px 6px;
}

/* ---- Confidential watermark (subtle, traceable — NOT screenshot-proof) ---- */
.wm-layer { position: absolute; inset: 0; z-index: 650; pointer-events: none; background-repeat: repeat; }

/* ---- Draw-mode banner over the map ---- */
.draw-banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 600; background: rgba(15,23,42,.94); color: #fff;
  padding: 9px 16px; border-radius: 999px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow); pointer-events: none; max-width: 92%; text-align: center;
}
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(14,165,164,.5); } 50% { box-shadow: 0 0 0 6px rgba(14,165,164,0); } }
button.pulse { animation: pulse 1.4s infinite; }
@media (prefers-reduced-motion: reduce) { button.pulse { animation: none; } }

/* ---- Compare table ---- */
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
table.cmp { width: 100%; border-collapse: collapse; font-size: 13px; }
table.cmp th, table.cmp td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.cmp th:first-child, table.cmp td:first-child { text-align: left; }
table.cmp th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); font-weight: 600; }
table.cmp tr.win td { background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; }

/* ---- AI ---- */
.ai-out { white-space: pre-wrap; font-size: 13px; color: var(--ink); margin-top: 10px; min-height: 20px; }
.ai-meta { font-size: 11px; color: var(--ink-soft); margin-top: 8px; }
.ai-meta.err { color: var(--danger); }
.principle { font-size: 11.5px; color: var(--ink-soft); background: var(--panel-2); border-left: 3px solid var(--accent); padding: 8px 10px; border-radius: 0 8px 8px 0; }

/* ---- Modal ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: none; align-items: center; justify-content: center; z-index: 1000; }
.modal-bg.open { display: flex; }
.modal { background: #fff; border-radius: 12px; padding: 20px; width: 420px; max-width: 90vw; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 6px; }
.modal p { margin: 0 0 12px; font-size: 12.5px; color: var(--ink-soft); }
.modal .btns { justify-content: flex-end; margin-top: 14px; }

.hint { font-size: 11.5px; color: var(--ink-soft); }
.src-note { font-size: 11px; color: #94a3b8; }

/* ---- Responsive ---- */
@media (max-width: 780px) {
  main { flex-direction: column; }
  aside { width: 100%; max-width: none; border-left: none; border-top: 1px solid var(--line); }
  #map { min-height: 46vh; }
  header .search input { width: 180px; }
}
