:root {
  --bg: #0a0c0f;
  --panel: #111418;
  --panel-2: #171b20;
  --border: #272d34;
  --text: #f3f5f7;
  --muted: #9aa3ad;
  --accent: #e6ebf0;
  --danger: #ff6b6b;
  --ok: #69d49d;
  --warn: #f2c66d;
  --radius: 16px;
}
* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  background: radial-gradient(circle at top, #151920 0, var(--bg) 38rem);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, .button {
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--accent);
  color: #0c0e11;
  padding: 10px 14px;
  font-weight: 750;
  cursor: pointer;
}
.button.secondary, button.secondary { background: var(--panel-2); color: var(--text); }
.button.danger, button.danger { background: transparent; border-color: #6a3131; color: #ffb3b3; }
button:disabled { opacity: .55; cursor: not-allowed; }
a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
.shell { width: min(1180px, calc(100% - 28px)); margin: 0 auto; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(18px);
  background: rgba(10,12,15,.82);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.topbar-inner { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; min-height: 70px; }
.brand { display: flex; flex: 0 1 auto; align-items: center; gap: 10px; min-width: 0; min-height: 44px; font-weight: 900; letter-spacing: .2px; }
.brand img { width: 34px; height: 34px; }
.nav { display: flex; flex: 1 1 20rem; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  max-width: 100%;
  color: var(--muted);
  padding: 9px 11px;
  border-radius: 10px;
  overflow-wrap: anywhere;
}
.nav a:hover, .nav a.active, .nav a[aria-current="page"] { color: var(--text); background: var(--panel-2); }
.userbox {
  display: flex;
  flex: 0 1 auto;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  max-width: 100%;
  margin-left: auto;
  color: var(--muted);
}
.utility-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; }
.userbox button { min-height: 44px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--panel-2); object-fit: cover; }
main { padding: 28px 0 60px; }
.hero { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.hero h1 { margin: 0; font-size: clamp(1.6rem, 4vw, 2.35rem); letter-spacing: -.04em; }
.hero p { margin: 7px 0 0; color: var(--muted); }
.page-context {
  max-width: 76ch;
  line-height: 1.5;
}
.help-term, .field-label-row {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.field-label-row {
  color: var(--muted);
  font-size: .83rem;
}
.field-label-row label { display: inline; color: inherit; font: inherit; }
.form-field { display: grid; gap: 7px; min-width: 0; }
.inline-help {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  text-align: left;
  text-transform: none;
  letter-spacing: normal;
}
button.inline-help-trigger {
  display: inline-grid;
  place-items: center;
  width: 25px;
  height: 25px;
  min-width: 25px;
  min-height: 25px;
  padding: 0;
  border: 1px solid #4a535e;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--text);
  font-size: .76rem;
  font-weight: 900;
  line-height: 1;
}
button.inline-help-trigger:hover { border-color: #7d8996; background: #222830; }
.inline-help-tooltip {
  position: absolute;
  z-index: 60;
  left: 50%;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: min(18rem, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 9px 11px;
  border: 1px solid #46505b;
  border-radius: 9px;
  background: #080a0d;
  box-shadow: 0 12px 28px rgba(0,0,0,.42);
  color: var(--text);
  font-size: .8rem;
  font-weight: 600;
  line-height: 1.4;
  overflow: auto;
  overflow-wrap: anywhere;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 3px);
  transition: opacity .12s ease, transform .12s ease, visibility .12s ease;
}
html:not(.help-js) .inline-help:hover .inline-help-tooltip,
html:not(.help-js) .inline-help:focus-within .inline-help-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}
.help-js .inline-help-tooltip {
  position: fixed;
  left: 0;
  top: 0;
  bottom: auto;
  transform: translateY(3px);
}
.help-js .inline-help-trigger[aria-expanded="true"] + .inline-help-tooltip[data-positioned="true"] {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.inline-help-guide {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  margin-top: 8px;
}
.inline-help-guide .help-term { color: var(--muted); font-size: .8rem; }
.action-with-help { display: inline-flex; align-items: center; gap: 6px; }
@media (prefers-reduced-motion: reduce) {
  .inline-help-tooltip { transition: none; }
}
.grid { display: grid; gap: 14px; }
.grid.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: 1.1fr .9fr; }
.card {
  background: linear-gradient(180deg, rgba(255,255,255,.025), rgba(255,255,255,0)), var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 12px 28px rgba(0,0,0,.18);
}
.stat-label { color: var(--muted); font-size: .86rem; }
.stat-value { font-size: clamp(1.25rem, 3vw, 2rem); font-weight: 900; margin-top: 7px; letter-spacing: -.03em; }
.stat-sub { color: var(--muted); margin-top: 5px; font-size: .83rem; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 0 0 14px; }
.section-title h2, .section-title h3 { margin: 0; font-size: 1.05rem; }
.muted { color: var(--muted); }
.good { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--danger); }
.table-wrap { overflow-x: auto; border-radius: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: .77rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 800; }
tbody tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--panel-2); padding: 5px 8px; border-radius: 999px; font-size: .78rem; }
.badge.low { border-color: #654f20; color: #f7d786; }
.badge.role { text-transform: capitalize; }
form.stack { display: grid; gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: .83rem; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #0d1014;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 11px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #65707d; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid #8995a3;
  outline-offset: 2px;
}
textarea { min-height: 92px; resize: vertical; }
.actions { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.notice { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--panel-2); margin-bottom: 16px; }
.notice.ok { border-color: #315845; }
.notice.error { border-color: #6a3131; }
.notice.warn { border-color: #655520; }
.empty { text-align: center; padding: 30px 14px; color: var(--muted); }
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card { width: min(520px, 100%); text-align: center; padding: 34px; }
.login-card img { width: 92px; height: 92px; margin-bottom: 16px; }
.login-card h1 { margin: 0; font-size: 2rem; }
.login-card p { color: var(--muted); line-height: 1.55; }
.discord-button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; margin-top: 12px; }
.codebox { background: #0b0e12; border: 1px solid var(--border); border-radius: 10px; padding: 12px; overflow-x: auto; color: #d8dee7; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .83rem; white-space: pre-wrap; }
.kpi-line { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.kpi-line:last-child { border-bottom: 0; }
.footer { color: var(--muted); text-align: center; font-size: .78rem; padding: 22px 0 0; }
.spacer-12 { height: 12px; }
.spacer-14 { height: 14px; }

.history-filters { display: grid; gap: 12px; }
.history-filter-grid {
  display: grid;
  grid-template-columns: minmax(10rem, 1.35fr) repeat(2, minmax(9rem, 1fr)) repeat(2, minmax(8.5rem, .9fr));
  gap: 12px;
}
.history-pagination {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}
.history-pagination > :first-child { justify-self: start; }
.history-pagination > :nth-child(2) { text-align: center; }
.history-pagination > :last-child { justify-self: end; }

.audit-log table { min-width: 900px; }
.audit-log th:last-child, .audit-log td:last-child { width: 40%; }
.analytics-page { display: grid; gap: 22px; }
.analytics-page > * { min-width: 0; }
.analytics-hero { margin-bottom: -4px; }
.analytics-periods { display: flex; flex-wrap: wrap; gap: 8px; }
.analytics-period { min-height: 42px; }
.analytics-period.active, .analytics-period[aria-current="page"] {
  border-color: #7d8996;
  background: var(--accent);
  color: #0c0e11;
}
.grid.stats.analytics-economy-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.analytics-economy-stats > .card, .analytics-page .grid.stats > .card { min-width: 0; }
.analytics-status-value { margin-top: 7px; font-size: 1.05rem; font-weight: 900; }
.analytics-rankings { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.analytics-ranking { min-width: 0; padding: 14px; }
.analytics-ranking table { min-width: 360px; }
.analytics-ranking th, .analytics-ranking td { padding: 10px 7px; }
.analytics-items table { min-width: 1280px; }
.audit-details summary { cursor: pointer; font-weight: 800; }
.audit-details[open] summary { margin-bottom: 8px; }
.audit-changes { display: grid; gap: 8px; margin: 0; padding-left: 18px; }
.audit-changes li { display: flex; flex-wrap: wrap; gap: 4px 7px; overflow-wrap: anywhere; white-space: pre-wrap; }
.audit-field { color: var(--muted); font-weight: 800; }

.inventory-danger {
  display: grid;
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid #6a3131;
}
.inventory-stock {
  display: grid;
  gap: 14px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.inventory-stock .section-title { margin-bottom: 0; }
.inventory-stock-status { color: var(--muted); }
.inventory-stock-status strong { color: var(--text); font-size: 1.08rem; }
.inventory-stock-form { max-width: 720px; }
.inventory-empty-stock {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.inventory-empty-stock p, .inventory-stock-empty { margin: 0; }
.inventory-empty-stock form { margin: 0; }
.inventory-danger h3, .inventory-danger p { margin: 0; }
.inventory-archived { margin-top: 18px; }
.inventory-archived > summary {
  min-height: 44px;
  padding: 3px 0;
  cursor: pointer;
  font-weight: 850;
}
.inventory-archived[open] > summary { margin-bottom: 12px; }
.inventory-archived > p { margin: 0 0 14px; line-height: 1.5; }
.inventory-archived table { min-width: 620px; }
.inventory-archived form { margin: 0; }

/* Smart Entry follows the shared card, notice, action and dark-form language. */
.smart-entry-page { display: grid; gap: 16px; }
.smart-entry-compose { display: grid; gap: 14px; }
input.smart-entry-input {
  min-height: 58px;
  padding: 14px 15px;
  font-size: 1.05rem;
  line-height: 1.5;
}
.smart-entry-examples { display: flex; flex-wrap: wrap; gap: 8px; }
.smart-entry-example {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #0d1014;
  color: var(--muted);
  padding: 7px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem;
}
.smart-entry-preview, .smart-entry-receipt { display: grid; gap: 14px; }
.smart-entry-effects {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.smart-entry-effect {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-2);
  padding: 12px 14px;
}
.smart-entry-effect-label { color: var(--muted); font-size: .78rem; }
.smart-entry-effect-value { margin-top: 5px; font-size: 1rem; font-weight: 800; }
.smart-entry-change {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}
.smart-entry-change > :last-child { text-align: right; }
.smart-entry-arrow { color: var(--muted); font-weight: 800; }
@media (max-width: 900px) {
  .grid.stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid.two { grid-template-columns: 1fr; }
  .topbar-inner { padding: 10px 0; gap: 10px; }
  .nav { order: 3; flex: 1 0 100%; width: auto; }
  .userbox .username { display: none; }
  .history-filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analytics-rankings { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .shell { width: min(100% - 18px, 1180px); }
  main { padding-top: 18px; }
  .grid.stats { grid-template-columns: 1fr 1fr; gap: 9px; }
  .card { padding: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .hero { align-items: flex-start; flex-direction: column; }
  .nav { gap: 5px; }
  .nav a { flex: 1 1 auto; padding-inline: 10px; }
  .inline-help-tooltip { max-width: calc(100vw - 18px); }
  .smart-entry-effects { grid-template-columns: 1fr; }
  .smart-entry-change { grid-template-columns: 1fr; }
  .smart-entry-change > :last-child { text-align: left; }
  .smart-entry-arrow { transform: rotate(90deg); transform-origin: left center; }
  .history-filter-grid { grid-template-columns: 1fr; }
  .history-pagination { grid-template-columns: 1fr 1fr; }
  .history-pagination > :nth-child(2) { grid-column: 1 / -1; grid-row: 1; }
  .history-pagination > :first-child { grid-column: 1; grid-row: 2; }
  .history-pagination > :last-child { grid-column: 2; grid-row: 2; }
  .analytics-page { gap: 16px; }
  .grid.stats.analytics-economy-stats { grid-template-columns: 1fr 1fr; }
  .analytics-period { flex: 1 1 calc(50% - 8px); text-align: center; }
}

/* Dashboard balance and layout */
.dashboard-page {
  display: grid;
  gap: 16px;
}
.dashboard-page > * { min-width: 0; }
.dashboard-hero {
  align-items: center;
  margin-bottom: 4px;
  min-height: 58px;
}
.dashboard-register {
  flex: 0 0 auto;
  min-width: 112px;
  text-align: center;
}
.dashboard-stats > .card {
  min-width: 0;
  min-height: 128px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.dashboard-lower {
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  align-items: stretch;
}
.dashboard-lower > .card {
  min-width: 0;
  min-height: 286px;
}
.dashboard-recent .table-wrap { min-width: 0; }
.dashboard-recent table { min-width: 620px; }
.dashboard-recent tbody .empty { height: 150px; vertical-align: middle; }
.dashboard-low-stock {
  display: flex;
  flex-direction: column;
}
.dashboard-low-stock .empty {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 172px;
  padding: 20px 14px 34px;
}
.dashboard-page + .footer { padding-top: 30px; }

@media (max-width: 900px) {
  .dashboard-lower { grid-template-columns: 1fr; }
  .dashboard-lower > .card { min-height: 0; }
  .dashboard-low-stock .empty { min-height: 120px; }
}

@media (max-width: 560px) {
  .dashboard-page { gap: 10px; }
  .dashboard-hero { margin-bottom: 2px; min-height: 0; }
  .dashboard-register { width: 100%; }
  .dashboard-stats > .card { min-height: 112px; }
  .dashboard-recent table { min-width: 600px; }
}
/* Keep form labels accessible without adding visual noise to compact tables. */
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0, 0, 0, 0); white-space:nowrap; border:0; }
.supplier-plan-group + .supplier-plan-group { margin-top:24px; padding-top:20px; border-top:1px solid var(--border); }
.supplier-plan-group .section-title { align-items:flex-start; flex-wrap:wrap; gap:12px; }
.supplier-plan-group table { min-width:880px; }
.supplier-actions { display:flex; flex-wrap:wrap; gap:8px; }
.supplier-actions form { margin:0; }
.supplier-list input { min-width:170px; }

/* Screenshot import keeps OCR guidance and correction inside the existing dark cards. */
.screenshot-import-page { display:grid; gap:16px; }
.screenshot-upload, .screenshot-recognition, .screenshot-proposal, .screenshot-receipt {
  display:grid;
  gap:14px;
}
.screenshot-correction { display:grid; gap:12px; padding-top:4px; }
.screenshot-ocr-text {
  max-height:220px;
  overflow:auto;
  white-space:pre-wrap;
  overflow-wrap:anywhere;
}
.screenshot-recognition .badge.good { border-color:#35684b; color:var(--good); }
.screenshot-recognition .badge.warn { border-color:#74602b; color:var(--warn); }
.screenshot-recognition .badge.bad { border-color:#713d3d; color:var(--bad); }
@media (max-width:560px) {
  .screenshot-import-page { gap:10px; }
  .screenshot-upload input[type="file"] { max-width:100%; }
}
