/* ME Studio design system: tokens, components and the app shell.
   Every page loads this file (nav.js adds it when a page does not link it).
   Element defaults for the older pages live in style.css; this file only
   styles classes, so it never fights a page's own stylesheet.
   Light theme by default; <html data-theme="dark"> switches to dark. */

:root {
  /* color */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --surface-3: #eceef2;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-2: #344054;
  --muted: #667085;
  --faint: #98a2b3;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-text: #3730a3;
  --success: #12b76a;
  --success-soft: #ecfdf3;
  --success-text: #027a48;
  --warn: #f79009;
  --warn-soft: #fffaeb;
  --warn-text: #b54708;
  --danger: #f04438;
  --danger-soft: #fef3f2;
  --danger-text: #b42318;
  --info-soft: #eff8ff;
  --info-text: #175cd3;
  --overlay: rgba(16, 24, 40, .45);
  /* older names used by existing pages */
  --panel: var(--surface);
  --panel-2: var(--surface-2);
  --accent-2: var(--success);
  --code-bg: var(--surface-2);
  /* space */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px;
  /* radius */
  --r-sm: 6px; --r: 8px; --r-lg: 12px; --r-full: 999px;
  /* type */
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --fs-xs: 12px; --fs-sm: 13px; --fs: 14px; --fs-md: 15px; --fs-lg: 17px; --fs-xl: 20px; --fs-2xl: 24px; --fs-3xl: 30px;
  /* depth */
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-md: 0 4px 8px -2px rgba(16, 24, 40, .08), 0 2px 4px -2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 24px -4px rgba(16, 24, 40, .12), 0 4px 8px -4px rgba(16, 24, 40, .06);
  --ring: 0 0 0 4px rgba(79, 70, 229, .16);
  /* shell */
  --sidebar-w: 256px;
  --topbar-h: 56px;
  --tabbar-h: 64px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #0c0e12;
  --surface: #14171c;
  --surface-2: #1b1f26;
  --surface-3: #232831;
  --border: #262b33;
  --border-strong: #353b45;
  --text: #f2f4f7;
  --text-2: #d0d5dd;
  --muted: #98a2b3;
  --faint: #667085;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-soft: rgba(99, 102, 241, .14);
  --accent-text: #a5b4fc;
  --success-soft: rgba(18, 183, 106, .12);
  --success-text: #6ce9a6;
  --warn-soft: rgba(247, 144, 9, .12);
  --warn-text: #fec84b;
  --danger-soft: rgba(240, 68, 56, .12);
  --danger-text: #fda29b;
  --info-soft: rgba(46, 144, 250, .12);
  --info-text: #84caff;
  --overlay: rgba(0, 0, 0, .6);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 8px -2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 24px -4px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ---------------------------------------------------------------- shell */
body.app { font-family: var(--font); background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ico-sm { width: 16px; height: 16px; }
.ico-lg { width: 22px; height: 22px; }

.app-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 60;
  display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border);
  font-family: var(--font);
}
.app-brand { display: flex; align-items: center; gap: 10px; height: 64px; padding: 0 20px; text-decoration: none; color: var(--text); flex: none; }
.app-logo { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 14px; background: linear-gradient(135deg, var(--accent), #7c3aed); box-shadow: var(--shadow-sm); }
.app-brand-name { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.app-brand-tag { font-size: 11px; color: var(--muted); font-weight: 500; margin-left: auto; padding: 2px 8px; border: 1px solid var(--border); border-radius: var(--r-full); }
.app-nav { flex: 1; overflow-y: auto; padding: 4px 12px 16px; scrollbar-width: thin; }
.app-nav-section { margin-top: 18px; }
.app-nav-section:first-child { margin-top: 4px; }
.app-nav-title { font-size: 11px; font-weight: 600; color: var(--faint); letter-spacing: .04em; padding: 0 10px 6px; text-transform: uppercase; }
.app-nav a {
  display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 7px 10px; border-radius: var(--r);
  color: var(--text-2); text-decoration: none; font-size: var(--fs); font-weight: 500; line-height: 1.3;
}
.app-nav a .ico { color: var(--faint); }
.app-nav a:hover { background: var(--surface-2); color: var(--text); }
.app-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.app-nav a[aria-current="page"] .ico { color: var(--accent); }
.app-nav a.sub { padding-left: 38px; min-height: 32px; font-size: var(--fs-sm); }
.app-nav a .count { margin-left: auto; font-size: 11px; font-weight: 600; color: var(--muted); background: var(--surface-2); border-radius: var(--r-full); padding: 1px 7px; }
.app-nav a .count.hot { color: #fff; background: var(--accent); }
.app-side-foot { flex: none; border-top: 1px solid var(--border); padding: 10px 12px; display: flex; gap: 6px; align-items: center; }
.app-side-foot .status-line { font-size: var(--fs-xs); color: var(--muted); display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }

.app-topbar { display: none; }
.app-tabbar { display: none; }
.app-scrim { display: none; }

@media (min-width: 1024px) {
  body.app { padding-left: var(--sidebar-w); }
}
@media (max-width: 1023.98px) {
  body.app { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .app-sidebar { transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow-lg); width: min(300px, 86vw); }
  body.app.nav-open .app-sidebar { transform: none; }
  body.app.nav-open .app-scrim { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 55; }
  body.app.nav-open { overflow: hidden; }
  .app-topbar {
    display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 40; height: var(--topbar-h);
    padding: 0 8px 0 4px; background: var(--surface); border-bottom: 1px solid var(--border); font-family: var(--font);
  }
  .app-topbar .app-brand { height: auto; padding: 0 4px; }
  .app-topbar .app-brand-name { font-size: 15px; }
  .app-tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border); font-family: var(--font);
  }
  .app-tabbar a, .app-tabbar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0;
    color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 500; background: none; border: 0; padding: 0; border-radius: 0; font-family: inherit;
  }
  .app-tabbar .ico { width: 22px; height: 22px; }
  .app-tabbar [aria-current="page"] { color: var(--accent); font-weight: 600; }
}
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border-radius: var(--r);
  background: transparent; border: 1px solid transparent; color: var(--text-2); cursor: pointer; box-shadow: none;
}
.icon-btn:hover { background: var(--surface-2); border-color: transparent; }

/* page header: breadcrumb, title, one-line description, actions on the right */
body.app > header.page-header,
body.app > header.ws-header.page-header {
  position: sticky; top: 0; z-index: 30; display: block; padding: 0; margin: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border); font-family: var(--font);
}
body.app.ws > header.page-header { position: static; }
@media (max-width: 1023.98px) { body.app > header.page-header { top: var(--topbar-h); } }
.page-header-inner { max-width: 1160px; margin: 0 auto; padding: 18px 32px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.page-heading { flex: 1 1 320px; min-width: 0; }
.crumbs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: var(--fs-xs); color: var(--muted); margin: 0 0 4px; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.crumbs .ico { width: 12px; height: 12px; color: var(--faint); }
.page-header h1, .page-title { margin: 0; font-size: var(--fs-2xl); line-height: 1.25; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.page-desc { margin: 4px 0 0; font-size: var(--fs); color: var(--muted); line-height: 1.5; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-actions .module-badges { display: none; }
@media (max-width: 640px) {
  .page-header-inner { padding: 14px 16px 12px; gap: 10px; }
  .page-header h1, .page-title { font-size: var(--fs-xl); }
  .page-desc { font-size: var(--fs-sm); }
  .page-actions { width: 100%; }
  .page-actions > .btn, .page-actions > button { flex: 1 1 auto; justify-content: center; }
}

/* the older top button menu is gone; pages that still print it hide it */
nav.snav { display: none !important; }

/* ---------------------------------------------------------------- layout helpers */
.container { max-width: 1160px; margin: 0 auto; padding: 24px 32px 56px; display: flex; flex-direction: column; gap: 24px; }
@media (max-width: 640px) { .container { padding: 16px 16px 40px; gap: 16px; } }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.hstack { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 0 0 12px; }
.section-title { margin: 0; font-size: var(--fs-lg); font-weight: 700; letter-spacing: -.01em; color: var(--text); }
.section-sub { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--muted); }
.text-muted { color: var(--muted); }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- card */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-xs); min-width: 0; }
.card-body { padding: 20px 24px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 24px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; font-size: var(--fs-md); font-weight: 650; color: var(--text); }
.card-head p { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--muted); }
.card-foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); flex-wrap: wrap; }
@media (max-width: 640px) { .card-body { padding: 16px; } .card-head { padding: 14px 16px; } .card-foot { padding: 12px 16px; } }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 8px 14px;
  font: inherit; font-size: var(--fs); font-weight: 600; line-height: 1.2; white-space: nowrap; cursor: pointer; text-decoration: none;
  color: var(--text-2); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r); box-shadow: var(--shadow-xs);
  transition: background .15s, border-color .15s, box-shadow .15s, color .15s;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger-text); }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: var(--fs-sm); }
.btn-lg { min-height: 46px; padding: 12px 20px; font-size: var(--fs-md); }
.btn-block { width: 100%; }

/* ---------------------------------------------------------------- pills / badges */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 600; line-height: 20px; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2); border: 1px solid transparent;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.pill.plain::before { display: none; }
.pill.ok { background: var(--success-soft); color: var(--success-text); }
.pill.warn { background: var(--warn-soft); color: var(--warn-text); }
.pill.err { background: var(--danger-soft); color: var(--danger-text); }
.pill.info { background: var(--info-soft); color: var(--info-text); }
.pill.accent { background: var(--accent-soft); color: var(--accent-text); }
.pill.live::before { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--border); font-size: var(--fs-sm); color: var(--text-2); min-width: 0; }
.chip b { font-weight: 600; color: var(--text); }
.chip .k { color: var(--muted); }

/* ---------------------------------------------------------------- form */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 16px 20px; }
.form-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-field.span-all { grid-column: 1 / -1; }
.form-label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); margin: 0; display: block; }
.form-help { font-size: var(--fs-xs); color: var(--muted); margin: 0; line-height: 1.45; }
.input, .select, .textarea {
  width: 100%; font: inherit; font-size: var(--fs); color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r); padding: 9px 12px; box-shadow: var(--shadow-xs); min-height: 40px;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.check { display: inline-flex; align-items: flex-start; gap: 10px; font-size: var(--fs); color: var(--text-2); cursor: pointer; margin: 0; line-height: 1.4; }
.check input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.check small { display: block; color: var(--muted); font-size: var(--fs-xs); }

/* ---------------------------------------------------------------- disclosure */
details.disclosure { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
details.disclosure > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 14px 20px; font-weight: 600; font-size: var(--fs); color: var(--text-2);
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::after { content: ""; margin-left: auto; width: 8px; height: 8px; border-right: 2px solid var(--faint); border-bottom: 2px solid var(--faint); transform: rotate(45deg); transition: transform .15s; }
details.disclosure[open] > summary::after { transform: rotate(-135deg); }
details.disclosure > summary .text-muted { font-weight: 400; font-size: var(--fs-sm); }
details.disclosure > .disclosure-body { padding: 4px 20px 20px; border-top: 1px solid var(--border); }
@media (max-width: 640px) { details.disclosure > summary { padding: 12px 16px; } details.disclosure > .disclosure-body { padding: 4px 16px 16px; } }

/* ---------------------------------------------------------------- stat card */
.stat { padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; }
a.stat:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.stat-label { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--muted); font-weight: 500; }
.stat-label .ico { width: 16px; height: 16px; }
.stat-value { font-size: var(--fs-3xl); font-weight: 700; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--text); }
.stat-foot { font-size: var(--fs-xs); color: var(--muted); }
.stat.attention .stat-value { color: var(--accent); }
.stat.bad .stat-value { color: var(--danger-text); }

/* ---------------------------------------------------------------- category card */
.cat-card { display: flex; gap: 14px; padding: 16px; text-decoration: none; color: inherit; align-items: flex-start; transition: border-color .15s, box-shadow .15s, transform .15s; }
.cat-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.cat-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent); }
.cat-icon.tone-2 { background: var(--success-soft); color: var(--success-text); }
.cat-icon.tone-3 { background: var(--warn-soft); color: var(--warn-text); }
.cat-icon.tone-4 { background: var(--info-soft); color: var(--info-text); }
.cat-icon.tone-5 { background: var(--danger-soft); color: var(--danger-text); }
.cat-title { margin: 0; font-size: var(--fs-md); font-weight: 650; color: var(--text); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cat-desc { margin: 3px 0 0; font-size: var(--fs-sm); color: var(--muted); line-height: 1.45; }

/* ---------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th { text-align: left; font-size: var(--fs-xs); font-weight: 600; color: var(--muted); padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-2); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table td.title-cell { color: var(--text); font-weight: 500; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .table th, .table td { padding: 10px 12px; } .table td.title-cell { max-width: 180px; } }

/* list rows (mobile-friendly alternative to a table) */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); text-decoration: none; color: inherit; min-width: 0; }
.list-row:last-child { border-bottom: 0; }
a.list-row:hover { background: var(--surface-2); }
.list-main { flex: 1; min-width: 0; }
.list-title { font-size: var(--fs); font-weight: 550; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-meta { font-size: var(--fs-xs); color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) { .list-row { padding: 12px 16px; } }

/* ---------------------------------------------------------------- empty / skeleton / alert / toast */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 40px 24px; color: var(--muted); }
.empty .empty-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--faint); margin-bottom: 4px; }
.empty h3 { margin: 0; font-size: var(--fs-md); color: var(--text); font-weight: 650; }
.empty p { margin: 0; font-size: var(--fs-sm); max-width: 380px; }
.empty .btn { margin-top: 8px; }

.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--r-sm); color: transparent !important; min-height: 1em; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .55), transparent); animation: shimmer 1.3s infinite; }
html[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .06), transparent); }
.skeleton-line { height: 12px; margin: 8px 0; }
.skeleton-value { height: 30px; width: 60px; }
@keyframes shimmer { to { transform: translateX(100%); } }

.alert-box { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: var(--r); font-size: var(--fs-sm); line-height: 1.5; border: 1px solid transparent; }
.alert-box .ico { margin-top: 1px; }
.alert-box.info { background: var(--info-soft); color: var(--info-text); }
.alert-box.warn { background: var(--warn-soft); color: var(--warn-text); }
.alert-box.err { background: var(--danger-soft); color: var(--danger-text); }
.alert-box.ok { background: var(--success-soft); color: var(--success-text); }
.alert-box b { font-weight: 650; }

.toast-stack { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
@media (max-width: 1023.98px) { .toast-stack { left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + 12px); } }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-radius: var(--r-lg); background: var(--text); color: var(--surface); font-size: var(--fs-sm); font-weight: 500; box-shadow: var(--shadow-lg); animation: toast-in .2s ease; max-width: 420px; }
.toast.err { background: var(--danger-text); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.dot-status { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: inline-block; flex: none; }
.dot-status.ok { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.dot-status.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot-status.err { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

/* ---------------------------------------------------------------- tabs (segmented) */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); }
.segmented a, .segmented button { padding: 6px 12px; border-radius: 6px; font-size: var(--fs-sm); font-weight: 600; color: var(--muted); text-decoration: none; background: none; border: 0; box-shadow: none; min-height: 0; cursor: pointer; }
.segmented [aria-selected="true"], .segmented [aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------------------------------------------------------------- utilities added 10/21 (b) */
/* [hidden] always wins over a component's display (alert-box, form-field …) */
[hidden] { display: none !important; }
:target, [id] { scroll-margin-top: 96px; }

/* sortable table: <th data-sort="key"> + MEUI.sortable(table) */
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]:hover { color: var(--text); }
.table th[data-sort]::after { content: ""; display: inline-block; width: 0; height: 0; margin-left: 6px; vertical-align: 2px; border: 4px solid transparent; border-top-color: var(--faint); border-bottom: 0; opacity: .5; }
.table th[aria-sort="ascending"]::after { border-top: 0; border-bottom: 4px solid var(--accent); opacity: 1; }
.table th[aria-sort="descending"]::after { border-top-color: var(--accent); opacity: 1; }
.table td.actions { white-space: nowrap; text-align: right; }
.table td.actions .btn, .table td.actions select { margin: 2px 0 2px 4px; }
.table .thumb { width: 96px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: var(--r-sm); background: var(--surface-2); display: block; }
.table .cell-title { display: flex; gap: 12px; align-items: flex-start; min-width: 240px; }
.table .cell-title b { display: block; color: var(--text); font-weight: 600; line-height: 1.4; }
.table .cell-sub { font-size: var(--fs-xs); color: var(--muted); margin-top: 2px; word-break: break-all; }
@media (max-width: 760px) {
  /* stacked rows on a phone */
  .table.stack-sm thead { display: none; }
  .table.stack-sm, .table.stack-sm tbody, .table.stack-sm tr, .table.stack-sm td { display: block; width: 100%; }
  .table.stack-sm tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .table.stack-sm td { padding: 3px 0; border: 0; }
  .table.stack-sm td[data-label]::before { content: attr(data-label); display: inline-block; min-width: 64px; color: var(--muted); font-size: var(--fs-xs); }
  .table.stack-sm td.actions { text-align: left; white-space: normal; padding-top: 8px; }
  .table.stack-sm td.actions .btn { margin: 4px 6px 0 0; }
  .table.stack-sm .cell-title { min-width: 0; }
  .table.stack-sm tbody tr:hover td { background: none; }
}

/* toolbar above a list: filters left, actions right */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 24px; border-bottom: 1px solid var(--border); }
.toolbar .segmented { flex-wrap: wrap; }
@media (max-width: 640px) { .toolbar { padding: 12px 16px; } }
.segmented .n { margin-left: 4px; font-weight: 500; color: var(--faint); font-variant-numeric: tabular-nums; }

/* small "자세히" area for internal ids / agent names */
details.more { font-size: var(--fs-xs); color: var(--muted); }
details.more > summary { cursor: pointer; color: var(--muted); font-size: var(--fs-xs); list-style: none; display: inline-flex; align-items: center; gap: 4px; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "＋"; font-size: 10px; }
details.more[open] > summary::before { content: "－"; }
details.more > :not(summary) { margin-top: 6px; }

/* key/value rows (presets, details) */
.kv { display: flex; flex-direction: column; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.kv-row:last-child { border-bottom: 0; }
.kv-row .k { color: var(--muted); white-space: nowrap; }
.kv-row .v { color: var(--text); font-weight: 600; text-align: right; min-width: 0; }

/* media cards (review list) */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 16px; }
.media-card { overflow: hidden; display: flex; flex-direction: column; }
.media-card video, .media-card img.poster { width: 100%; display: block; margin: 0; border-radius: 0; background: #000; max-height: 520px; }
.media-card .media-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.media-card h3 { margin: 0; font-size: var(--fs); font-weight: 650; color: var(--text); line-height: 1.4; }
.media-card .media-note { margin: 0; font-size: var(--fs-xs); color: var(--muted); line-height: 1.5; }
.media-card .media-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 8px; }

/* in old pages: <button> inside the new shell header gets .btn; .panel looks like .card */
body.app main > .panel, body.app main > section.panel { border-radius: var(--r-lg); }
body.app main > .panel > h2:first-child { font-size: var(--fs-md); }
.table td.actions { white-space: normal; min-width: 210px; }
.table td.actions .btn { margin: 2px 0 2px 4px; }
.table td.status-cell { min-width: 150px; }
