@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=IBM+Plex+Sans+Thai:wght@300;400;500;600&family=Space+Grotesk:wght@300;400;500;600;700&display=swap');

/* ════════════════════════════════════════════════
   THEME TOKENS — Light Mode (default)
   ════════════════════════════════════════════════ */
:root {
  --bg:    #f4f3f0;
  --bg1:   #ffffff;
  --bg2:   #f8f7f4;
  --bg3:   #eeece8;
  --bg4:   #e4e1db;
  --bg5:   #d6d2ca;
  --line:  #dedad4;
  --line2: #ccc8c0;
  --fg:    #1a1916;
  --fg1:   #3a3832;
  --fg2:   #6e6a60;
  --fg3:   #9e9a8e;
  --fg4:   #bab6aa;
  --red:       #d93b2b;
  --red-dim:   rgba(217,59,43,.10);
  --red-mid:   rgba(217,59,43,.22);
  --red-glow:  rgba(217,59,43,.35);
  --green:     #1a9e5c;
  --green-dim: rgba(26,158,92,.10);
  --amber:     #c07b00;
  --amber-dim: rgba(192,123,0,.10);
  --term-bg:   #0c0b0a;
  --mono:   'IBM Plex Mono', monospace;
  --thai:   'IBM Plex Sans Thai', sans-serif;
  --sans:   'Space Grotesk', sans-serif;
  --r:      4px;
  --r2:     8px;
  --shadow: 0 1px 4px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 24px rgba(0,0,0,.10), 0 16px 48px rgba(0,0,0,.10);
  --t: 200ms ease;
}

[data-theme="dark"] {
  --bg:    #0e0e10;
  --bg1:   #141416;
  --bg2:   #1a1a1e;
  --bg3:   #222228;
  --bg4:   #2c2c34;
  --bg5:   #38383f;
  --line:  #252530;
  --line2: #303040;
  --fg:    #ededf0;
  --fg1:   #c0bec8;
  --fg2:   #7a78a0;
  --fg3:   #4e4c68;
  --fg4:   #333355;
  --red:       #ff4035;
  --red-dim:   rgba(255,64,53,.12);
  --red-mid:   rgba(255,64,53,.28);
  --red-glow:  rgba(255,64,53,.45);
  --green:     #00e676;
  --green-dim: rgba(0,230,118,.10);
  --amber:     #ffab00;
  --amber-dim: rgba(255,171,0,.10);
  --shadow: 0 4px 20px rgba(0,0,0,.55);
  --shadow-lg: 0 8px 48px rgba(0,0,0,.80);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  height: 100%; overflow: hidden;
  background: var(--bg); color: var(--fg);
  font-family: var(--mono); font-size: 12px;
  -webkit-font-smoothing: antialiased;
  transition: background var(--t), color var(--t);
}
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg5); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--fg4); }

/* ── Layout ── */
.shell { display: grid; grid-template-rows: 52px 1fr; grid-template-columns: 288px 1fr; grid-template-areas: "top top" "side body"; height: 100vh; }

/* ── Topbar ── */
.topbar { grid-area: top; background: var(--bg1); border-bottom: 1px solid var(--line); display: flex; align-items: stretch; position: relative; z-index: 400; box-shadow: var(--shadow); transition: background var(--t), border-color var(--t); }
.topbar::before { content: ''; width: 3px; background: linear-gradient(180deg, var(--red) 0%, transparent 100%); flex-shrink: 0; }
.tb-logo { display: flex; align-items: center; padding: 0 22px; gap: 14px; border-right: 1px solid var(--line); flex-shrink: 0; transition: border-color var(--t); }
.tb-wm { font-family: var(--sans); font-size: 17px; font-weight: 700; letter-spacing: -.5px; color: var(--fg); transition: color var(--t); }
.tb-wm em { color: var(--red); font-style: normal; }
.tb-sub { font-size: 7px; letter-spacing: 2.5px; color: var(--fg3); text-transform: uppercase; border: 1px solid var(--line); padding: 3px 8px; background: var(--bg2); border-radius: var(--r); font-family: var(--mono); transition: all var(--t); }
.tb-tags { display: flex; align-items: center; padding: 0 16px; gap: 7px; border-right: 1px solid var(--line); transition: border-color var(--t); }
.tb-tag { font-size: 8px; letter-spacing: 1px; color: var(--fg3); border: 1px solid var(--line); padding: 3px 9px; text-transform: uppercase; border-radius: var(--r); background: var(--bg2); font-family: var(--mono); transition: all var(--t); }
.tb-tag.alert { color: var(--red); border-color: var(--red-dim); background: var(--red-dim); }
.tb-tag.ok    { color: var(--green); border-color: var(--green-dim); background: var(--green-dim); }
.tb-status { display: flex; align-items: center; gap: 10px; padding: 0 18px; border-right: 1px solid var(--line); transition: border-color var(--t); }
.s-led { width: 8px; height: 8px; border-radius: 50%; background: var(--bg5); flex-shrink: 0; transition: background .3s, box-shadow .3s; }
.s-led.run { background: var(--red); box-shadow: 0 0 10px var(--red-glow); animation: ledPulse 1s ease-in-out infinite; }
.s-led.done { background: var(--green); box-shadow: 0 0 8px rgba(0,230,118,.4); }
.s-led.err  { background: var(--amber); }
@keyframes ledPulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.35;transform:scale(.65)} }
.s-txt { font-size: 8px; font-weight: 600; letter-spacing: 3px; color: var(--fg3); text-transform: uppercase; transition: color .2s; font-family: var(--mono); }
.s-txt.run { color: var(--red); } .s-txt.done { color: var(--green); } .s-txt.err { color: var(--amber); }
.tb-right { margin-left: auto; display: flex; align-items: center; }

/* Theme Toggle */
.theme-toggle { display: flex; align-items: center; justify-content: center; width: 52px; height: 100%; border: none; background: transparent; cursor: pointer; border-left: 1px solid var(--line); color: var(--fg3); transition: all var(--t); position: relative; flex-shrink: 0; }
.theme-toggle:hover { background: var(--bg2); color: var(--fg1); }
.theme-toggle svg { transition: transform .4s ease, opacity .25s; }
.icon-sun  { position: absolute; }
.icon-moon { position: absolute; }
:root .icon-sun  { opacity: 0; transform: rotate(-90deg) scale(.7); }
:root .icon-moon { opacity: 1; transform: rotate(0deg) scale(1); }
[data-theme="dark"] .icon-sun  { opacity: 1; transform: rotate(0deg) scale(1); }
[data-theme="dark"] .icon-moon { opacity: 0; transform: rotate(90deg) scale(.7); }

.tb-clock { padding: 0 22px; font-size: 14px; font-weight: 300; letter-spacing: 2.5px; color: var(--fg3); border-left: 1px solid var(--line); height: 100%; display: flex; align-items: center; font-variant-numeric: tabular-nums; font-family: var(--mono); transition: all var(--t); }
.tb-menu { display: none; align-items: center; justify-content: center; width: 52px; height: 100%; border: none; background: transparent; cursor: pointer; border-right: 1px solid var(--line); flex-shrink: 0; }
.tb-menu span { display: block; width: 18px; height: 1.5px; background: var(--fg1); position: relative; transition: all .22s; }
.tb-menu span::before, .tb-menu span::after { content: ''; position: absolute; left: 0; width: 100%; height: 1.5px; background: var(--fg1); transition: all .22s; }
.tb-menu span::before { top: -5px; } .tb-menu span::after { top: 5px; }
.tb-menu.open span { background: transparent; }
.tb-menu.open span::before { top: 0; transform: rotate(45deg); }
.tb-menu.open span::after  { top: 0; transform: rotate(-45deg); }

/* ── Sidebar ── */
.sidebar { grid-area: side; background: var(--bg1); border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; transition: background var(--t), border-color var(--t); }
.s-head { display: flex; align-items: center; height: 38px; border-bottom: 1px solid var(--line); flex-shrink: 0; padding: 0 16px; gap: 10px; transition: border-color var(--t); }
.s-head-bar { width: 2px; height: 16px; background: var(--red); flex-shrink: 0; border-radius: 1px; }
.s-head-lbl { font-size: 7px; font-weight: 600; letter-spacing: 4px; text-transform: uppercase; color: var(--fg3); font-family: var(--mono); transition: color var(--t); }
.s-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.fg { padding: 16px 16px 0; margin-bottom: 16px; }
.fg-lbl { font-size: 7px; font-weight: 600; letter-spacing: 3px; text-transform: uppercase; color: var(--fg3); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; font-family: var(--mono); transition: color var(--t); }
.fg-lbl::after { content: ''; flex: 1; height: 1px; background: var(--line); transition: background var(--t); }

.f-input { width: 100%; background: var(--bg2); border: 1px solid var(--line); color: var(--fg); font-family: var(--mono); font-size: 10px; padding: 9px 12px; outline: none; transition: border-color .15s, background .15s, box-shadow .15s; letter-spacing: .5px; border-radius: var(--r); }
.f-input:focus { border-color: var(--red); background: var(--bg1); box-shadow: 0 0 0 3px var(--red-dim); }
.f-input::placeholder { color: var(--fg4); }
.f-hint { margin-top: 6px; font-size: 8px; color: var(--fg3); line-height: 1.7; font-family: var(--thai); }

.src-tabs { display: grid; grid-template-columns: 1fr 1fr 1fr; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; margin-bottom: 12px; transition: border-color var(--t); }
.src-tab { padding: 9px 0; text-align: center; font-size: 7.5px; font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase; color: var(--fg3); background: var(--bg2); border: none; cursor: pointer; border-right: 1px solid var(--line); transition: all .12s; font-family: var(--mono); }
.src-tab:last-child { border-right: none; }
.src-tab:hover { color: var(--fg1); background: var(--bg3); }
.src-tab.on { color: var(--fg); background: var(--bg); position: relative; }
.src-tab.on::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 2px; background: var(--red); }
.tp { display: none; } .tp.on { display: flex; flex-direction: column; gap: 10px; }

.dz { border: 1.5px dashed var(--line2); padding: 22px 14px; text-align: center; cursor: pointer; transition: all .15s; background: var(--bg2); border-radius: var(--r2); }
.dz:hover, .dz.over { border-color: var(--red); background: var(--red-dim); }
.dz.ok { border-style: solid; border-color: var(--green); background: var(--green-dim); }
.dz-ico { width: 36px; height: 36px; border: 1px solid var(--line2); display: flex; align-items: center; justify-content: center; margin: 0 auto 10px; color: var(--fg3); transition: all .15s; border-radius: var(--r); background: var(--bg1); }
.dz:hover .dz-ico, .dz.over .dz-ico { border-color: var(--red); color: var(--red); }
.dz.ok .dz-ico { border-color: var(--green); color: var(--green); }
.dz-title { font-size: 10px; font-weight: 600; color: var(--fg1); margin-bottom: 4px; transition: color var(--t); }
.dz-sub   { font-size: 8px; color: var(--fg3); }

.fi { display: none; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; transition: border-color var(--t); }
.fi.on { display: flex; }
.fi-row { display: flex; justify-content: space-between; padding: 7px 12px; border-bottom: 1px solid var(--line); font-size: 9px; background: var(--bg1); transition: all var(--t); }
.fi-row:last-child { border-bottom: none; }
.fi-k { color: var(--fg3); letter-spacing: 1px; text-transform: uppercase; }
.fi-v { color: var(--fg1); max-width: 155px; text-align: right; word-break: break-all; }

.folder-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; max-height: 155px; overflow-y: auto; background: var(--bg1); transition: all var(--t); }
.f-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 9px; transition: background .1s; }
.f-item:last-child { border-bottom: none; }
.f-item:hover { background: var(--bg3); }
.f-item.sel { background: var(--red-dim); border-left: 2px solid var(--red); }
.f-item.f-empty { justify-content: center; color: var(--fg3); font-size: 8px; letter-spacing: 1px; cursor: default; }
.f-dt { color: var(--fg1); font-weight: 600; }
.f-ct { color: var(--fg3); font-size: 8px; }

.param { display: flex; flex-direction: column; gap: 8px; }
.param-row { display: flex; align-items: baseline; justify-content: space-between; }
.param-key { font-size: 7px; font-weight: 600; letter-spacing: 2.5px; text-transform: uppercase; color: var(--fg3); font-family: var(--mono); }
.param-num { font-size: 22px; font-weight: 700; color: var(--fg); letter-spacing: -1.5px; font-variant-numeric: tabular-nums; transition: color var(--t); }
.param-note { font-family: var(--thai); font-size: 9px; color: var(--fg3); line-height: 1.6; }
input[type=range] { width: 100%; -webkit-appearance: none; height: 3px; background: var(--bg5); outline: none; cursor: pointer; border-radius: 2px; transition: background var(--t); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; background: var(--fg); cursor: pointer; border-radius: 3px; transition: background .1s; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
input[type=range]:hover::-webkit-slider-thumb { background: var(--red); }

.action-bar { padding: 12px 14px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px; flex-shrink: 0; background: var(--bg2); transition: all var(--t); }
.btn { font-family: var(--mono); font-size: 7.5px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 8px; transition: all .15s; border-radius: var(--r); }
.btn:disabled { opacity: .25; cursor: not-allowed; }
.btn-go { background: var(--red); color: #fff; box-shadow: 0 2px 10px var(--red-mid); }
.btn-go:not(:disabled):hover { filter: brightness(1.08); box-shadow: 0 4px 18px var(--red-mid); transform: translateY(-1px); }
.btn-pause { background: transparent; color: var(--amber); border: 1px solid var(--amber-dim); }
.btn-pause:not(:disabled):hover { background: var(--amber-dim); border-color: var(--amber); }
.btn-stop { background: transparent; color: var(--fg3); border: 1px solid var(--line); }
.btn-stop:not(:disabled):hover { border-color: var(--red); color: var(--red); }

/* ── Body ── */
.body { grid-area: body; display: flex; flex-direction: column; min-height: 0; overflow: hidden; background: var(--bg); transition: background var(--t); }

.metrics { display: grid; grid-template-columns: repeat(5,1fr) auto; border-bottom: 1px solid var(--line); background: var(--bg1); flex-shrink: 0; transition: all var(--t); }
.metric { padding: 14px 18px; border-right: 1px solid var(--line); position: relative; transition: background .15s; }
.metric:hover { background: var(--bg2); }
.metric::before { content: attr(data-label); display: block; font-size: 6px; font-weight: 600; letter-spacing: 3.5px; text-transform: uppercase; color: var(--fg3); margin-bottom: 5px; font-family: var(--mono); transition: color var(--t); }
.mnum { font-size: 28px; font-weight: 700; line-height: 1; letter-spacing: -2px; color: var(--fg); transition: color .3s; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.mnum.dim { color: var(--bg5); } .mnum.grn { color: var(--green); } .mnum.ylw { color: var(--amber); } .mnum.red { color: var(--red); }
.mstrip { position: absolute; bottom: 0; left: 0; right: 0; height: 3px; opacity: .5; border-radius: 0 0 2px 2px; }
.meta-eta { padding: 14px 20px; display: flex; flex-direction: column; justify-content: center; gap: 4px; min-width: 110px; }
.meta-eta::before { content: 'ETA'; font-size: 6px; letter-spacing: 4px; color: var(--fg3); text-transform: uppercase; font-family: var(--mono); }
.eta-val { font-size: 20px; font-weight: 700; color: var(--fg2); letter-spacing: -1px; font-variant-numeric: tabular-nums; transition: color .3s; }

.prog-row { display: none; height: 38px; padding: 0 20px; background: var(--bg1); border-bottom: 1px solid var(--line); align-items: center; gap: 14px; flex-shrink: 0; transition: all var(--t); }
.prog-row.on { display: flex; }
.prog-file { font-size: 8px; color: var(--fg3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; font-family: var(--thai); }
.prog-track { flex: 3; height: 3px; background: var(--bg4); position: relative; border-radius: 2px; overflow: hidden; }
.prog-fill { position: absolute; top: 0; left: 0; bottom: 0; background: var(--red); width: 0%; transition: width .3s cubic-bezier(.4,0,.2,1); border-radius: 2px; }
.prog-fill::after { content: ''; position: absolute; right: 0; top: 0; bottom: 0; width: 50px; background: linear-gradient(90deg, transparent, rgba(255,255,255,.3)); }
.prog-fill.done { background: var(--green); } .prog-fill.done::after { display: none; }
.prog-pct { font-size: 10px; font-weight: 700; color: var(--fg1); min-width: 40px; text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.prog-pct.done { color: var(--green); }

.content { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; position: relative; }

.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; background: var(--bg); position: relative; overflow: hidden; }
.empty::before { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse 60% 40% at 50% 55%, var(--red-dim) 0%, transparent 70%); pointer-events: none; }
.empty-icon { width: 72px; height: 72px; border: 1px solid var(--line2); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--fg4); position: relative; background: var(--bg1); box-shadow: var(--shadow); transition: all var(--t); }
.empty-icon::before { content: ''; position: absolute; inset: -8px; border-radius: 50%; border: 1px dashed var(--line); opacity: .6; }
.empty-lbl { font-size: 8px; font-weight: 700; letter-spacing: 5px; color: var(--fg3); text-transform: uppercase; font-family: var(--mono); }
.empty-sub { font-family: var(--thai); font-size: 12px; color: var(--fg4); }

/* ── Gallery ── */
.gallery { display: none; flex: 1; flex-direction: column; min-height: 0; overflow: hidden; }
.gallery.on { display: flex; }
.gal-bar { padding: 8px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; background: var(--bg1); flex-shrink: 0; transition: all var(--t); }
.gal-cnt { font-size: 8px; letter-spacing: 2px; color: var(--fg3); text-transform: uppercase; font-family: var(--mono); }
.gal-filters { display: flex; gap: 4px; margin-left: auto; }
.gf { font-size: 7px; font-weight: 700; letter-spacing: 2px; padding: 4px 12px; border: 1px solid var(--line); background: transparent; color: var(--fg3); cursor: pointer; text-transform: uppercase; transition: all .12s; border-radius: var(--r); font-family: var(--mono); }
.gf:hover { border-color: var(--fg3); color: var(--fg1); background: var(--bg2); }
.gf.on { border-color: var(--red); color: var(--red); background: var(--red-dim); }

.gal-grid { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: grid; grid-template-columns: repeat(auto-fill, 216px); grid-auto-rows: max-content; gap: 10px; align-content: start; align-items: start; justify-content: start; }

.card { width: 216px; background: var(--bg1); border: 1px solid var(--line); border-radius: var(--r2); display: flex; flex-direction: column; cursor: pointer; transition: border-color .15s, box-shadow .2s, transform .12s; animation: cardIn .22s ease forwards; opacity: 0; flex-shrink: 0; }
.card:hover { border-color: var(--fg3); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.card.c-ok   { border-top: 2px solid var(--green); }
.card.c-warn { border-top: 2px solid var(--amber); }
.card.c-err  { border-top: 2px solid var(--red); }
@keyframes cardIn { from{opacity:0;transform:translateY(10px) scale(.97)} to{opacity:1;transform:translateY(0) scale(1)} }

.card-top { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 7px; border-bottom: 1px solid var(--line); background: var(--bg2); transition: all var(--t); border-radius: var(--r2) var(--r2) 0 0; }
.card-num { font-size: 8px; font-weight: 600; letter-spacing: 1px; color: var(--fg4); font-variant-numeric: tabular-nums; font-family: var(--mono); }
.card-badge { font-size: 6px; font-weight: 700; letter-spacing: 1.5px; padding: 2px 8px; text-transform: uppercase; border-radius: 20px; font-family: var(--mono); }
.card-badge.ok   { background: var(--green-dim); color: var(--green); }
.card-badge.warn { background: var(--amber-dim);  color: var(--amber); }
.card-badge.err  { background: var(--red-dim);    color: var(--red); }
.card-body { padding: 10px 12px 8px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.c-field { display: flex; flex-direction: column; gap: 2px; }
.c-label { font-size: 6px; font-weight: 600; letter-spacing: 2px; text-transform: uppercase; color: var(--fg4); font-family: var(--mono); }
.c-wb  { font-size: 10px; font-weight: 500; color: var(--fg1); letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.c-nm  { font-family: var(--thai); font-size: 11px; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.c-tel { font-size: 9px; color: var(--fg2); letter-spacing: 1px; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.card-foot { padding: 6px 12px; border-top: 1px solid var(--line); font-size: 7px; color: var(--fg4); letter-spacing: .5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--bg2); font-family: var(--mono); transition: all var(--t); border-radius: 0 0 var(--r2) var(--r2); }

/* ── Bottom bar ── */
.bot-bar { background: var(--bg1); border-top: 1px solid var(--line); padding: 8px 20px; display: flex; align-items: center; gap: 12px; flex-shrink: 0; transition: all var(--t); }
.bot-stat { font-size: 8px; color: var(--fg3); font-family: var(--mono); }
.bot-stat b { color: var(--fg1); }
.exp-btn { display: none; align-items: center; gap: 7px; padding: 7px 16px; font-family: var(--mono); font-size: 8px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; border: 1px solid var(--green-dim); background: transparent; color: var(--green); cursor: pointer; transition: all .15s; border-radius: var(--r); margin-left: auto; }
.exp-btn.on { display: flex; }
.exp-btn:hover { border-color: var(--green); background: var(--green-dim); box-shadow: 0 0 14px rgba(0,230,118,.15); }

/* ── Terminal — always dark ── */
.terminal { background: var(--term-bg); border-top: 1px solid var(--line); height: 115px; display: flex; flex-direction: column; flex-shrink: 0; }
.term-top { display: flex; align-items: center; padding: 0 16px; height: 30px; border-bottom: 1px solid rgba(255,255,255,.06); gap: 8px; flex-shrink: 0; }
.mac { width: 8px; height: 8px; border-radius: 50%; }
.mac.r { background: #e05252; } .mac.y { background: #d4a017; } .mac.g { background: #3aaf67; }
.term-ttl { margin-left: 6px; font-size: 7px; letter-spacing: 3px; color: rgba(255,255,255,.14); text-transform: uppercase; font-family: var(--mono); }
.term-cnt { margin-left: auto; font-size: 7px; letter-spacing: 2px; color: rgba(255,255,255,.10); font-family: var(--mono); }
.term-body { flex: 1; overflow-y: auto; padding: 7px 16px; font-size: 9px; line-height: 2; scroll-behavior: smooth; font-family: var(--mono); }
.tl { color: rgba(255,255,255,.18); }
.tl.ok   { color: #3aaf67; } .tl.err { color: #e05252; } .tl.warn { color: #d4a017; } .tl.info { color: rgba(255,255,255,.48); }
.tl:last-child::after { content: '█'; animation: blink .9s step-end infinite; opacity: .4; margin-left: 3px; color: var(--red); }
@keyframes blink { 0%,100%{opacity:.4} 50%{opacity:0} }

/* ── Modal ── */
.modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1000; align-items: center; justify-content: center; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
[data-theme="dark"] .modal-bg { background: rgba(0,0,0,.75); }
.modal-bg.on { display: flex; }
.modal-box { background: var(--bg1); border: 1px solid var(--line); border-top: 3px solid var(--red); width: min(680px,95vw); max-height: 90vh; display: flex; flex-direction: column; overflow: hidden; animation: mIn .18s ease; border-radius: var(--r2); box-shadow: var(--shadow-lg); transition: background var(--t); }
@keyframes mIn { from{opacity:0;transform:translateY(-12px) scale(.97)} to{opacity:1;transform:translateY(0) scale(1)} }
.modal-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); gap: 10px; background: var(--bg2); transition: all var(--t); }
.modal-dot { width: 7px; height: 7px; background: var(--red); border-radius: 50%; flex-shrink: 0; }
.modal-ttl { font-size: 9px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--fg1); font-family: var(--mono); }
.modal-cls { margin-left: auto; padding: 5px 12px; font-family: var(--mono); font-size: 8px; font-weight: 600; letter-spacing: 2px; border: 1px solid var(--line); background: transparent; color: var(--fg3); cursor: pointer; text-transform: uppercase; transition: all .1s; border-radius: var(--r); }
.modal-cls:hover { border-color: var(--red); color: var(--red); background: var(--red-dim); }
.modal-fields { padding: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; overflow-y: auto; }
.mf { background: var(--bg2); border: 1px solid var(--line); border-left: 2px solid var(--line2); padding: 12px 14px; display: flex; flex-direction: column; gap: 5px; border-radius: var(--r); transition: all var(--t); }
.mf.full { grid-column: 1 / -1; } .mf.hit { border-left-color: var(--green); } .mf.warn { border-left-color: var(--amber); }
.mf-k { font-size: 7px; font-weight: 600; letter-spacing: 2px; color: var(--fg3); text-transform: uppercase; font-family: var(--mono); }
.mf-v { font-size: 13px; color: var(--fg); word-break: break-all; font-family: var(--thai); font-weight: 500; transition: color var(--t); }
.mf-v.grn { color: var(--green); } .mf-v.ylw { color: var(--amber); }

.side-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 299; opacity: 0; transition: opacity .25s; backdrop-filter: blur(3px); }
.side-overlay.on { display: block; opacity: 1; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .shell { grid-template-columns: 268px 1fr; }
  .tb-sub { display: none; }
  .metrics { grid-template-columns: repeat(3,1fr) auto; }
  .metric:nth-child(4), .metric:nth-child(5) { display: none; }
  .mnum { font-size: 24px; }
  .gal-grid { grid-template-columns: repeat(auto-fill, 204px); }
  .card { width: 204px; }
}

@media (max-width: 768px) {
  html, body { overflow: auto; }
  .shell { grid-template-columns: 1fr; grid-template-rows: 52px 1fr; grid-template-areas: "top top" "body body"; }
  .tb-menu { display: flex; }
  .tb-tags { display: none; }
  .tb-logo { padding: 0 14px; }
  .tb-wm { font-size: 15px; }
  .sidebar { position: fixed; top: 52px; left: 0; bottom: 0; width: min(300px,85vw); z-index: 300; transform: translateX(-100%); transition: transform .25s ease; box-shadow: 4px 0 32px rgba(0,0,0,.15); }
  [data-theme="dark"] .sidebar { box-shadow: 4px 0 32px rgba(0,0,0,.65); }
  .sidebar.open { transform: translateX(0); }
  .metrics { grid-template-columns: repeat(3,1fr); }
  .metric:nth-child(4), .metric:nth-child(5) { display: none; }
  .mnum { font-size: 20px; }
  .gal-grid { padding: 8px; grid-template-columns: repeat(auto-fill, 180px); gap: 7px; }
  .card { width: 180px; }
  .modal-fields { grid-template-columns: 1fr; }
  .action-bar { gap: 5px; padding: 10px 12px; }
  .btn { font-size: 7px; padding: 9px 5px; }
  .terminal { height: 88px; }
}

@media (max-width: 480px) {
  .gal-grid { grid-template-columns: repeat(auto-fill, 160px); gap: 6px; }
  .card { width: 160px; }
  .metrics { grid-template-columns: repeat(2,1fr) auto; }
  .metric:nth-child(3) { display: none; }
  .tb-clock { display: none; }
}
/* ─── Modal Image Preview ─────────────────────────────────────── */
/* override grid เฉพาะเมื่อมีรูป โดยใช้ class has-img บน modal-fields */
.modal-fields.has-img { padding: 0; display: flex; flex-direction: column; gap: 0; }

.modal-img-wrap {
  position: relative;
  width: 100%;
  max-height: 52vh;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100px;
  flex-shrink: 0;
}
.modal-img-wrap.loaded .modal-img-spinner { display: none; }
.modal-img-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  opacity: .5;
}

.modal-img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  object-position: top center;
  opacity: 0;
  transition: opacity .3s ease;
  cursor: zoom-in;
}
.modal-img-wrap.loaded .modal-img { opacity: 1; }

/* fields grid ด้านล่างรูป — ใช้ grid เดิมแต่ wrap ใน div */
.modal-fields.has-img .mf-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 14px;
  overflow-y: auto;
}
@media (max-width: 600px) {
  .modal-fields.has-img .mf-grid { grid-template-columns: 1fr; }
}
