/*
 * Local AI Publisher — Professional Operations UI
 * Visual-only override layer. Business markup, IDs and interactions remain intact.
 */

:root,
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-soft: #eef3f8;
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --text: #24324a;
  --text-strong: #0f172a;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --border: #dce4ee;
  --border-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eff6ff;
  --accent-2: #0891b2;
  --good: #059669;
  --good-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --sidebar: #0f1d32;
  --sidebar-soft: #15263e;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .05);
  --shadow-raised: 0 16px 40px rgba(15, 23, 42, .10);
  --radius: 12px;
  --radius-sm: 8px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220;
  --bg-soft: #111b2c;
  --panel: #111c2e;
  --panel-strong: #17243a;
  --text: #d8e1ee;
  --text-strong: #f8fafc;
  --muted: #94a3b8;
  --muted-2: #64748b;
  --border: #25344b;
  --border-strong: #354761;
  --accent: #60a5fa;
  --accent-strong: #93c5fd;
  --accent-soft: rgba(37, 99, 235, .16);
  --accent-2: #22d3ee;
  --good: #34d399;
  --good-soft: rgba(5, 150, 105, .14);
  --warn: #fbbf24;
  --warn-soft: rgba(217, 119, 6, .14);
  --bad: #f87171;
  --bad-soft: rgba(220, 38, 38, .14);
  --sidebar: #07101e;
  --sidebar-soft: #101d31;
  --shadow: 0 1px 2px rgba(0, 0, 0, .16), 0 10px 30px rgba(0, 0, 0, .14);
  --shadow-raised: 0 18px 48px rgba(0, 0, 0, .28);
}

html { min-width: 320px; }

body {
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, "Segoe UI Variable", "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(37, 99, 235, .025), transparent 260px);
}

a, button, input, select, textarea, label { -webkit-tap-highlight-color: transparent; }
a, button, [role="button"], label[for], .publish-entry-option, .upload-button { cursor: pointer; }

:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .34) !important;
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 264px;
  z-index: 1000;
  padding: 10px 14px;
  color: #fff;
  background: #1d4ed8;
  border-radius: 8px;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform .18s ease-out;
}
.skip-link:focus { transform: translateY(0); }

/* Shell */
.sidebar {
  z-index: 60;
  width: 248px;
  padding: 18px 14px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  color: #dbe7f5;
  background: var(--sidebar);
  border-right: 1px solid rgba(148, 163, 184, .12);
  box-shadow: 8px 0 24px rgba(15, 23, 42, .06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 54px;
  margin: 0 2px 18px;
  padding: 6px 8px 12px;
  border-bottom: 1px solid rgba(148, 163, 184, .14);
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  color: #fff;
  background: #2563eb;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 10px;
  box-shadow: 0 8px 18px rgba(37, 99, 235, .28);
  font-size: 16px;
  font-weight: 800;
}

.brand-copy { display: grid; min-width: 0; line-height: 1.2; }
.brand-copy strong { color: #f8fafc; font-size: 15px; font-weight: 700; letter-spacing: .02em; }
.brand-copy small { margin-top: 4px; color: #7185a0; font-size: 9px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }

.nav-section-label {
  margin: 16px 10px 7px;
  color: #627792;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.sidebar > .nav-section-label { margin-top: 4px; }
.sidebar nav > .nav-section-label { margin-top: 18px; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  margin: 2px 0;
  padding: 9px 11px;
  color: #a9b9cc;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  transition: color .18s ease, background-color .18s ease, border-color .18s ease;
}

.sidebar nav a:hover {
  color: #eef6ff;
  background: rgba(148, 163, 184, .09);
  border-color: rgba(148, 163, 184, .08);
  box-shadow: none;
}

.sidebar nav a.active {
  color: #fff;
  background: #1d4ed8;
  border-color: rgba(147, 197, 253, .20);
  box-shadow: 0 7px 18px rgba(29, 78, 216, .23);
}

.nav-icon {
  display: grid;
  place-items: center;
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  color: currentColor;
  position: relative;
  border: 1.5px solid currentColor;
  border-radius: 5px;
  opacity: .82;
}
.nav-icon::before, .nav-icon::after {
  content: "";
  position: absolute;
  background: currentColor;
  opacity: .76;
}
.nav-icon::before { inset: 4px 8px 4px 4px; border-radius: 2px; }
.nav-icon::after { inset: 4px 4px 4px 12px; border-radius: 2px; }

.nav-group { margin: 0; }
.nav-parent::after { right: 13px; }
.nav-submenu {
  margin: 3px 0 7px 20px;
  padding: 2px 0 2px 12px;
  border-left-color: rgba(148, 163, 184, .18);
}
.sidebar .nav-submenu a { min-height: 36px; padding: 7px 10px; color: #8ea2ba; font-size: 12px; }

.main {
  min-width: 0;
  margin-left: 248px;
  padding: 88px clamp(18px, 2.4vw, 36px) 40px;
}

.topbar {
  position: fixed;
  inset: 0 0 auto 248px;
  z-index: 50;
  min-height: 68px;
  padding: 0 clamp(18px, 2.4vw, 36px);
  justify-content: space-between;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .025);
  backdrop-filter: blur(16px);
}

.topbar-context { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-context > div { display: grid; min-width: 0; line-height: 1.2; }
.topbar-context span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.topbar-context strong { margin-top: 4px; overflow: hidden; color: var(--text-strong); font-size: 14px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-toggle { display: none; width: 42px; min-height: 42px; padding: 0; color: var(--text-strong); background: var(--panel); border: 1px solid var(--border); box-shadow: none; }
.sidebar-toggle span, .sidebar-toggle span::before, .sidebar-toggle span::after {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}
.sidebar-toggle span { position: relative; }
.sidebar-toggle span::before, .sidebar-toggle span::after { content: ""; position: absolute; left: 0; }
.sidebar-toggle span::before { top: -6px; }
.sidebar-toggle span::after { top: 6px; }

.account-chip {
  min-height: 40px;
  padding: 4px 11px 4px 5px;
  color: var(--text);
  background: var(--panel);
  border-color: var(--border);
  border-radius: 10px;
}
.account-chip:hover { border-color: #93b4e7; background: var(--accent-soft); }
.account-chip span { width: 30px; height: 30px; background: #1d4ed8; box-shadow: none; font-size: 12px; }
.account-chip em { font-weight: 600; }
.logout-button { min-height: 40px; color: var(--muted); background: transparent; border-color: var(--border); border-radius: 9px; }
.logout-button:hover { color: var(--bad); background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 30%, var(--border)); }

/* Content hierarchy */
.page-head, .hero-head { margin: 0 0 22px; padding: 0 260px 0 0; }
.page-head h1, .hero-head h1 {
  margin: 0 0 6px;
  color: var(--text-strong);
  font-size: clamp(22px, 2vw, 28px);
  font-weight: 750;
  letter-spacing: -.025em;
  line-height: 1.25;
}
.page-head p, .hero-head p { max-width: 900px; color: var(--muted); font-size: 13px; }

.panel, .metric {
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: none;
}
.panel { padding: 18px; margin-bottom: 16px; }
.panel-title {
  margin-bottom: 15px;
  color: var(--text-strong);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -.01em;
}
.panel-title-row { padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.metric { padding: 16px 17px; background: var(--panel); }
.metric span { color: var(--muted); font-size: 12px; font-weight: 600; }
.metric strong { margin-top: 5px; color: var(--text-strong); font-size: 26px; font-variant-numeric: tabular-nums; }

.command-grid, .lower-grid, .workspace { gap: 16px; }
.workspace { grid-template-columns: minmax(350px, .85fr) minmax(0, 1.4fr); }

/* Forms */
label { color: var(--text); font-size: 13px; font-weight: 600; }
input, select, textarea {
  min-height: 42px;
  padding: 10px 12px;
  color: var(--text-strong);
  background: color-mix(in srgb, var(--panel) 92%, var(--bg));
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.45;
  transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}
textarea { min-height: 110px; }
textarea:hover, input:hover, select:hover { border-color: #a7b8cc; }
textarea:focus, input:focus, select:focus {
  border-color: #2563eb;
  background: var(--panel);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea::placeholder, input::placeholder { color: var(--muted-2); }

button, .button, .upload-button {
  min-height: 42px;
  padding: 9px 15px;
  color: #fff;
  background: #2563eb;
  border: 1px solid #2563eb;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.2;
  transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease, transform .12s ease;
}
button:hover, .button:hover, .upload-button:hover { background: #1d4ed8; border-color: #1d4ed8; box-shadow: 0 5px 13px rgba(37, 99, 235, .18); }
button:active, .button:active { transform: translateY(1px); }
button.secondary, .secondary, button.ghost {
  color: var(--text);
  background: var(--panel);
  border-color: var(--border-strong);
  box-shadow: none;
}
button.secondary:hover, .secondary:hover, button.ghost:hover { color: var(--accent-strong); background: var(--accent-soft); border-color: #93b4e7; }
button:disabled { cursor: not-allowed; opacity: .48; box-shadow: none; transform: none; }
.danger-button, button.danger { color: #fff; background: #dc2626; border-color: #dc2626; }

.raw-input { min-height: 330px; }
.actions { flex-wrap: wrap; }
.publish-entry-switch { gap: 8px; }
.publish-entry-option span { min-height: 76px; padding: 12px; background: var(--bg); border-color: var(--border); border-radius: 9px; }
.publish-entry-option small { color: var(--muted); line-height: 1.45; }
.publish-entry-option input:checked + span { color: var(--accent-strong); background: var(--accent-soft); border-color: #6e9ce6; box-shadow: inset 0 0 0 1px rgba(37, 99, 235, .15); }

.notice, .form-alert, .error-box, .result-box {
  padding: 11px 13px;
  color: var(--muted);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.55;
}
.notice.success, .form-alert.success, .result-box.success { color: #047857; background: var(--good-soft); border-color: #a7f3d0; }
.notice.error, .form-alert.error, .error-box { color: #b91c1c; background: var(--bad-soft); border-color: #fecaca; }

/* Tables and status */
.panel:has(> table) { overflow-x: auto; }
table { width: 100%; min-width: 700px; color: var(--text); border-spacing: 0; }
thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 12px;
  color: #52627a;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border-strong);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .04em;
  text-transform: uppercase;
}
tbody td { padding: 11px 12px; color: var(--text); border-bottom: 1px solid var(--border); font-size: 13px; }
tbody tr { transition: background-color .15s ease; }
tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
tbody tr:last-child td { border-bottom: 0; }
pre { color: var(--text); background: var(--bg-soft); border-color: var(--border); border-radius: 8px; }

.status, .badge, [class*="status-badge"] { border-radius: 999px; font-size: 11px; font-weight: 700; }
.filters { gap: 10px; padding: 12px; margin-bottom: 16px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.filters select, .filters input { min-height: 40px; }

/* Dashboard */
.overview-cards { gap: 10px; }
.data-overview .overview-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.overview-cards > div {
  padding: 15px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: none;
}
.overview-cards strong { color: var(--text-strong); font-variant-numeric: tabular-nums; }
.overview-cards span { color: var(--muted); }
.overview-cards em { color: var(--good); font-size: 11px; font-style: normal; }
.scope-card { border-radius: 10px; box-shadow: none; transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.scope-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-raised); }
.agent-line { border-color: var(--border); }
.bot-icon { color: var(--accent); background: var(--accent-soft); }
.task-tabs { gap: 4px; padding: 4px; background: var(--bg-soft); border-radius: 8px; }
.task-tabs span { padding: 7px 10px; color: var(--muted); border-radius: 6px; }
.flow-steps a { background: var(--bg); border-color: var(--border); border-radius: 8px; }
.flow-log { min-height: 160px; }
.architecture { gap: 8px; padding: 15px; background: var(--panel); }
.arch-node { background: var(--bg); border-color: var(--border); border-radius: 9px; }
.arch-arrow { color: var(--muted-2); }

.settings-layout { grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); }
.settings-layout > *, .settings-preview-card, .theme-preview-shell { min-width: 0; max-width: 100%; }

/* Upload and details */
.upload-zone, .upload-card, .media-preview-card, .submission-channel-card, .task-group-card {
  border-color: var(--border);
  background: var(--panel);
  box-shadow: none;
}
.upload-card { border-style: dashed; border-radius: 10px; }
.upload-card:hover { border-color: #8eb1e8; background: var(--accent-soft); }
.detail-entry, .small-link, .link { color: var(--accent-strong); font-weight: 650; }
.detail-entry:hover, .small-link:hover, .link:hover { color: #1e40af; text-decoration: underline; text-underline-offset: 3px; }

/* Login */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 32px;
  background: #eef3f8;
}
.login-body::before {
  background:
    radial-gradient(circle at 15% 15%, rgba(37, 99, 235, .09), transparent 34%),
    radial-gradient(circle at 85% 85%, rgba(8, 145, 178, .08), transparent 32%);
}
.login-shell {
  width: min(1040px, 100%);
  min-height: 610px;
  overflow: hidden;
  background: #fff;
  border: 1px solid #dbe4ef;
  border-radius: 18px;
  box-shadow: 0 28px 70px rgba(15, 23, 42, .13);
}
.login-panel { padding: clamp(34px, 5vw, 66px); color: #24324a; background: #fff; }
.login-product { padding-bottom: 24px; border-bottom: 1px solid #e2e8f0; }
.login-brand-mark { display: grid; place-items: center; color: #fff; background: #1d4ed8; border-radius: 11px; box-shadow: 0 8px 18px rgba(29, 78, 216, .22); }
.login-product span, .login-card-head > span { color: #64748b; letter-spacing: .12em; }
.login-product strong, .login-card-head h1 { color: #0f172a; }
.login-card-head h1 { margin-top: 8px; font-size: 30px; letter-spacing: -.03em; }
.login-card-head p { color: #64748b; }
.login-form label { color: #334155; }
.login-form input { color: #0f172a; background: #f8fafc; border-color: #cbd5e1; }
.login-submit { min-height: 46px; }
.login-form .login-submit { background: #2563eb; border-color: #2563eb; box-shadow: 0 8px 18px rgba(37, 99, 235, .18); }
.login-form .login-submit:hover { background: #1d4ed8; border-color: #1d4ed8; }
.login-footnote { color: #64748b; border-top-color: #e2e8f0; }
.login-showcase {
  position: relative;
  color: #dbeafe;
  background: #0f1d32;
}
.login-showcase::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 80% 10%, rgba(37, 99, 235, .30), transparent 38%);
}
.showcase-head, .showcase-card, .showcase-list { position: relative; }
.showcase-card { background: rgba(15, 30, 52, .82); border-color: rgba(148, 163, 184, .22); border-radius: 14px; box-shadow: 0 20px 40px rgba(0, 0, 0, .18); }
.showcase-title em { color: #6ee7b7; background: rgba(5, 150, 105, .14); border-color: rgba(52, 211, 153, .25); }
.showcase-metrics div, .showcase-list > div { background: rgba(15, 30, 52, .72); border-color: rgba(148, 163, 184, .16); }

/* Responsive */
@media (max-width: 1180px) {
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .workspace { grid-template-columns: 1fr; }
  .raw-input { min-height: 260px; }
}

@media (min-width: 1440px) {
  .main { max-width: 1920px; }
  .command-grid { grid-template-columns: minmax(360px, 1.05fr) minmax(420px, 1.25fr) minmax(290px, .8fr); }
}

@media (max-width: 860px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 55;
    pointer-events: none;
    background: rgba(2, 6, 23, .5);
    opacity: 0;
    transition: opacity .18s ease;
  }
  body.nav-open { overflow: hidden; }
  body.nav-open::after { pointer-events: auto; opacity: 1; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 86vw);
    transform: translateX(-104%);
    transition: transform .22s ease-out;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .main { margin-left: 0; padding: 82px 16px 28px; }
  .topbar { left: 0; min-height: 64px; padding: 0 16px; }
  .sidebar-toggle { display: inline-grid; place-items: center; }
  .page-head, .hero-head { padding-right: 0; }
  .account-chip em { display: none; }
  .account-chip { padding-right: 5px; }
  .logout-button { display: none; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .command-grid, .lower-grid { grid-template-columns: 1fr; }
  html[data-theme] .workspace { width: 100%; grid-template-columns: minmax(0, 1fr); }
  .workspace > *, .panel, .form-grid, .fields-editor, .upload-zone { min-width: 0; max-width: 100%; }
}

@media (max-width: 560px) {
  body { font-size: 13px; }
  .main { padding-inline: 12px; }
  .topbar { padding-inline: 12px; }
  .topbar-context > div { display: none; }
  .panel { padding: 14px; border-radius: 10px; }
  .page-head h1, .hero-head h1 { font-size: 22px; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric { padding: 13px; }
  .metric strong { font-size: 22px; }
  .publish-entry-switch, .form-grid { grid-template-columns: 1fr; }
  html[data-theme] .workspace { gap: 12px; }
  .workspace .panel-title { font-size: 16px; }
  .actions > button { flex: 1 1 calc(50% - 6px); }
  .login-body { padding: 0; background: #fff; }
  .login-shell { min-height: 100vh; border: 0; border-radius: 0; box-shadow: none; }
  .login-showcase { display: none; }
  .login-panel { padding: 30px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
