/* =============================================================
   MCM Stone Tailors — UI
   Software-first: functional, dense, monochrome with warm tones.
   Serif italic reserved for view titles only.
   ============================================================= */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;1,400;1,500&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Surface */
  --bg: #f4f1ea;            /* warm parchment — main app background */
  --surface: #ffffff;       /* cards / panels */
  --surface-2: #faf8f3;     /* subtle alt (zebra, hover) */
  --surface-3: #ece8df;     /* strong tone (header, active row) */
  --sidebar-bg: #1a1916;    /* dark sidebar — strong contrast for nav */
  --sidebar-fg: #e8e4dc;
  --sidebar-muted: #87837a;
  --sidebar-active: #ffffff;

  /* Borders */
  --border: #d8d4ca;
  --border-strong: #a8a397;
  --border-subtle: #e8e4d9;

  /* Text */
  --text: #1a1916;
  --text-2: #3d3a33;
  --muted: #757066;
  --muted-2: #a8a397;

  /* Accents */
  --accent: #1a1916;        /* primary */
  --accent-soft: #3d3a33;
  --accent-hl: #2c5f5a;     /* deep green marble vein */
  --accent-hl-soft: #d4e0de;
  --ok: #2f6b3e;
  --ok-soft: #dce8de;
  --warn: #8a5a00;
  --warn-soft: #f0e3c8;
  --err: #8a1c1c;
  --err-soft: #f0d4d4;
  --highlight: #c19a3e;     /* gold — selected/highlight only */

  /* Type */
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(26, 25, 22, .04);
  --shadow-md: 0 2px 8px rgba(26, 25, 22, .06);
  --shadow-lg: 0 8px 24px rgba(26, 25, 22, .08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html { background: var(--sidebar-bg); }

/* Body gets a 2-column gradient so the dark sidebar band ALWAYS reaches the
   bottom of the page, even when the sticky sidebar content runs out. The
   actual sidebar element sits on top with sticky positioning. */
body {
  display: flex;
  min-height: 100vh;
  background: linear-gradient(to right,
    var(--sidebar-bg) 0,
    var(--sidebar-bg) 220px,
    var(--bg) 220px);
}

a { color: var(--text); text-decoration: none; }
a:hover { color: var(--accent-hl); }

::selection { background: var(--highlight); color: var(--text); }

/* =============== Sidebar (dark, strong contrast) =============== */
.sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  border-right: none;
  display: flex;
  flex-direction: column;
  padding: 22px 0 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand-mini {
  padding: 0 22px 22px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
  line-height: 1;
}
.brand-mini .brand-name {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 4px;
  text-transform: lowercase;
  border: 1px solid var(--sidebar-fg);
  width: 32px; height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  color: var(--sidebar-fg);
}
.brand-mini .brand-sub {
  font-family: var(--sans);
  font-size: 9px;
  color: var(--sidebar-fg);
  text-transform: uppercase;
  letter-spacing: 3px;
  font-weight: 400;
}
.brand-mini .brand-tag {
  margin-top: 6px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 11px;
  color: var(--sidebar-muted);
}
.nav-menu {
  display: flex; flex-direction: column;
  gap: 1px;
  padding: 14px 10px;
  flex: 1;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: transparent;
  border: none;
  color: var(--sidebar-muted);
  text-align: left;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  width: 100%;
  cursor: pointer;
  font-family: var(--sans);
  transition: color .15s, background .15s;
  position: relative;
}
.nav-item:hover {
  background: rgba(255,255,255,.05);
  color: var(--sidebar-fg);
}
.nav-item.active {
  background: rgba(255,255,255,.1);
  color: var(--sidebar-active);
  font-weight: 600;
}
.nav-icon {
  font-size: 11px;
  width: 14px;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  opacity: .55;
}
.nav-label { font-weight: inherit; flex: 1; }

.sidebar-footer {
  padding: 14px 22px 0;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 9px;
  color: var(--sidebar-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
}
.sidebar-footer .user {
  font-family: var(--mono);
  color: var(--sidebar-fg);
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
}
.sidebar-footer .user-block { text-transform: none; letter-spacing: 0; }
.sidebar-footer .user-name {
  color: var(--sidebar-fg);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 2px;
}
.sidebar-footer .user-email {
  color: var(--sidebar-muted);
  font-size: 10px;
  font-family: var(--mono);
  word-break: break-all;
}
.sidebar-footer .logout-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,.15);
  color: var(--sidebar-muted);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 2px;
  padding: 5px 10px;
  cursor: pointer;
  border-radius: 1px;
  width: 100%;
  font-family: inherit;
}
.sidebar-footer .logout-btn:hover {
  border-color: rgba(255,255,255,.3);
  color: var(--sidebar-fg);
}

/* =============== Main =============== */
main.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
main.main > header {
  padding: 12px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(244, 241, 234, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
}
main.main > header h1 {
  margin: 0;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--text);
}
main.main > header h1::before {
  content: "—";
  margin-right: 10px;
  color: var(--muted-2);
}
.meta { color: var(--muted); font-size: 11px; text-align: right; letter-spacing: .3px; }
.meta .ok { color: var(--ok); }
.meta .muted { color: var(--muted); }

.view {
  display: none;
  padding: 24px 28px 60px;
  flex: 1;
  max-width: 1480px;
  width: 100%;
}
.view.active { display: block; }

.view-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 24px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.view-title {
  display: flex; flex-direction: column; gap: 2px;
}
.view-title .eyebrow {
  font-size: 10px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}
.view-title h2 {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 28px;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -.4px;
}
.view-header h2 {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 24px;
  color: var(--text);
}
.actions-right {
  display: flex; gap: 8px; align-items: center; flex-wrap: nowrap;
}
.actions-right input[type=text] { width: 280px; }

/* =============== Tabs =============== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
}
.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  padding: 9px 16px 11px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-family: var(--sans);
  cursor: pointer;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: transparent;
  color: var(--text);
  border-bottom-color: var(--text);
}

.cat-tab { display: block; }
.cat-tab.hidden { display: none !important; }

/* =============== Cards / Lists =============== */
.catalog-list, .history-list, .phc-list {
  display: flex; flex-direction: column;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.cat-card, .hist-card, .phc-card {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 18px;
  background: var(--surface);
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  border-radius: 0;
  transition: background .12s;
}
.cat-card:last-child, .hist-card:last-child, .phc-card:last-child { border-bottom: none; }
.cat-card:hover, .hist-card:hover, .phc-card:hover { background: var(--surface-2); }
.cat-card.unmapped { border-left: 2px solid var(--warn); }
.cat-card.balcao { border-left: 2px solid var(--ok); }

.cc-main, .hc-main, .phc-info {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 3px;
}
.cc-sku, .pc-sku, .hc-project {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
  letter-spacing: .2px;
}
.cc-desc, .pc-desc {
  font-size: 13px;
  color: var(--text);
}
.cc-meta, .pc-meta, .hc-meta {
  font-size: 11px;
  color: var(--muted);
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: center;
}
.hc-time {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  min-width: 100px;
  font-family: var(--mono);
}
.cc-actions, .hc-actions, .pc-actions {
  display: flex; gap: 6px; flex-shrink: 0;
}

/* =============== Chips =============== */
.chip {
  display: inline-block;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 2px 8px;
  border-radius: 2px;
  font-size: 10px;
  font-family: var(--mono);
  letter-spacing: .3px;
  font-weight: 500;
}
.chip.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.chip.muted { background: transparent; border-color: var(--border); color: var(--muted); }

/* =============== Dashboard =============== */
.dashboard-filters {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
  padding: 14px 18px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.dashboard-filters .filter-group {
  display: flex; align-items: center; gap: 8px;
}
.dashboard-filters .filter-label {
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.period-tabs {
  display: flex;
  gap: 0;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  overflow: hidden;
}
.period-tabs button {
  background: var(--surface);
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  padding: 6px 12px;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--muted);
  font-family: var(--sans);
  text-transform: uppercase;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.period-tabs button:last-child { border-right: none; }
.period-tabs button:hover { background: var(--surface-2); color: var(--text); }
.period-tabs button.active {
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
}

.filter-note {
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  font-family: var(--serif);
  margin-left: auto;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .kpi-grid { grid-template-columns: 1fr; } }

.kpi {
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: border-color .12s, box-shadow .12s;
}
.kpi:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.kpi-label {
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.kpi-value {
  font-family: var(--sans);
  font-style: normal;
  font-weight: 600;
  font-size: 26px;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -.5px;
  font-variant-numeric: tabular-nums;
}
.kpi-unit {
  font-family: var(--sans);
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
  margin-left: 6px;
  font-weight: 500;
  letter-spacing: .5px;
}
.kpi-delta {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .2px;
}
.kpi-delta strong { color: var(--text); font-weight: 600; }
.kpi-delta.zero { color: var(--muted-2); }

.dashboard-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.dashboard-row-3 {
  grid-template-columns: 1fr 1fr 1.2fr;
}
@media (max-width: 1100px) {
  .dashboard-row, .dashboard-row-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 700px) {
  .dashboard-row, .dashboard-row-3 { grid-template-columns: 1fr; }
}

.dashboard-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 18px 22px;
  box-shadow: var(--shadow-sm);
}
.dashboard-card h3 {
  margin: 0 0 14px;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 17px;
  letter-spacing: -.2px;
  line-height: 1.2;
}
.dashboard-card .small-eyebrow {
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 600;
}

/* Bar chart for monthly */
.month-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 180px;
  border-bottom: 1px solid var(--border);
  padding: 12px 0 0;
  position: relative;
}
.month-chart::before {
  content: "";
  position: absolute;
  left: 0; right: 0;
  top: 0; bottom: 0;
  background-image: linear-gradient(0deg, transparent 0%, transparent 24%, var(--border-subtle) 24%, var(--border-subtle) 25%, transparent 25%, transparent 49%, var(--border-subtle) 49%, var(--border-subtle) 50%, transparent 50%, transparent 74%, var(--border-subtle) 74%, var(--border-subtle) 75%, transparent 75%);
  pointer-events: none;
  z-index: 0;
}
.month-chart .month-bar {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center;
  position: relative;
  z-index: 1;
}
.month-chart .month-bar .bar {
  width: 100%;
  background: var(--text);
  transition: background .15s;
  min-height: 2px;
  border-top: 2px solid var(--accent-hl);
}
.month-chart .month-bar:hover .bar { background: var(--accent-hl); }
.month-chart .month-bar .bar.empty {
  background: var(--border);
  border-top: none;
  min-height: 2px;
}
.month-chart .month-bar .val {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}
.month-chart .month-bar .lbl {
  font-size: 9px;
  color: var(--muted);
  margin-top: 6px;
  letter-spacing: .8px;
  text-transform: uppercase;
  text-align: center;
  font-weight: 500;
}

/* Top stones / clients */
.breakdown-list { display: flex; flex-direction: column; gap: 10px; }
.breakdown-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  font-size: 12px;
  align-items: baseline;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}
.breakdown-row:last-child { border-bottom: none; padding-bottom: 0; }
.breakdown-row .br-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text);
  letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.breakdown-row .br-label-text {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
}
.breakdown-row .br-value {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  text-align: right;
  min-width: 60px;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  justify-content: flex-end;
  white-space: nowrap;
}
.breakdown-row .br-unit {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 600;
}
.breakdown-row .br-bar {
  grid-column: 1 / -1;
  height: 3px;
  background: var(--border-subtle);
  position: relative;
  margin-top: 4px;
  border-radius: 2px;
  overflow: hidden;
}
.breakdown-row .br-bar::before {
  content: "";
  position: absolute; top: 0; left: 0; height: 3px;
  background: var(--accent-hl);
  width: var(--w, 0%);
  transition: width .3s;
}

.dashboard-empty {
  padding: 50px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  font-family: var(--sans);
  font-style: normal;
}
.dashboard-empty em {
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  color: var(--text);
  display: block;
  margin-bottom: 6px;
}

.recent-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.recent-table thead { display: none; }
.recent-table tr { border-bottom: 1px solid var(--border-subtle); }
.recent-table tr:last-child { border-bottom: none; }
.recent-table td {
  padding: 10px 8px;
  vertical-align: middle;
  border: none;
  font-size: 12px;
}
.recent-table td:first-child { padding-left: 0; }
.recent-table td:last-child { padding-right: 0; text-align: right; }
.recent-table .r-time {
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  white-space: nowrap;
  width: 90px;
  font-family: var(--mono);
}
.recent-table .r-project { font-weight: 600; color: var(--text); font-size: 12px; }
.recent-table .r-client { color: var(--muted); font-size: 11px; }
.recent-table .r-sku { font-family: var(--mono); font-size: 10px; color: var(--text); }
.recent-table .r-num {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.recent-table .r-num-wrap {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  white-space: nowrap;
}
.recent-table .r-num-wrap .unit {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 600;
}

/* =============== Stat (history view) =============== */
.hist-stats {
  display: flex; gap: 0; flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.stat {
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px 20px;
  border-right: 1px solid var(--border-subtle);
  min-width: 130px;
}
.stat:last-child { border-right: none; }
.stat-num {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 22px;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-lbl {
  font-size: 9px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 2px;
  font-weight: 600;
}

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
}

/* =============== View hints (texto explicativo no topo de vistas) ============ */
.view-hint {
  background: var(--surface);
  border-left: 3px solid var(--accent, #4a6a45);
  padding: 12px 16px;
  margin-bottom: 22px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text);
}
.view-hint strong { color: var(--text); font-weight: 600; }

/* =============== Modal hint =============== */
.modal-hint {
  background: var(--surface);
  border-left: 3px solid var(--accent, #4a6a45);
  padding: 10px 14px;
  margin: 0 0 16px 0;
  font-size: 12px;
  color: var(--text);
  line-height: 1.5;
}
.modal-hint strong { font-weight: 600; }
.hint-inline {
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  font-weight: normal;
}
.hint-text {
  font-size: 11.5px;
  color: var(--muted);
  font-style: italic;
  margin: 8px 0 0 0;
  line-height: 1.55;
}
.hint-text code {
  font-family: var(--mono);
  font-size: 10.5px;
  background: var(--surface);
  padding: 1px 5px;
  border-radius: 2px;
  font-style: normal;
}

/* =============== User chip (activity tracking) =============== */
.user-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* =============== PHC pager =============== */
.phc-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 18px 0;
  margin-top: 12px;
  border-top: 1px solid var(--border);
}
.phc-pager button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.phc-page-info {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-family: var(--mono);
}

/* =============== Advanced section (collapsed) =============== */
.adv-section {
  margin: 14px 0 4px 0;
  font-size: 12px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.adv-section summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 6px 0;
}
.adv-section summary:hover { color: var(--text); }
.adv-section[open] summary { color: var(--text); margin-bottom: 8px; }

/* =============== Forms =============== */
.form-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 18px;
}
.form-actions button.danger { margin-right: auto; }

select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 7px 12px;
  border-radius: 3px;
  font-size: 12px;
  font-family: var(--sans);
  letter-spacing: .2px;
  min-width: 160px;
  cursor: pointer;
}
select:hover { border-color: var(--text); }
select:focus { outline: none; border-color: var(--accent-hl); box-shadow: 0 0 0 2px var(--accent-hl-soft); }

input[type=text], input[type=number] {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 7px 10px;
  border-radius: 3px;
  font-size: 13px;
  width: 100%;
  font-family: var(--sans);
}
input[type=text]:hover, input[type=number]:hover { border-color: var(--muted); }
input[type=text]:focus, input[type=number]:focus {
  outline: none;
  border-color: var(--accent-hl);
  box-shadow: 0 0 0 2px var(--accent-hl-soft);
}
input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }

.hidden { display: none !important; }

/* =============== Dropzone =============== */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: 4px;
  padding: 60px 40px;
  text-align: center;
  background: var(--surface);
  transition: border-color .15s, background .15s;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.dropzone:hover {
  border-color: var(--accent-hl);
  background: var(--surface);
}
.dropzone.dragging {
  border-color: var(--accent-hl);
  background: var(--accent-hl-soft);
}
.dropzone p { margin: 6px 0; }
.dropzone p strong {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 22px;
  color: var(--text);
}
.dropzone .hint {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 16px;
  font-weight: 500;
}

/* =============== Buttons =============== */
button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 7px 12px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  font-family: var(--sans);
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 600;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
button:hover {
  background: var(--surface-3);
  border-color: var(--text);
}
button:active { box-shadow: inset 0 1px 2px rgba(0,0,0,.08); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
button.primary:hover {
  background: var(--accent-hl);
  border-color: var(--accent-hl);
}
button.danger {
  background: transparent;
  color: var(--err);
  border-color: var(--err);
}
button.danger:hover { background: var(--err); color: var(--surface); }
button.mini {
  padding: 4px 9px;
  font-size: 10px;
  letter-spacing: .8px;
}

a.mini {
  display: inline-block;
  padding: 4px 9px;
  font-size: 10px;
  letter-spacing: .8px;
  text-transform: uppercase;
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-weight: 600;
  border-radius: 3px;
  background: var(--surface);
}
a.mini:hover {
  background: var(--text);
  color: var(--bg);
  text-decoration: none;
  border-color: var(--text);
}

.status {
  color: var(--muted);
  padding: 24px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  text-align: center;
}

/* =============== Review Layout =============== */
.review-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(400px, 1fr);
  gap: 16px;
}
.review-grid.preview-hidden { grid-template-columns: 1fr; }
.review-grid.preview-hidden .right-col { display: none; }
@media (max-width: 1200px) { .review-grid { grid-template-columns: 1fr; } }
#togglePreviewBtn.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.toolbar .info { display: flex; gap: 10px; align-items: center; flex-wrap: nowrap; }
.toolbar .info label {
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-weight: 600;
  min-width: 90px;
}
.toolbar .info input { flex: 1; min-width: 0; }
.toolbar .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* =============== Warnings =============== */
.warnings { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.warnings .w {
  padding: 9px 14px;
  background: var(--warn-soft);
  border-left: 3px solid var(--warn);
  color: var(--text);
  font-size: 12px;
  font-family: var(--sans);
  letter-spacing: .2px;
}

/* =============== Annotations =============== */
.annotations-panel {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 0;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
@media (max-width: 900px) { .annotations-panel { grid-template-columns: 1fr; } }
.annotations-panel .ap-section {
  background: var(--surface);
  border-right: 1px solid var(--border-subtle);
  padding: 14px 18px;
}
.annotations-panel .ap-section:last-child { border-right: none; }
.annotations-panel .ap-section:empty { display: none; }
.ap-section h4 {
  margin: 0 0 10px;
  font-size: 9px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 2px;
}
.ap-section .ap-list {
  max-height: 180px; overflow-y: auto;
  font-size: 12px;
}
.ap-section .ap-item {
  padding: 5px 0;
  border-bottom: 1px solid var(--border-subtle);
  line-height: 1.5;
}
.ap-section .ap-item:last-child { border-bottom: none; }
.ap-section .ap-item strong { color: var(--text); font-family: var(--mono); font-size: 11px; }

/* =============== Issues =============== */
.issues-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.issues-panel h3 {
  margin: 0 0 10px;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 16px;
}
.issue-row {
  display: flex; gap: 10px; align-items: center;
  padding: 6px 10px; margin: 3px 0;
  font-size: 12px;
  background: transparent;
  border-left: 3px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}
.issue-row:hover { background: var(--surface-2); }
.issue-row.severity-error { border-left-color: var(--err); background: var(--err-soft); color: var(--err); }
.issue-row.severity-warn { border-left-color: var(--warn); background: var(--warn-soft); color: var(--text); }
.issue-row.severity-info { border-left-color: var(--muted); color: var(--muted); }
.issue-severity { font-weight: 700; text-transform: uppercase; font-size: 9px; letter-spacing: 1px; min-width: 50px; }

/* =============== Project Banner =============== */
.project-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 18px 22px;
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: minmax(260px, 2fr) 3fr;
  gap: 24px;
  align-items: start;
  box-shadow: var(--shadow-sm);
}
.project-banner .pb-main .pb-title {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
}
.pb-project {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 24px;
  color: var(--text);
  line-height: 1.1;
}
.pb-badge {
  background: var(--text);
  color: var(--surface);
  border: 1px solid var(--text);
  padding: 3px 9px;
  font-size: 10px;
  font-weight: 600;
  font-family: var(--mono);
  letter-spacing: .5px;
  border-radius: 2px;
}
.pb-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}
.pb-sep { margin: 0 8px; opacity: .5; }
.pb-fields {
  display: grid; grid-template-columns: auto 1fr auto 1fr;
  gap: 6px 16px; font-size: 12px; align-self: center;
}
.pb-fields .k {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-size: 9px;
  font-weight: 600;
}
.pb-fields .v { color: var(--text); font-family: var(--mono); font-size: 11px; }
.pb-fields .v.empty { color: var(--muted-2); font-family: var(--serif); font-style: italic; }
.pb-stones {
  grid-column: 1 / -1;
  display: flex; flex-wrap: wrap; gap: 6px;
  padding-top: 14px; border-top: 1px solid var(--border-subtle);
}
.pb-stones .stone-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 3px 9px;
  font-size: 10px;
  font-family: var(--mono);
  letter-spacing: .2px;
  border-radius: 2px;
}
.pb-stones .stone-chip.unmapped {
  background: var(--warn-soft);
  border-color: var(--warn);
  color: var(--warn);
}
.pb-stones .stone-chip .src { color: var(--muted); font-size: 9px; }
.pb-stones .stone-chip .resolve-unmapped {
  background: transparent;
  border: 1px solid var(--warn);
  color: var(--warn);
  padding: 2px 7px;
  font-size: 9px;
  margin-left: 4px;
  text-transform: uppercase;
  letter-spacing: .8px;
}
.pb-stones .stone-chip .resolve-unmapped:hover {
  background: var(--warn);
  color: var(--surface);
}

/* =============== Unmapped banner =============== */
.unmapped-banner {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 18px;
  margin-bottom: 18px;
  background: var(--warn-soft);
  border-left: 4px solid var(--warn);
  border-radius: 2px;
}
.unmapped-banner .ub-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--warn);
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.unmapped-banner .ub-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--warn);
  margin-bottom: 3px;
}
.unmapped-banner .ub-sub {
  font-size: 12px;
  color: var(--text);
  margin-bottom: 8px;
}
.unmapped-banner .ub-list {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text);
}
.unmapped-banner .ub-list li {
  margin-bottom: 4px;
  cursor: pointer;
  text-decoration: underline dotted;
}
.unmapped-banner .ub-list li:hover { color: var(--warn); }

/* =============== Totals bar =============== */
.totals-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  padding: 0;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.totals-item {
  display: flex; flex-direction: column; gap: 4px;
  padding: 12px 18px;
  border-right: 1px solid var(--border-subtle);
}
.totals-item:last-child { border-right: none; }
.totals-item .totals-label {
  color: var(--muted);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}
.totals-item span:not(.totals-label) {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 18px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
@media (max-width: 800px) {
  .totals-bar { grid-template-columns: repeat(2, 1fr); }
  .totals-item:nth-child(2n) { border-right: none; }
}

/* =============== Stones found =============== */
.stones-found {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 12px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.stones-found h3 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 15px;
}
.stone-pill {
  display: inline-block;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 3px 10px;
  font-size: 11px;
  font-family: var(--mono);
  margin: 2px;
  border-radius: 2px;
}

/* =============== Tables =============== */
.tables { display: flex; flex-direction: column; gap: 22px; }
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%; border-collapse: collapse;
  background: var(--surface);
  border: none;
  border-radius: 0;
}
thead tr {
  background: var(--surface-3);
  border-bottom: 1px solid var(--border-strong);
}
th, td {
  padding: 8px 10px; text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12px;
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-weight: 700;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  white-space: nowrap;
  padding: 9px 10px;
}
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.selected { background: rgba(193, 154, 62, .08); border-left: 2px solid var(--highlight); }
tbody tr.has-issue td:first-child { border-left: 3px solid var(--warn); }
tbody tr:last-child td { border-bottom: none; }

td input {
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  padding: 4px 6px; width: 100%; min-width: 0;
  font-size: 12px;
  font-family: var(--sans);
  border-radius: 2px;
}
td input:hover { border-color: var(--border); background: var(--surface-2); }
td input:focus {
  background: var(--surface);
  border-color: var(--accent-hl);
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-hl-soft);
}
td input[type=number] { font-variant-numeric: tabular-nums; }
td.idx { color: var(--muted); font-variant-numeric: tabular-nums; font-family: var(--mono); }
td.zone {
  color: var(--text);
  font-size: 10px;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}
td.ref .ref-chip {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 1px 7px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .2px;
  border-radius: 2px;
}
td.ref .muted { color: var(--muted-2); font-size: 11px; font-family: var(--serif); font-style: italic; }

tr.zone-header td {
  background: var(--surface-3);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 11px;
}
tr.zone-header .zone-name {
  color: var(--text);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-size: 10px;
}
tr.zone-header .zone-count { color: var(--muted); margin-left: 12px; font-size: 10px; }
tr.zone-header .zone-total {
  float: right;
  color: var(--text);
  font-family: var(--sans);
  font-weight: 600;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.table-controls { margin-left: auto; font-weight: 400; font-size: 11px; }
.table-controls .toggle { color: var(--muted); }

h2 {
  margin: 0 0 10px;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 20px;
  display: flex; align-items: baseline; gap: 12px;
}
h3 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 15px;
}
.count {
  color: var(--muted);
  font-family: var(--mono);
  font-style: normal;
  font-weight: 500;
  font-size: 11px;
  letter-spacing: .3px;
}

.row-remove { color: var(--muted-2); cursor: pointer; font-size: 16px; padding: 0 6px; user-select: none; }
.row-remove:hover { color: var(--err); }
.row-swap { color: var(--muted-2); cursor: pointer; font-size: 14px; padding: 0 4px; user-select: none; margin-right: 2px; }
.row-swap:hover { color: var(--accent-hl); }

details {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
}
details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  user-select: none;
  font-weight: 600;
}
details[open] summary { margin-bottom: 10px; }

#diag {
  font-size: 11px;
  color: var(--muted);
}
#diag dl { margin: 0; display: grid; grid-template-columns: 160px 1fr; gap: 4px 12px; }
#diag dt { color: var(--muted); }
#diag dd { margin: 0; color: var(--text); font-family: var(--mono); font-size: 11px; word-break: break-all; }
#diag .raw { margin-top: 12px; max-height: 80px; overflow: auto; font-family: var(--mono); font-size: 10px; }

/* =============== Right column (preview) =============== */
.right-col {
  position: sticky; top: 80px;
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px 16px;
  height: calc(100vh - 110px);
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-sm);
}
.preview-header { display: flex; justify-content: space-between; align-items: baseline; }
.preview-header h3 { margin: 0; }
.preview-controls { display: flex; gap: 8px; align-items: center; }
.toggle {
  font-size: 10px;
  color: var(--muted);
  display: flex;
  gap: 4px;
  align-items: center;
  cursor: pointer;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 500;
}
.preview-wrap {
  flex: 1;
  background: var(--surface-3);
  border: 1px solid var(--border);
  margin: 10px 0 6px;
  overflow: hidden;
  position: relative;
}
#preview { width: 100%; height: 100%; display: block; cursor: grab; }
#preview:active { cursor: grabbing; }
.preview-legend {
  font-size: 9px;
  color: var(--muted);
  display: flex;
  gap: 14px;
  padding: 4px 2px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 500;
}
.lg { display: inline-block; width: 8px; height: 8px; margin-right: 4px; vertical-align: middle; border-radius: 1px; }
.lg-piece { background: var(--text); }
.lg-context { background: var(--muted-2); }
.lg-selected { background: var(--highlight); }

/* =============== Modals =============== */
.modal {
  position: fixed; inset: 0;
  background: rgba(26, 25, 22, .35);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  width: 100%; max-width: 720px;
  max-height: 85vh; overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  border-radius: 4px;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-3);
}
.modal-header h2 {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 22px;
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  padding: 0 6px;
  letter-spacing: 0;
}
.modal-close:hover { color: var(--text); background: transparent; }
.modal-body { padding: 18px 24px; overflow-y: auto; }
.catalog-search input { margin-bottom: 12px; }
.form-grid {
  display: grid; grid-template-columns: 160px 1fr;
  gap: 8px 12px; align-items: center;
  margin-top: 12px;
}
.form-grid label {
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-weight: 600;
}
.catalog-item {
  padding: 9px 12px;
  border: 1px solid var(--border);
  margin: 4px 0;
  cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px;
  background: var(--surface);
  border-radius: 2px;
}
.catalog-item:hover { background: var(--surface-2); }
.catalog-item strong { color: var(--text); font-family: var(--mono); font-size: 11px; }

/* =============== Misc =============== */
.muted { color: var(--muted); }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
