/* 3D Studio — shared styles. Dark by default (3D viewport), light theme via [data-theme="light"]. */
:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e232b;
  --panel-3: #262c35;
  --border: #2c333d;
  --border-strong: #3a4350;
  --text: #e8ecf1;
  --muted: #9aa4b2;
  --faint: #6b7583;
  --accent: #00ae42;
  --accent-hover: #0cc453;
  --accent-soft: rgba(0, 174, 66, 0.14);
  --danger: #ef4d56;
  --danger-soft: rgba(239, 77, 86, 0.14);
  --warn: #f5a524;
  --warn-soft: rgba(245, 165, 36, 0.14);
  --info: #4c9aff;
  --info-soft: rgba(76, 154, 255, 0.14);
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: 'Noto Sans Thai', 'Sarabun', 'Leelawadee UI', 'Thonburi', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  color-scheme: dark;
}

:root[data-theme='light'] {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-2: #f6f8fa;
  --panel-3: #eceff3;
  --border: #dde2e8;
  --border-strong: #c8cfd8;
  --text: #1a1f26;
  --muted: #5d6775;
  --faint: #8a94a2;
  --accent-soft: rgba(0, 174, 66, 0.1);
  --shadow: 0 10px 30px rgba(20, 30, 50, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }
small, .muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- controls ---------- */
button, .btn {
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
button:hover, .btn:hover { background: var(--panel-3); text-decoration: none; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-hover); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--panel-3); }
button.sm { min-height: 28px; padding: 0 10px; font-size: 13px; }
button.icon { width: 34px; padding: 0; }
button.icon.sm { width: 28px; }
button.active, button[aria-pressed='true'] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

input, select, textarea {
  font: inherit;
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type='checkbox'], input[type='radio'] { width: auto; min-height: 0; accent-color: var(--accent); }
input[type='color'] { padding: 2px; width: 44px; height: 34px; }
input[type='range'] { padding: 0; accent-color: var(--accent); }
label { display: block; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12.5px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 4px; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sep { height: 1px; background: var(--border); margin: 6px 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--panel-3); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.swatch { width: 18px; height: 18px; border-radius: 5px; border: 1px solid rgba(255, 255, 255, 0.25); display: inline-block; flex: none; }

.progress { height: 8px; border-radius: 99px; background: var(--panel-3); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width 0.4s; }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: var(--panel-2); position: sticky; top: 0; }
table.list tr:hover td { background: var(--panel-2); }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }

.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-rows: 54px 1fr; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; color: var(--text); }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #0a7d35); display: grid; place-items: center; color: #fff; font-size: 15px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs a {
  display: flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 8px;
  color: var(--muted); font-weight: 500; white-space: nowrap;
}
.tabs a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.tabs a.active { background: var(--accent-soft); color: var(--accent); }
.topbar .spacer { flex: 1; }
.status-pill {
  display: flex; align-items: center; gap: 8px; padding: 4px 12px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border); font-size: 13px; cursor: pointer; white-space: nowrap;
}
.status-pill .progress { width: 70px; height: 6px; }
.view { overflow: auto; min-height: 0; }
.view.full { overflow: hidden; }
.page { max-width: 1400px; margin: 0 auto; padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head h2 { margin-right: auto; }

.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; z-index: 50;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px;
}
.menu-pop button { width: 100%; justify-content: flex-start; background: transparent; border-color: transparent; }
.menu-pop button:hover { background: var(--panel-3); }
.menu-pop .head { padding: 8px 10px; color: var(--muted); font-size: 12.5px; }

/* ---------- modal + toast ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow: auto;
}
.modal {
  width: min(560px, 100%); background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; max-height: 90vh;
}
.modal.wide { width: min(980px, 100%); }
.modal.xwide { width: min(1240px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin-right: auto; font-size: 16px; }
.modal-body { padding: 16px 18px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--info);
  border-radius: var(--radius-sm); padding: 10px 14px; box-shadow: var(--shadow); animation: slidein 0.2s ease-out;
}
.toast.success { border-left-color: var(--accent); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast b { display: block; }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } }

.spinner { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(ellipse at top, rgba(0, 174, 66, 0.16), transparent 60%), var(--bg); }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login-card .brand { justify-content: center; font-size: 20px; margin-bottom: 4px; }
.login-card .brand .logo { width: 36px; height: 36px; font-size: 19px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 20px; }

/* Every view fills the area under the top bar; the editor manages its own scrolling. */
#views { position: relative; min-height: 0; }
.view { position: absolute; inset: 0; overflow: auto; -webkit-overflow-scrolling: touch; }
.view.full { overflow: hidden; }
.tabs a i { font-style: normal; }
.lbl-s { display: none; }

body { overflow-x: hidden; }
.tabs { min-width: 0; flex: 0 1 auto; }
.status-pill { min-width: 0; max-width: 360px; overflow: hidden; }
.status-pill > span { overflow: hidden; text-overflow: ellipsis; }

/* Tablets (iPad portrait 768-834px, landscape 1024-1180px): short labels, compact top bar. */
@media (max-width: 1100px) {
  .tabs a .lbl { display: none; }
  .tabs a .lbl-s { display: inline; }
  .brand span { display: none; }
  .user-btn span { display: none; }
  .status-pill { max-width: 210px; }
  .status-pill .muted { display: none; }
  .tabs a { padding: 7px 9px; }
}

/* Phones (portrait) and small tablets: bottom tab bar like a native app. */
@media (max-width: 760px) {
  :root { --navh: calc(60px + env(safe-area-inset-bottom)); }
  .shell { grid-template-rows: calc(50px + env(safe-area-inset-top)) 1fr; }
  .topbar { gap: 6px; padding: env(safe-area-inset-top) 8px 0; }
  .brand span { display: none; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; height: var(--navh);
    padding: 4px 4px env(safe-area-inset-bottom); background: var(--panel); border-top: 1px solid var(--border);
    justify-content: space-around; gap: 0;
  }
  .tabs a { flex: 1; flex-direction: column; justify-content: center; gap: 1px; padding: 4px 2px; font-size: 11px; border-radius: 10px; }
  .tabs a i { font-size: 20px; line-height: 1.1; }
  .tabs a .lbl { display: none; }
  .tabs a .lbl-s { display: block; }
  .view { bottom: var(--navh); }
  .status-pill { padding: 4px 10px; font-size: 12px; min-width: 0; overflow: hidden; }
  .status-pill .progress { display: none; }
  .status-pill .muted { display: none; }
  .user-btn span { display: none; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .page { padding: 12px; }
  .toasts { bottom: calc(var(--navh) + 10px); }
  .modal-back { padding: 0; align-items: stretch; }
  .modal, .modal.wide, .modal.xwide { width: 100%; max-height: none; height: 100%; border-radius: 0; border: 0; }
  .modal-head { padding-top: calc(12px + env(safe-area-inset-top)); }
  .modal-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .notif-pop { position: fixed; left: 8px; right: 8px; top: 56px; width: auto; }
  button, .btn { min-height: 40px; }
  button.sm { min-height: 34px; }
  input, select { min-height: 40px; font-size: 16px; } /* 16px stops iOS from zooming into inputs */
}
