:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #687285;
  --line: #dce2ea;
  --accent: #2563eb;
  --accent-rgb: 37, 99, 235;
  --sidebar-width: 137px;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111318;
  --panel: #1b1f27;
  --text: #f1f5f9;
  --muted: #a5afbf;
  --line: #343b47;
  --accent: #60a5fa;
  --accent-rgb: 96, 165, 250;
}
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea,
[data-theme="dark"] button,
[data-theme="dark"] .button-link.secondary {
  background: #222833;
  color: var(--text);
}
[data-theme="dark"] .danger-button { background: #3b1d25; color: #fda4af; border-color: #7f1d1d; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 8px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }

.app-shell { display: flex; min-height: 100vh; position: relative; }
.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  padding: 12px;
  background: #111827;
  color: #fff;
  overflow-x: hidden;
  overflow-y: auto;
  transition: flex-basis 0.3s ease, width 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
}
.sidebar:not(.expanded) {
  flex-basis: 0;
  width: 0;
  padding-left: 0;
  padding-right: 0;
  opacity: 0;
  pointer-events: none;
}
.brand { font-weight: 800; margin-bottom: 22px; }
.sidebar nav { display: grid; gap: 8px; }
.sidebar a { padding: 9px 10px; border-radius: 6px; color: #e5e7eb; }
.sidebar a:hover { background: rgba(255,255,255,.08); }
.sidebar-toggle-button {
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 60px;
  border-radius: 0 8px 8px 0;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  z-index: 1001;
  font-size: 14px;
  font-weight: 700;
  transition: left 0.3s ease, opacity 0.3s ease, background 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(15, 23, 42, 0.2);
  opacity: 0.4;
  padding: 0;
}
.sidebar-toggle-button.expanded { left: var(--sidebar-width); }
.sidebar-toggle-button:hover {
  opacity: 1;
  background: #1d4ed8;
  border-color: transparent;
}
[data-theme="dark"] .sidebar-toggle-button:hover { background: #3b82f6; }
.nav-section { display: grid; gap: 6px; }
.nav-section-title {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border-radius: 6px;
  border: 0;
  background: transparent;
  color: #e5e7eb;
  font-weight: 700;
  cursor: pointer;
}
.nav-section-title:hover { background: rgba(255,255,255,.08); border-color: transparent; }
.nav-section-caret { transition: transform .15s ease; }
.nav-section-caret.is-open { transform: rotate(90deg); }
.nav-section-links { display: grid; gap: 6px; }
.nav-section-links a { margin-left: 12px; padding-left: 14px; }
.nav-section-links--popover {
  position: fixed;
  z-index: 1100;
  min-width: 168px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: #1f2937;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.38);
}
.nav-section-links--popover a {
  margin-left: 0;
  padding-left: 10px;
}
.main-content { flex: 1; padding: 24px; min-width: 0; }
.main-content:has(.dashboard) { padding-left: 12px; padding-right: 12px; }

.auth-panel {
  max-width: 380px;
  margin: 8vh auto;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.auth-links { display: flex; justify-content: space-between; gap: 12px; }
.form-errors {
  color: #be123c;
  font-size: 12px;
  font-weight: 700;
}
.form-errors ul, .signup-password-help ul {
  margin: 0;
  padding-left: 18px;
}
.signup-password-help-group {
  display: grid;
  gap: 8px;
  margin-top: -4px;
}
.signup-password-help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}
form { display: grid; gap: 12px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 700; }
input, select, textarea {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; line-height: 1.5; }
.inline-check { display: flex; align-items: center; gap: 8px; }
.inline-check[data-tooltip] {
  position: relative;
}
.inline-check[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 30;
  width: max-content;
  max-width: min(320px, 80vw);
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--text);
  color: var(--panel);
  box-shadow: var(--shadow);
  font-size: 12px;
  line-height: 1.4;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 80ms ease, transform 80ms ease;
}
.inline-check[data-tooltip]:hover::after,
.inline-check[data-tooltip]:focus-within::after {
  opacity: 1;
  transform: translateY(0);
}
[x-cloak] { display: none !important; }

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.checkbox-row input[type="checkbox"] {
  width: 14px;
  height: 14px;
  min-width: 14px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

/* Toast styles */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 380px;
  width: calc(100% - 48px);
}

.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  font-size: 14px;
  font-weight: 500;
  backdrop-filter: blur(8px);
  transition: all 0.3s ease;
  margin-bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--line);
  color: var(--text);
}

/* Success theme */
.flash.success {
  background: rgba(240, 253, 250, 0.95);
  border: 1px solid #99f6e4;
  color: #0f766e;
}
/* Error/Danger theme */
.flash.error, .flash.danger {
  background: rgba(254, 242, 242, 0.95);
  border: 1px solid #fecaca;
  color: #b91c1c;
}
/* Warning theme */
.flash.warning {
  background: rgba(254, 251, 232, 0.95);
  border: 1px solid #fef08a;
  color: #a16207;
}
/* Info theme */
.flash.info {
  background: rgba(240, 249, 255, 0.95);
  border: 1px solid #bae6fd;
  color: #0369a1;
}

/* Dark mode overrides */
[data-theme="dark"] .flash {
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #f1f5f9;
}
[data-theme="dark"] .flash.success {
  background: rgba(6, 78, 59, 0.95);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #a7f3d0;
}
[data-theme="dark"] .flash.error, [data-theme="dark"] .flash.danger {
  background: rgba(127, 29, 29, 0.95);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}
[data-theme="dark"] .flash.warning {
  background: rgba(120, 53, 4, 0.95);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #fde68a;
}
[data-theme="dark"] .flash.info {
  background: rgba(30, 58, 138, 0.95);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #bfdbfe;
}

.toast-close {
  background: transparent;
  border: none;
  font-size: 18px;
  line-height: 1;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  padding: 4px;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: opacity 0.15s, background-color 0.15s;
}
.toast-close:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.05);
  border-color: transparent;
}
[data-theme="dark"] .toast-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

.nav-with-badge { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.nav-badge {
  min-width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #dc2626;
  color: #fff;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 800;
}

.page-head, .toolbar, .inline-form, .filter-bar, .report-tabs {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.page-head { justify-content: space-between; margin-bottom: 14px; }
.page-head h1, .panel-head h2, .panel-head h3 { margin: 0; }
.page-description, .muted { color: var(--muted); }
.page-description { margin: 5px 0 0; font-size: 14px; }
.upload-form { display: flex; align-items: center; }
.item-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.content-panel {
  margin-bottom: 14px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.panel-head p { margin: 5px 0 0; }
.section-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.section-tabs button {
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}
.section-tabs button.active { border-bottom-color: var(--accent); color: var(--accent); }
.table-scroll { overflow-x: auto; }
.inline-action, .action-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.inline-action { min-width: 180px; }
.inline-action select { min-width: 95px; }
.action-row { flex-wrap: wrap; }
.action-row form { display: inline-flex; }
.bulk-entry-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.bulk-entry-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.bulk-entry-head h3,
.bulk-entry-head h4 {
  margin: 0;
}
.bulk-input-list {
  display: grid;
  gap: 8px;
}
.bulk-input-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(180px, 1.4fr) 90px auto;
  gap: 8px;
  align-items: center;
}
.modal-panel.type-bulk-modal-panel {
  width: min(1080px, calc(100vw - 24px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  overflow-x: hidden;
}
.modal-panel.classification-editor-modal-panel {
  width: min(1160px, calc(100vw - 24px));
  height: 90vh;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow-y: hidden;
  overflow-x: hidden;
  padding: 0;
  border: 1px solid #cbd5e1;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
}
.classification-editor-headbar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.classification-editor-headbar h2 {
  margin-bottom: 2px;
}
.classification-editor-modal-panel form {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
}
.classification-editor-body {
  min-height: 0;
  overflow-y: auto;
  padding: 10px 14px;
  background: #f6f8fb;
}
.classification-editor-section {
  margin: 0 0 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.04);
}
.classification-editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.classification-editor-toolbar h3 {
  margin: 0;
  font-size: 1rem;
}
.classification-tree-editor-section {
  margin-bottom: 0;
}
.classification-editor-actions {
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
}
.modal-bulk-head {
  margin-bottom: 10px;
}
.modal-bulk-list {
  margin-bottom: 14px;
}
.type-add-row-button {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  padding: 6px 10px;
  border-color: rgba(var(--accent-rgb), 0.42);
  background: rgba(var(--accent-rgb), 0.1);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 800;
}
.type-bulk-input-row {
  grid-template-columns: 34px minmax(120px, 1fr) minmax(0, 3fr) 58px 74px 54px;
  gap: 6px;
}
.type-bulk-input-head {
  align-items: end;
  padding: 0 0 2px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}
.type-bulk-input-row input[name="type_names"],
.type-bulk-input-row input[name="type_descriptions"] {
  width: 100%;
  min-width: 0;
}
.type-active-check {
  display: inline-flex;
  margin: 0;
  gap: 4px;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  font-size: 0.88rem;
}
.type-active-check input[type="checkbox"] {
  width: 14px;
  height: 14px;
  min-width: 14px;
  margin: 0;
}
.type-bulk-input-row > .danger-button {
  width: 100%;
  padding-inline: 0;
}
.row-number {
  min-width: 32px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}
.row-move-actions {
  display: inline-flex;
  gap: 4px;
}
.row-move-actions button {
  padding-inline: 8px;
}
.move-icon-button {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 0;
}
.move-triangle {
  display: block;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
}
.move-up {
  border-bottom: 10px solid currentColor;
}
.move-down {
  border-top: 10px solid currentColor;
}
.classification-tree {
  display: grid;
  gap: 8px;
}
.classification-browser {
  display: grid;
  gap: 12px;
}
.classification-selector-row {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 8px;
}
.classification-selector-row label:first-child {
  min-width: min(360px, 100%);
}
.classification-toggle-active-form {
  margin-left: auto;
}
.classification-active-filter {
  margin-bottom: 7px;
  gap: 4px;
  align-items: center;
  font-size: 0.88rem;
}
.classification-active-filter input[type="checkbox"] {
  width: 14px;
  height: 14px;
  min-width: 14px;
  margin: 0;
}
.classification-summary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.classification-browser button,
.classification-editor-modal-panel button {
  padding: 5px 8px;
  font-size: 0.86rem;
  line-height: 1.15;
}
.classification-tree-row {
  display: grid;
  grid-template-columns: 24px minmax(180px, 1fr);
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 3px 6px;
  margin-left: calc(var(--tree-depth, 0) * 18px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.classification-tree-main {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  font-size: 0.9rem;
}
.classification-tree-main strong {
  overflow-wrap: anywhere;
}
.tree-toggle-button {
  width: 24px;
  min-width: 24px;
  padding: 2px 0;
}
.tree-toggle-button:disabled {
  border-color: transparent;
  background: transparent;
  cursor: default;
}
.tree-empty {
  padding: 10px;
  text-align: center;
}
.classification-editor-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1.1fr) minmax(220px, 1.6fr) 112px 62px;
  gap: 8px;
  align-items: end;
}
.classification-description-field {
  grid-column: auto;
}
.classification-editor-tree {
  display: grid;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
}
.classification-editor-row {
  display: grid;
  grid-template-columns: 24px 38px minmax(140px, 1fr) minmax(170px, 1.35fr) 46px 62px 48px 48px;
  align-items: center;
  gap: 5px;
  min-height: 26px;
  padding: 1px 0;
  margin-left: calc(var(--tree-depth, 0) * 16px);
}
.classification-tree-column-head {
  margin-left: 0;
  padding: 0 0 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}
.classification-editor-row:not(.classification-tree-column-head):hover {
  background: rgba(241, 245, 249, 0.75);
}
.classification-editor-row input {
  width: 100%;
  min-width: 0;
  padding: 4px 6px;
  font-size: 0.85rem;
  line-height: 1.15;
}
.classification-editor-row > button:not(.tree-toggle-button):not(.move-icon-button) {
  width: 100%;
  padding: 4px 0;
  white-space: nowrap;
}
.classification-add-cell button {
  width: 100%;
  padding: 4px 0;
  white-space: nowrap;
}
.classification-tree-column-head > span:nth-child(5),
.classification-tree-column-head > span:nth-child(6),
.classification-tree-column-head > span:nth-child(7) {
  text-align: center;
}
.classification-level-badge {
  justify-self: start;
  min-width: 24px;
  justify-content: center;
  padding: 2px 6px;
  color: #fff;
  font-size: 10px;
}
.classification-active-check {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  margin: 0;
  gap: 4px;
  white-space: nowrap;
  font-size: 0.84rem;
}
.classification-active-check input[type="checkbox"] {
  width: 12px;
  height: 12px;
  min-width: 12px;
  margin: 0;
  accent-color: var(--accent);
}
.classification-editor-row .move-icon-button {
  width: 26px;
  height: 26px;
}
.classification-editor-row .move-triangle {
  border-left-width: 5px;
  border-right-width: 5px;
}
.classification-editor-row .move-up {
  border-bottom-width: 7px;
}
.classification-editor-row .move-down {
  border-top-width: 7px;
}
.classification-add-root-button {
  border-color: rgba(var(--accent-rgb), 0.42);
  background: rgba(var(--accent-rgb), 0.1);
  color: var(--accent);
  font-weight: 800;
}
@media (max-width: 1100px) {
  .classification-editor-grid {
    grid-template-columns: 1fr;
  }
  .classification-editor-row {
    grid-template-columns: 28px minmax(0, 1fr);
  }
  .classification-tree-column-head {
    display: none;
  }
  .classification-editor-row > *:not(.tree-toggle-button) {
    grid-column: 2;
  }
}
.primary, .button-link {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
.danger-button {
  border-color: #fecaca;
  background: #fff1f2;
  color: #be123c;
}
.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 12px;
  border-radius: 6px;
}
.button-link.secondary { border: 1px solid var(--line); background: #fff; color: var(--text); }
.text-link { color: var(--accent); font-weight: 700; }
.table-sort { color: var(--text); font-weight: 800; }
.detail-button { border: 0; background: transparent; padding: 0; }
.status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 7px;
  background: #eef2f7;
  color: #475569;
  font-size: 11px;
  font-weight: 800;
}
.status-badge.success { background: #dcfce7; color: #166534; }
.status-badge.warning { background: #fef3c7; color: #92400e; }
.status-badge.danger { background: #fee2e2; color: #991b1b; }
.status-badge.muted { background: #e2e8f0; color: #64748b; }
.status-badge.classification-level-badge {
  width: 20px;
  min-width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
}
.status-badge.classification-level-badge.classification-level-1 { background: #2563eb; }
.status-badge.classification-level-badge.classification-level-2 { background: #059669; }
.status-badge.classification-level-badge.classification-level-3 { background: #d97706; }
.status-badge.classification-level-badge.classification-level-4 { background: #7c3aed; }
.mono-cell {
  max-width: 220px;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.error-copy { white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.detail-grid div { min-width: 0; }
.detail-grid .wide { grid-column: 1 / -1; }
.detail-grid dt { color: var(--muted); font-size: 12px; font-weight: 800; }
.detail-grid dd { margin: 5px 0 0; }
.detail-dialog {
  width: min(1100px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--panel);
  color: var(--text);
}
.detail-dialog::backdrop { background: rgba(15, 23, 42, 0.58); }
.settings-section {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}
.settings-form {
  display: flex;
  align-items: end;
  grid-template-columns: 180px auto;
}
.mapper-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.mapper-item {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.mapper-item textarea {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  color: var(--muted);
}
.pagination a { color: var(--accent); font-weight: 700; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.56);
}
.modal-panel {
  width: min(480px, 100%);
  padding: 18px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.28);
}
.customer-modal-panel { width: min(920px, calc(100vw - 32px)); }
.dual-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.dual-picker section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.dual-picker h3 {
  margin: 0 0 10px;
  font-size: 14px;
}
.picker-list {
  display: grid;
  gap: 6px;
  max-height: 320px;
  overflow: auto;
  margin-top: 10px;
}
.picker-row {
  width: 100%;
  border-color: var(--line);
  background: #fff;
  color: var(--text);
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.picker-row:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.picker-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background-color: rgba(var(--accent-rgb), 0.12);
  padding: 2.5px 6px;
  border-radius: 4px;
  white-space: nowrap;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 12px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.icon-button {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 20px;
}
.field-feedback { min-height: 18px; margin-top: -8px; font-size: 12px; font-weight: 700; }
.field-error { color: #be123c; }
.count-failed { color: #be123c; font-weight: 700; }
.field-success { color: #15803d; }
.preset-manager {
  width: min(820px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  margin-top: 14px;
}
.preset-manager > div:first-child { margin-bottom: 12px; }
.preset-manager h2 { margin: 0; }
.preset-manager p { margin: 5px 0 0; }
.preset-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.preset-label {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.preset-list {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.preset-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.preset-list-item.dragging {
  opacity: 0.56;
  border-style: dashed;
}
.preset-list-item.selected {
  border-color: var(--accent);
  background: #eff6ff;
}
.drag-handle {
  color: var(--muted);
  cursor: grab;
  font-weight: 800;
  user-select: none;
}
.preset-inline-form {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  min-width: 240px;
}
.preset-inline-form input[name="preset_name"] {
  flex: 1;
  min-width: 120px;
}
.preset-inline-form input[readonly] {
  background: var(--bg);
}
.preset-rename-actions {
  display: inline-flex;
  gap: 6px;
}
.theme-settings {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.theme-settings h2 { margin: 0; }
.theme-settings p { margin: 5px 0 0; }
.light-segmented { background: var(--bg); border-color: var(--line); }
.light-segmented button { color: var(--muted); }
.light-segmented button.active { color: #111; }

.report-workspace { margin: 12px 0; }
.report-tabs {
  margin: 0;
  align-items: flex-end;
  gap: 4px;
  position: relative;
  z-index: 1;
}
.report-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  position: relative;
  background: linear-gradient(180deg, #eef1f6 0%, #e3e8ef 100%);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  padding: 8px 14px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
  transform: translateY(3px);
  transition: transform 0.16s ease, box-shadow 0.16s ease, color 0.16s ease, background 0.16s ease;
}
.report-tab:hover {
  color: var(--text);
  background: linear-gradient(180deg, #f3f5f9 0%, #e8ecf1 100%);
  border-color: var(--line);
}
.report-tab:active { cursor: grabbing; }
.report-tab.active {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
  border-bottom: 1px solid var(--panel);
  margin-bottom: -1px;
  font-weight: 700;
  z-index: 2;
  transform: translateY(0);
  box-shadow:
    -3px 0 6px rgba(15, 23, 42, 0.05),
    3px 0 6px rgba(15, 23, 42, 0.05),
    0 -2px 8px rgba(15, 23, 42, 0.06);
}
.report-tab.add {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  transform: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  font-weight: 900;
}
.report-tab.add:hover { border-color: var(--accent); }
.report-save-button {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 6px 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: rgba(var(--accent-rgb), 0.08);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.report-save-button:hover {
  background: rgba(var(--accent-rgb), 0.14);
  border-color: var(--accent);
}
.report-tab.dragging {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: transparent;
  transform: none;
}
.report-tab.dragging > * { visibility: hidden; }
.report-tab.drag-image {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  color: var(--text);
  opacity: 0.95;
  z-index: 1000;
  transform: translateY(-1px);
  box-shadow:
    0 8px 20px rgba(15, 23, 42, 0.16),
    0 2px 6px rgba(15, 23, 42, 0.1);
}
.report-tab.drag-image > * { visibility: visible; }
.report-body {
  border: 1px solid var(--line);
  border-radius: 0 8px 8px 8px;
  background: var(--panel);
  padding: 16px 12px;
  box-shadow: 0 4px 18px rgba(15, 23, 42, 0.07);
}
.report-body > *:last-child { margin-bottom: 0; }
.tab-actions { display: inline-flex; gap: 4px; color: inherit; }
.tab-actions span { padding: 0 2px; }
.report-tab [data-tab-close] {
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.15s ease, background 0.15s ease;
}
.report-tab [data-tab-close]:hover {
  color: #be123c;
  background: rgba(190, 24, 60, 0.12);
}
[data-theme="dark"] .report-tab [data-tab-close]:hover {
  color: #fda4af;
  background: rgba(190, 24, 60, 0.2);
}
[data-theme="dark"] .report-tab {
  background: linear-gradient(180deg, #141820 0%, #10131a 100%);
  color: #7d8798;
  border-color: #2a3140;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
[data-theme="dark"] .report-tab:hover {
  color: #b6c0d0;
  background: linear-gradient(180deg, #181d27 0%, #141820 100%);
}
[data-theme="dark"] .report-tab.active {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
  border-bottom-color: var(--panel);
  box-shadow:
    -3px 0 8px rgba(0, 0, 0, 0.22),
    3px 0 8px rgba(0, 0, 0, 0.22),
    0 -2px 10px rgba(0, 0, 0, 0.24);
}
[data-theme="dark"] .report-body {
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28);
}
[data-theme="dark"] .report-tab.drag-image {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.36),
    0 3px 8px rgba(0, 0, 0, 0.24);
}
[data-theme="dark"] .report-tab.add {
  background: #222833;
  color: var(--text);
  border-color: var(--line);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.24);
}
[data-theme="dark"] .report-save-button {
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--accent);
  border-color: var(--accent);
}
[data-theme="dark"] .report-save-button:hover {
  background: rgba(var(--accent-rgb), 0.2);
}

.quick-date-bar {
  margin-bottom: 12px;
  width: fit-content;
  max-width: 100%;
}
.quick-date-segmented {
  display: inline-flex;
  align-items: stretch;
  width: fit-content;
  max-width: 100%;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: #334155;
  overflow: hidden;
  overflow-x: auto;
}
.quick-btn {
  position: relative;
  flex: 0 0 auto;
  padding: 8px 14px;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: #e2e8f0;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.quick-btn:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 22%;
  right: 0;
  bottom: 22%;
  width: 1px;
  background: rgba(255, 255, 255, 0.22);
}
.quick-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}
.quick-btn.active {
  background: var(--accent);
  color: #fff;
}
.quick-btn.active::after {
  display: none;
}
[data-theme="dark"] .quick-date-segmented {
  background: #252b36;
}
[data-theme="dark"] .quick-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.filter-bar {
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  align-items: end;
}
.filter-bar label { min-width: 0; }
.filter-bar-dates {
  display: contents;
}
.filter-bar-dates label {
  min-width: 0;
}
.filter-bar-pickers {
  display: contents;
}
.filter-bar-pickers label {
  min-width: 0;
}
.filter-bar > .filter-bar-submit {
  min-height: 36px;
  padding: 8px 18px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.24);
}
.filter-bar > .filter-bar-submit:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}
[data-theme="dark"] .filter-bar > .filter-bar-submit:hover {
  background: #3b82f6;
  border-color: #3b82f6;
}
.filter-bar label:has(.filter-picker) {
  overflow: visible;
  padding-top: 9px;
}
.filter-preset-field {
  min-width: min(100%, 180px);
}
.filter-preset-label-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.preset-reload-button {
  flex: 0 0 auto;
  margin: 0;
  padding: 1px 8px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.01em;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.24);
  cursor: pointer;
}
.preset-reload-button:hover:not(:disabled) {
  background: #1d4ed8;
  border-color: #1d4ed8;
}
.preset-reload-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
[data-theme="dark"] .preset-reload-button:hover:not(:disabled) {
  background: #3b82f6;
  border-color: #3b82f6;
}
.filter-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.filter-picker-count {
  position: absolute;
  left: 50%;
  top: 0;
  z-index: 2;
  transform: translate(-50%, -50%);
  color: #f97316;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
}
.filter-picker-tooltip {
  position: fixed;
  z-index: 80;
  width: max-content;
  max-width: min(420px, calc(100vw - 16px));
  max-height: min(360px, calc(100vh - 16px));
  overflow: auto;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.18);
}
.filter-picker-tooltip strong {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
}
.filter-picker-tooltip div {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.filter-picker-tooltip span {
  max-width: 180px;
  padding: 4px 7px;
  border-radius: 5px;
  background: var(--bg);
  overflow-wrap: anywhere;
  font-size: 12px;
}
.sales-filter-picker-modal {
  max-height: calc(100vh - 32px);
  overflow: auto;
}
.filter-picker-foreign-all {
  margin-bottom: 8px;
}
.card-picker-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.card-picker-row-lead {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.card-picker-handle {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  letter-spacing: -2px;
  cursor: grab;
  user-select: none;
}
.card-picker-row[draggable="true"] { cursor: grab; }
.card-picker-row[draggable="true"].dragging {
  opacity: 0.5;
  border-color: var(--accent);
  cursor: grabbing;
}
.card-picker-pin-badge {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: rgba(120, 120, 120, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
}
.card-picker-row small {
  flex: 0 0 auto;
  margin-left: 8px;
  color: var(--muted);
  font-weight: 400;
}
.card-picker-row:hover small {
  color: var(--muted);
}
.report-card-picker > button {
  border-color: var(--accent);
}
.report-card-loading {
  text-align: center;
  padding: 12px 8px;
}
.detail-loading {
  display: flex;
  justify-content: center;
  padding: 24px 8px;
}
.report-card-loading-state {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.report-card-loading-text {
  color: var(--muted);
  font-size: 13px;
}
.report-card-shimmer {
  display: inline-block;
  width: 82px;
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, #e9edf3 0%, #f8fbff 45%, #dfe7f1 70%, #e9edf3 100%);
  background-size: 220% 100%;
  animation: report-card-shimmer 1.15s linear infinite;
  box-shadow: inset 0 0 0 1px rgba(0, 123, 255, 0.06);
}
[data-theme="dark"] .report-card-shimmer {
  background: linear-gradient(90deg, #2a3140 0%, #3a4558 45%, #252b38 70%, #2a3140 100%);
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.08);
}
@keyframes report-card-shimmer {
  from {
    background-position: 120% 0;
  }
  to {
    background-position: -120% 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .report-card-shimmer {
    animation: none;
    background-position: 0 0;
  }
}

/* Report card layout profiles (viewport width basis) */
.layout-full {
  display: grid;
  grid-template-columns: 1fr;
}
.layout-responsive-52 {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 10px;
}
@media (max-width: 1100px) {
  .layout-responsive-52 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.layout-responsive-321 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
@media (max-width: 1920px) {
  .layout-responsive-321 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 1100px) {
  .layout-responsive-321 {
    grid-template-columns: 1fr;
  }
}

.kpi-grid {
  margin: 14px 0;
}
.kpi-grid article {
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.kpi-grid span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.kpi-grid strong { display: block; margin-top: 6px; font-size: 22px; }

.chart-panel {
  background: #101114;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,.1);
}
.chart-toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  background: #101114;
  color: #e5e7eb;
  overflow: visible;
  position: relative;
  z-index: 20;
}
.chart-toolbar-left {
  justify-self: start;
}
.chart-toolbar-center {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  justify-self: center;
}
.chart-toolbar-right {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  justify-self: end;
}
.segmented {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid rgba(214, 211, 209, 0.16);
  border-radius: 7px;
  background: rgba(12, 10, 9, 0.5);
}
.segmented button {
  min-width: 34px;
  height: 28px;
  background: transparent;
  color: #d6d3d1;
  border: 0;
  border-radius: 5px;
  padding: 0 9px;
  font-size: 13px;
  font-weight: 800;
}
.segmented button:hover { background: rgba(214, 211, 209, 0.11); }
.segmented button.active {
  background: linear-gradient(135deg, #ff7a59 0%, #38bdf8 100%);
  color: #111;
  box-shadow: 0 8px 20px rgba(255, 122, 89, 0.18);
}
.chart-series-toggles {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.chart-series-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border: 1px solid rgba(214, 211, 209, 0.16);
  border-radius: 7px;
  background: rgba(12, 10, 9, 0.48);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  user-select: none;
}
.chart-series-toggle input {
  width: 13px;
  height: 13px;
  margin: 0;
  accent-color: currentColor;
}
.chart-series-toggle-amount { color: #ff7a59; }
.chart-series-toggle-quantity { color: #38bdf8; }
.chart-zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid rgba(214, 211, 209, 0.16);
  border-radius: 7px;
  background: rgba(12, 10, 9, 0.5);
}
.chart-zoom-controls button {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #d6d3d1;
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  padding: 0;
}
.chart-zoom-controls button:hover {
  background: rgba(214, 211, 209, 0.11);
  color: #ffffff;
}
[data-chart-status] {
  min-height: 18px;
  color: #a8a29e;
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}
.chart-wrap {
  position: relative;
  height: 480px;
}
#salesMainChart { width: 100%; height: 100%; }
.axis-label {
  position: absolute;
  top: 8px;
  z-index: 3;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(16,17,20,.86);
  border: 1px solid rgba(214, 211, 209, 0.14);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.3;
  pointer-events: none;
}
.axis-label.left { left: 8px; color: #ff7a59; border-color: rgba(255, 122, 89, 0.34); }
.axis-label.right { right: 8px; color: #38bdf8; border-color: rgba(56, 189, 248, 0.34); }
.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 205px;
  padding: 9px 10px;
  border: 1px solid rgba(214,211,209,.18);
  border-radius: 7px;
  background: rgba(16,17,20,.96);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  color: #d6d3d1;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.55;
  pointer-events: none;
}
.chart-tooltip-date {
  margin-bottom: 3px;
  color: #fafaf9;
  font-weight: 800;
}
.chart-tooltip-weekday { color: #facc15; }
.chart-tooltip-row {
  display: grid;
  grid-template-columns: 74px minmax(96px, 1fr);
  gap: 10px;
  align-items: baseline;
}
.chart-tooltip-row span { text-align: left; }
.chart-tooltip-row strong { text-align: right; }
.chart-tooltip-row-amount span,
.chart-tooltip-row-amount strong { color: #ff7a59; }
.chart-tooltip-row-quantity span,
.chart-tooltip-row-quantity strong { color: #38bdf8; }
.chart-tooltip .is-up { color: #ff1493; }
.chart-tooltip .is-down { color: #38bdf8; }

.forecast-panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.forecast-head,
.forecast-controls,
.forecast-weight,
.forecast-switch {
  display: flex;
  align-items: center;
}
.forecast-head {
  justify-content: space-between;
  gap: 12px;
}
.forecast-head h2 { margin: 0 0 3px; }
.forecast-switch,
.forecast-controls,
.forecast-weight { gap: 8px; }
.forecast-switch { font-size: 13px; font-weight: 800; }
.forecast-controls {
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.forecast-weight input[type="number"] { width: 64px; }
.forecast-weight input[type="range"] { width: 180px; }
.forecast-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.forecast-summary-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
}
.forecast-summary-item span,
.forecast-summary-item strong { display: block; }
.forecast-summary-item span { color: var(--muted); font-size: 12px; }
.forecast-summary-item strong { margin-top: 3px; font-size: 18px; }
.forecast-chart-wrap {
  position: relative;
  height: 330px;
  margin-top: 12px;
  border: 1px solid rgba(214, 211, 209, 0.14);
  border-radius: 7px;
  background: #101114;
}
#salesForecastChart { width: 100%; height: 100%; display: block; }
.forecast-axis-label {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 3;
  padding: 2px 6px;
  border: 1px solid rgba(255, 122, 89, 0.34);
  border-radius: 5px;
  background: rgba(16, 17, 20, .86);
  color: #ff7a59;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.3;
  pointer-events: none;
}
.forecast-meta { margin-top: 10px; font-size: 12px; }
.forecast-table-wrap { margin-top: 12px; overflow-x: auto; }
.forecast-panel.is-loading { opacity: .72; }

.two-column {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.two-column > section, .two-column > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.analysis-grid {
  margin-top: 14px;
}
.analysis-grid > div {
  min-width: 0;
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.analysis-grid h2 { margin: 0 0 10px; }
.analysis-chart-wrap {
  position: relative;
  width: 100%;
  height: 210px;
  margin-bottom: 12px;
}
.analysis-chart-rank { height: 230px; }
.analysis-chart-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}
.analysis-chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}
.analysis-other-row td { font-weight: 700; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { border-bottom: 1px solid var(--line); padding: 8px; text-align: left; }
th { color: var(--muted); font-size: 12px; }
td { font-size: 13px; }
th.numeric-cell,
td.numeric-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
th.rank-cell,
td.rank-cell {
  width: 42px;
  white-space: nowrap;
}
th.checkbox-cell,
td.checkbox-cell {
  width: 2.5rem;
  text-align: center;
  vertical-align: middle;
}
th.numeric-cell .sort-button {
  width: 100%;
  text-align: right;
}
.preset-form { margin-top: 14px; display: flex; }

.upload-modal-trigger {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-weight: 700;
  font-size: 13px;
  padding: 6px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  margin-left: auto;
  align-self: flex-start;
}
.upload-modal-trigger:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}
[data-theme="dark"] .upload-modal-trigger:hover {
  background: #3b82f6;
  border-color: #3b82f6;
}
.upload-manager {
  width: min(850px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}
.modal-upload-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.upload-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.modal-divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 8px 0;
}
.modal-recent-uploads h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 800;
}
.modal-table-wrap {
  overflow-x: auto;
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.modal-table-wrap table {
  width: 100%;
  border-collapse: collapse;
}
.modal-table-wrap th, .modal-table-wrap td {
  padding: 10px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.modal-table-wrap tr:last-child td {
  border-bottom: 0;
}
.modal-table-wrap th {
  background: var(--bg);
  font-weight: 800;
  position: sticky;
  top: 0;
  z-index: 10;
}

.last-upload-info {
  font-size: 13px;
  font-weight: 500;
  color: #f97316;
  margin-left: 10px;
}

/* Table Cell Detail Button & Modal CSS */
.table-detail-button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--accent);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s ease;
}

.table-detail-button:hover {
  background: var(--bg);
  border-color: var(--muted);
}

.table-header-count {
  color: var(--accent);
  font-weight: 600;
  margin-left: 4px;
}

.table-header-count-danger {
  color: #be123c;
  font-weight: 600;
  margin-left: 4px;
}

/* 품목 관리 페이지 탭 테이블: 행 간격 최소화로 화면당 행 수 증가 */
.items-page table th,
.items-page table td { padding: 3px 8px; }
.items-page table td { font-size: 12px; }
.items-page table .action-row { gap: 4px; }
.items-page table .action-row button,
.items-page table .action-row .button-link {
  min-height: 0;
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 4px;
}
.items-page table .table-detail-button {
  padding: 1px 6px;
  font-size: 12px;
}
/* 선택 열 체크박스가 전역 input(min-height:36px)을 상속해 행을 키우는 문제 해소 */
.items-page table input[type="checkbox"] {
  min-height: 0;
  width: auto;
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.modal-panel.detail-list-modal-panel {
  width: max-content;
  min-width: 280px;
  max-width: min(800px, 90vw);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.modal-panel.edit-upload-modal-panel {
  position: relative;
  width: min(1100px, calc(100vw - 24px));
  height: min(95vh, calc(100vh - 40px));
  max-height: min(95vh, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}
.modal-panel.item-edit-modal-panel {
  width: min(560px, calc(100vw - 24px));
  height: min(95vh, calc(100vh - 40px));
  max-height: min(95vh, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  box-sizing: border-box;
}
.item-edit-modal-panel .panel-head {
  flex-shrink: 0;
  padding: 12px 14px 0;
}
.item-edit-modal-panel .panel-head h2 {
  font-size: 16px;
}
.item-edit-modal-form {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  gap: 0;
}
.item-edit-modal-body {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 14px 0;
}
.item-edit-modal-panel .modal-actions {
  flex-shrink: 0;
  padding: 8px 14px 12px;
}
.item-edit-modal-panel .modal-actions button {
  min-height: 28px;
  padding: 5px 10px;
  font-size: 12px;
}
.item-edit-modal-panel label {
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
}
.item-edit-modal-panel input,
.item-edit-modal-panel select,
.item-edit-modal-panel textarea {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}
.item-edit-modal-panel .field-feedback {
  min-height: 14px;
  margin-top: -4px;
  font-size: 11px;
}
.item-edit-modal-panel .form-section {
  display: grid;
  gap: 4px;
}
.item-edit-modal-panel .form-section > h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
}
.item-edit-modal-panel .form-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}
.item-edit-modal-panel .form-section-head h3 {
  margin: 0;
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
}
.item-edit-modal-panel .form-section-head input[type="search"] {
  flex: 1;
  min-width: 0;
  max-width: 200px;
  min-height: 26px;
  padding: 3px 8px;
  font-size: 11px;
}
.item-edit-modal-panel .item-representative-current {
  margin: 0 0 2px;
  font-size: 11px;
  line-height: 1.35;
}
.item-edit-modal-panel .item-representative-picker.picker-list {
  gap: 3px;
  max-height: 240px;
  margin-top: 0;
}
.item-edit-modal-panel .item-representative-picker .picker-row {
  min-height: 0;
  padding: 4px 8px;
  font-size: 11px;
  line-height: 1.35;
  gap: 6px;
}
.item-edit-modal-panel .item-representative-picker .picker-row span {
  font-size: 11px;
}
.item-edit-modal-panel .item-representative-picker .picker-tag {
  font-size: 9px;
  padding: 1px 4px;
}
.item-edit-modal-panel .item-representative-picker .muted {
  font-size: 11px;
  margin: 0;
  padding: 2px 0;
}
.picker-row.is-selected {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.08);
}
.loading-overlay.edit-upload-loading-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  z-index: 30;
}
.edit-upload-body {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.edit-upload-result {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.edit-upload-notice {
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 600;
}
.edit-upload-notice.success {
  background: #ecfdf5;
  color: #047857;
}
.edit-upload-notice.error {
  background: #fef2f2;
  color: #be123c;
}
.edit-upload-actions {
  display: flex;
  gap: 8px;
}
.edit-upload-section h3 {
  margin: 4px 0;
}

.detail-list-content {
  margin: 12px 0;
  max-height: 50vh;
  overflow-y: auto;
  text-align: left;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.detail-list-item {
  font-size: 13px;
  line-height: 1.5;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
}

.detail-list-item:last-child {
  border-bottom: 0;
}

@media (max-width: 1100px) {
  .app-shell { display: block; }
  .sidebar-toggle-button { display: none; }
  .sidebar,
  .sidebar:not(.expanded) {
    width: auto;
    flex: none;
    opacity: 1;
    pointer-events: auto;
    padding: 10px 12px;
  }
  .brand {
    margin-bottom: 8px;
  }
  .sidebar nav {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .sidebar nav > a,
  .nav-section-title {
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .nav-section {
    position: relative;
    flex: 0 0 auto;
    display: block;
  }
  .nav-section-title {
    width: auto;
  }
  .nav-with-badge {
    justify-content: flex-start;
    gap: 6px;
  }
  .main-content { padding: 16px; }
  .page-head { align-items: stretch; }
  .page-head h1 { width: 100%; }
  .upload-form {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }
  .upload-form > * {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
  .upload-form input[type="file"] { overflow: hidden; }
  .report-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .report-tab {
    flex: 0 0 auto;
    touch-action: auto;
    cursor: pointer;
  }
  .report-tab:active { cursor: pointer; }
  .quick-date-bar {
    width: 100%;
    max-width: 100%;
  }
  .quick-date-segmented {
    max-width: 100%;
  }
  .filter-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
  }
  .filter-bar label,
  .filter-bar > button {
    width: 100%;
    min-width: 0;
  }
  .filter-bar-dates {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
  }
  .filter-bar-dates label,
  .filter-bar-pickers label {
    width: auto;
  }
  .filter-bar-dates input[type="date"] {
    width: 100%;
    min-width: 0;
  }
  .filter-bar-pickers {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    width: 100%;
  }
  .filter-bar-pickers .filter-picker,
  .filter-bar-pickers .filter-picker > button {
    width: 100%;
    min-width: 0;
  }
  .two-column { grid-template-columns: 1fr; }
  .analysis-chart-wrap,
  .analysis-chart-rank { height: 240px; }
  .mapper-grid, .detail-grid { grid-template-columns: 1fr; }
  .detail-grid .wide { grid-column: auto; }
  .settings-section { display: block; }
  .settings-form { margin-top: 12px; }
  .preset-list-item { align-items: flex-start; flex-direction: column; }
  .chart-wrap { height: 360px; }
  .chart-toolbar {
    display: grid;
    grid-template-columns: auto auto auto;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 6px;
  }
  .chart-toolbar-left,
  .chart-toolbar-center,
  .chart-toolbar-right,
  .chart-series-toggles {
    justify-self: auto;
    min-width: 0;
  }
  .chart-toolbar-center,
  .chart-toolbar-right {
    flex-wrap: nowrap;
    justify-content: center;
  }
  .chart-toolbar-right { justify-content: flex-end; }
  .chart-toolbar .segmented {
    gap: 1px;
    padding: 1px;
  }
  .chart-toolbar .segmented button {
    min-width: 26px;
    height: 26px;
    padding: 0 5px;
    font-size: 12px;
  }
  .chart-series-toggles {
    gap: 3px;
    flex-wrap: nowrap;
  }
  .chart-series-toggle {
    gap: 3px;
    padding: 3px 4px;
    font-size: 11px;
    white-space: nowrap;
  }
  .chart-series-toggle input {
    width: 11px;
    height: 11px;
  }
  .chart-zoom-controls {
    gap: 1px;
    padding: 1px;
  }
  .chart-zoom-controls button {
    width: 24px;
    height: 26px;
    font-size: 16px;
  }
  [data-chart-status] { display: none; }
  .forecast-summary { grid-template-columns: 1fr; }
  .forecast-head { align-items: flex-start; }
  .forecast-controls { align-items: stretch; flex-direction: column; }
  .forecast-weight { flex-wrap: wrap; }
  .forecast-weight input[type="range"] { width: 100%; }
  .forecast-chart-wrap { height: 300px; }
  .upload-fields {
    grid-template-columns: 1fr;
  }
  .dashboard .page-head {
    align-items: center;
    flex-wrap: nowrap;
  }
  .dashboard .page-head h1 {
    width: auto;
  }
  .last-upload-info {
    display: block;
    margin-left: 0;
    margin-top: 4px;
    font-size: 11px;
  }
  @media (max-width: 360px) {
    .filter-bar-dates,
    .filter-bar-pickers {
      grid-template-columns: 1fr;
    }
  }
}

/* Glassmorphic Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

[data-theme="dark"] .loading-overlay {
  background: rgba(0, 0, 0, 0.6);
}

/* 페이드인 활성화 시 클래스 */
.loading-overlay.active {
  opacity: 1;
}

/* 글래스모피즘 박스 */
.loading-box {
  background: rgba(255, 255, 255, 0.9);
  padding: 30px 40px;
  border-radius: 16px;
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.18);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 320px;
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

[data-theme="dark"] .loading-box {
  background: rgba(27, 31, 39, 0.9);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.loading-overlay.active .loading-box {
  transform: scale(1);
}

/* 스피너 및 발광 아우라 */
.loading-spinner-wrapper {
  position: relative;
  width: 80px;
  height: 80px;
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.loading-spinner {
  width: 60px;
  height: 60px;
  border: 4px solid rgba(var(--accent-rgb), 0.1);
  border-top: 4px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  z-index: 2;
}

.loading-aura {
  position: absolute;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(var(--accent-rgb), 0.4) 0%, rgba(var(--accent-rgb), 0) 70%);
  animation: pulse-glow 2s infinite ease-in-out;
  z-index: 1;
}

/* 프로그레스 바 디자인 */
.loading-progress-container {
  width: 100%;
  height: 6px;
  background-color: var(--line);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.loading-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent));
  border-radius: 3px;
  transition: width 0.2s ease-out;
}

.loading-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 15px;
  text-align: center;
}

/* 회전 키프레임 */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 아우라 펄스 키프레임 */
@keyframes pulse-glow {
  0%, 100% {
    transform: scale(0.9);
    opacity: 0.3;
  }
  50% {
    transform: scale(1.3);
    opacity: 0.8;
  }
}

/* 거래처 매출 순위 표시순위 입력란 스타일 */
.analysis-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.analysis-card-head h2 {
  margin: 0 !important;
}
.customer-limit-control,
.item-limit-control,
.item-type-limit-control,
.classification-limit-control,
.region-limit-control {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
.customer-limit-input,
.item-limit-input,
.item-type-limit-input,
.classification-limit-input,
.region-limit-input {
  width: 55px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  text-align: center;
}
.customer-limit-input:focus,
.item-limit-input:focus,
.item-type-limit-input:focus,
.classification-limit-input:focus,
.region-limit-input:focus {
  outline: none;
  border-color: var(--accent);
}
