:root {
  --bg: #f3f6fb;
  --panel: rgba(255, 255, 255, 0.82);
  --card: #ffffff;
  --text: #13233f;
  --muted: #61708d;
  --line: rgba(144, 165, 196, 0.24);
  --line-strong: rgba(144, 165, 196, 0.38);
  --brand: #0f6d89;
  --brand-deep: #0e2b59;
  --accent: #10b3a3;
  --danger: #de4f3d;
  --warn: #d48e16;
  --ok: #159a66;
  --shadow: 0 18px 60px rgba(14, 40, 84, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Be Vietnam Pro", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 8%, rgba(16, 179, 163, 0.15), transparent 24%),
    radial-gradient(circle at 88% 18%, rgba(15, 109, 137, 0.16), transparent 22%),
    linear-gradient(180deg, #f7f9fd 0%, #edf3fb 100%);
}

.page-shell {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.35), transparent 35%),
    radial-gradient(circle at bottom right, rgba(15, 109, 137, 0.07), transparent 26%);
}

.layout {
  position: relative;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
  transition: grid-template-columns 0.22s ease;
}

.layout.sidebar-collapsed {
  grid-template-columns: 78px minmax(0, 1fr);
}

.sidebar {
  position: relative;
  z-index: 20;
  overflow: visible;
  background:
    linear-gradient(180deg, rgba(15, 30, 75, 0.96) 0%, rgba(19, 31, 74, 0.92) 100%);
  color: #eef4ff;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 28px;
  padding: 16px 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  transition: padding 0.22s ease, border-radius 0.22s ease;
}

.sidebar-toggle {
  position: absolute;
  z-index: 5;
  top: 22px;
  right: -13px;
  width: 30px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(144, 165, 196, 0.34);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--brand-deep);
  cursor: pointer;
  box-shadow: 0 12px 26px rgba(14, 40, 84, 0.18);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.sidebar-toggle:hover {
  transform: translateX(-1px);
  box-shadow: 0 16px 34px rgba(14, 40, 84, 0.24);
}

.sidebar-toggle .material-symbols-outlined {
  font-size: 22px;
  transition: transform 0.2s ease;
}

.brand-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 16px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.08);
  min-width: 0;
}

.brand-icon {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #ffffff, #dbeafe);
  color: #3756cf;
  box-shadow: 0 10px 24px rgba(55, 86, 207, 0.18);
}

.brand-card h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.brand-card p {
  margin: 6px 0 0;
  color: rgba(219, 231, 255, 0.82);
  font-size: 11px;
  line-height: 1.45;
}

.nav-title {
  margin: 20px 8px 10px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(176, 194, 234, 0.72);
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-list a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  color: #e7efff;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  border-radius: 16px;
  transition: background 0.18s ease, transform 0.18s ease;
}

.nav-list a:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: translateX(2px);
}

.nav-list a.active {
  background: linear-gradient(90deg, rgba(53, 88, 176, 0.42), rgba(15, 126, 152, 0.38));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.layout.sidebar-collapsed .sidebar {
  padding: 14px 10px;
  border-radius: 24px;
}

.layout.sidebar-collapsed .sidebar-toggle {
  right: -15px;
}

.layout.sidebar-collapsed .sidebar-toggle .material-symbols-outlined {
  transform: rotate(180deg);
}

.layout.sidebar-collapsed .brand-card {
  justify-content: center;
  padding: 12px 8px;
  border-radius: 18px;
}

.layout.sidebar-collapsed .brand-card > div:not(.brand-icon),
.layout.sidebar-collapsed .nav-title {
  display: none;
}

.layout.sidebar-collapsed .brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 15px;
}

.layout.sidebar-collapsed .nav-list {
  margin-top: 16px;
}

.layout.sidebar-collapsed .nav-list a {
  justify-content: center;
  gap: 0;
  min-height: 48px;
  padding: 12px;
  font-size: 0;
  border-radius: 16px;
}

.layout.sidebar-collapsed .nav-list a .material-symbols-outlined {
  font-size: 24px;
}

.layout.sidebar-collapsed .nav-list a:hover {
  transform: translateY(-1px);
}

.layout.sidebar-collapsed .nav-list a[data-nav-label]::after {
  content: attr(data-nav-label);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  z-index: 80;
  min-width: max-content;
  max-width: 240px;
  padding: 8px 11px;
  border: 1px solid rgba(144, 165, 196, 0.28);
  border-radius: 12px;
  background: rgba(14, 35, 75, 0.96);
  color: #ffffff;
  box-shadow: 0 14px 34px rgba(14, 40, 84, 0.24);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0;
  opacity: 0;
  pointer-events: none;
  transform: translate(6px, -50%);
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.layout.sidebar-collapsed .nav-list a[data-nav-label]::before {
  content: "";
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  z-index: 81;
  width: 10px;
  height: 10px;
  background: rgba(14, 35, 75, 0.96);
  border-left: 1px solid rgba(144, 165, 196, 0.28);
  border-bottom: 1px solid rgba(144, 165, 196, 0.28);
  opacity: 0;
  pointer-events: none;
  transform: translate(6px, -50%) rotate(45deg);
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.layout.sidebar-collapsed .nav-list a[data-nav-label]:hover::after,
.layout.sidebar-collapsed .nav-list a[data-nav-label]:focus-visible::after,
.layout.sidebar-collapsed .nav-list a[data-nav-label]:hover::before,
.layout.sidebar-collapsed .nav-list a[data-nav-label]:focus-visible::before {
  opacity: 1;
  transform: translate(0, -50%);
}

.content {
  display: grid;
  gap: 16px;
}

.hidden { display: none !important; }

.hero,
.controls,
.focus-card,
.signal-panel,
.table-panel,
.excel-source-panel,
.logic-editor,
.change-log-panel,
.logic-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  padding: 24px 26px;
}

.hero.compact {
  padding: 22px 24px;
}

.hero-copy {
  max-width: 760px;
}

.eyebrow,
.section-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(15, 109, 137, 0.09);
  color: var(--brand);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 14px 0 10px;
  font-size: clamp(24px, 2.8vw, 40px);
  line-height: 1.08;
  letter-spacing: -0.04em;
}

.hero-subtitle {
  margin: 0;
  max-width: 720px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.logic-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.logic-rollup-panel {
  margin-top: 16px;
  overflow: hidden;
  border-radius: 28px;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(230, 246, 249, 0.76));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.logic-rollup-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 18px 22px 22px;
}

.logic-rollup-grid article {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.78);
}

.logic-rollup-grid .material-symbols-outlined {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(15, 109, 137, 0.1);
  color: var(--brand);
  font-size: 20px;
}

.logic-rollup-grid h3 {
  margin: 12px 0 8px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.25;
}

.logic-rollup-grid p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.logic-editor {
  margin-top: 16px;
  overflow: hidden;
}

.change-log-panel {
  margin-top: 16px;
  overflow: hidden;
}

.change-log-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.change-log-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.change-log-list {
  display: grid;
  gap: 12px;
  max-height: 520px;
  overflow: auto;
  padding: 18px 22px 22px;
}

.change-log-empty {
  padding: 16px;
  border: 1px dashed var(--line-strong);
  border-radius: 18px;
  color: var(--muted);
  background: rgba(246, 249, 255, 0.78);
  font-size: 13px;
}

.change-log-item {
  padding: 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
}

.change-log-item.logic-change {
  border-color: rgba(15, 109, 137, 0.2);
  background: linear-gradient(135deg, rgba(235, 248, 252, 0.88), rgba(255, 255, 255, 0.86));
}

.change-log-item.plan-edit {
  border-color: rgba(214, 142, 22, 0.2);
  background: linear-gradient(135deg, rgba(255, 249, 239, 0.88), rgba(255, 255, 255, 0.86));
}

.change-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--brand-deep);
  font-weight: 800;
}

.change-log-head time {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.change-log-item p {
  margin: 10px 0 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
}

.change-log-item ul {
  margin: 10px 0 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.change-log-item small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.logic-editor-body {
  padding: 18px 22px 22px;
}

.logic-form-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
}

.logic-form-grid label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.logic-form-grid input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 10px 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.9);
  font: inherit;
  font-weight: 700;
  outline: none;
}

.logic-form-grid input:focus {
  border-color: rgba(15, 109, 137, 0.55);
  box-shadow: 0 0 0 4px rgba(15, 109, 137, 0.1);
}

.logic-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.logic-current-summary,
.logic-preview {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(246, 249, 255, 0.88);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.logic-preview strong,
.logic-current-summary strong {
  color: var(--brand-deep);
}

.logic-preview-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.logic-preview-metric {
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
}

.logic-preview-metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.logic-preview-metric b {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 18px;
}

.logic-preview-metric small {
  display: block;
  margin-top: 4px;
  color: var(--brand);
  font-weight: 800;
}

.logic-card {
  padding: 22px;
  position: relative;
}

.logic-card.highlight {
  grid-column: span 2;
  background:
    linear-gradient(135deg, rgba(15, 109, 137, 0.12), rgba(255, 255, 255, 0.88)),
    var(--panel);
}

.logic-card-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}

.logic-card-edit-btn,
.logic-card-reset-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--brand-deep);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.logic-card-edit-btn:hover,
.logic-card-reset-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(15, 109, 137, 0.28);
  background: rgba(235, 248, 252, 0.96);
}

.logic-card-edit-btn.primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  color: white;
}

.logic-card-content {
  border-radius: 18px;
  outline: 2px solid transparent;
  outline-offset: 8px;
}

.logic-card.editing .logic-card-content {
  outline-color: rgba(15, 109, 137, 0.28);
  background: rgba(235, 248, 252, 0.44);
}

.logic-card-content[contenteditable="true"] {
  cursor: text;
}

.logic-card h2 {
  margin: 14px 0 12px;
  font-size: 20px;
  letter-spacing: -0.02em;
}

.logic-card ul,
.logic-card ol {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.logic-card li + li {
  margin-top: 6px;
}

.logic-formula {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(15, 109, 137, 0.14);
  background: rgba(235, 248, 252, 0.82);
  color: var(--brand-deep);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.55;
}

.hero-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
  flex-shrink: 0;
}

.source-box {
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(246, 249, 255, 0.88);
  white-space: nowrap;
}

.source-box span {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.source-box p {
  margin: 0;
  font-size: 11px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }

.bd-status-box { border-color: rgba(99,102,241,0.25); background: rgba(238,242,255,0.7); }
.bd-status-text.ok { color: #16a34a; font-weight: 600; }
.bd-status-text.err { color: var(--danger); font-weight: 600; }
.bd-refresh-btn { display: flex; align-items: center; gap: 5px; border-color: rgba(99,102,241,0.35); color: #4338ca; }
.bd-refresh-btn:hover { background: rgba(99,102,241,0.08); border-color: rgba(99,102,241,0.55); }

.lot-placeholder-row td {
  background: rgba(255, 248, 232, 0.72);
}

.lot-placeholder-row .table-edit-input {
  border-color: rgba(209, 111, 20, 0.28);
  background: rgba(255, 252, 245, 0.92);
}

.btn,
.icon-btn {
  cursor: pointer;
  border-radius: 16px;
  font: inherit;
}

.btn {
  height: 46px;
  padding: 0 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(18, 35, 63, 0.1);
  border-color: var(--line-strong);
}

.btn.primary {
  color: #fff;
  border: none;
  background: linear-gradient(135deg, var(--brand-deep), var(--brand));
}

.btn.danger {
  color: #fff;
  border: none;
  background: linear-gradient(135deg, #b81919, #ef3b2d);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  background: #fff;
  display: grid;
  place-items: center;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  padding: 16px;
}

.compact-controls .filter-summary {
  flex: 1 1 100%;
  order: 99;
}

.catalog-channel-control {
  flex: 0 0 240px;
  order: 98;
}

#catalogChannelFilter {
  min-width: 190px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

select,
input[type="month"],
input[type="text"],
input[type="url"],
input[type="number"],
input[type="file"] {
  min-width: 162px;
  height: 44px;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  font: inherit;
}

input[type="file"] {
  display: flex;
  align-items: center;
  padding: 10px 12px;
}

.capacity-note-input {
  width: 100%;
  min-width: 220px;
  min-height: 54px;
  resize: vertical;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  line-height: 1.45;
}

.capacity-cell-input {
  width: 100%;
  min-width: 110px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
}

.table-edit-input {
  width: 100%;
  min-width: 86px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

.table-edit-input.name {
  min-width: 220px;
}

.table-edit-input:hover,
.table-edit-input:focus {
  border-color: rgba(15, 109, 137, 0.34);
  background: rgba(255, 255, 255, 0.92);
  outline: 2px solid rgba(15, 109, 137, 0.12);
}

.capacity-cell-input.number {
  text-align: right;
}

.capacity-note-input:focus,
.capacity-cell-input:focus {
  outline: 2px solid rgba(15, 109, 137, 0.18);
  border-color: rgba(15, 109, 137, 0.45);
}

.capacity-system-note {
  margin-top: 6px;
  color: var(--danger);
  font-size: 11px;
  font-weight: 800;
}

/* ── Capacity Report ──────────────────────────────────────── */
.cap-report-panel { grid-column: 1 / -1; margin-top: 12px; }

.cap-report-kpi {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.cap-kpi-card {
  flex: 1 1 140px;
  min-width: 120px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cap-kpi-card.danger { border-color: #f87171; background: rgba(239,68,68,0.06); }
.cap-kpi-card.warn { border-color: #f59e0b; background: rgba(245,158,11,0.07); }
.cap-kpi-card.ok { border-color: rgba(34,197,94,0.4); background: rgba(34,197,94,0.05); }
.cap-kpi-label { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.cap-kpi-value { font-size: 22px; font-weight: 800; color: var(--brand); line-height: 1.2; }
.cap-kpi-card.danger .cap-kpi-value { color: var(--danger); }
.cap-kpi-card.warn .cap-kpi-value { color: #d97706; }
.cap-kpi-card.ok .cap-kpi-value { color: #16a34a; }

.cap-report-insights {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cap-insights-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--brand);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.cap-insight-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  line-height: 1.5;
  padding: 6px 10px;
  border-radius: 7px;
}
.cap-insight-danger { background: rgba(239,68,68,0.08); color: #b91c1c; border-left: 3px solid #ef4444; }
.cap-insight-warn   { background: rgba(245,158,11,0.08); color: #92400e; border-left: 3px solid #f59e0b; }
.cap-insight-info   { background: rgba(99,102,241,0.07); color: #3730a3; border-left: 3px solid #6366f1; }
.cap-insight-ok     { background: rgba(34,197,94,0.06); color: #166534; border-left: 3px solid #22c55e; }
.cap-insight-icon   { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

.cap-report-section-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  color: var(--brand);
  padding: 14px 20px 6px;
  border-top: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cap-report-matrix-scroll { overflow-x: auto; }
.cap-report-matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.cap-report-matrix th,
.cap-report-matrix td {
  padding: 7px 10px;
  border: 1px solid var(--border);
  white-space: nowrap;
  text-align: center;
}
.cap-report-matrix thead th {
  background: var(--surface);
  font-weight: 700;
  font-size: 11.5px;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
  z-index: 1;
}
.cap-matrix-subhead th { background: rgba(15,109,137,0.04); }
.cap-matrix-sub { font-size: 10px; font-weight: 500; color: var(--text-muted); text-transform: none; letter-spacing: 0; }
.cap-report-matrix tfoot td { background: rgba(15,109,137,0.06); font-size: 12px; }
.cap-line-code { font-weight: 700; text-align: left !important; color: var(--brand); }
.cap-line-group { text-align: left !important; font-size: 12px; color: var(--text-muted); }

.cap-report-cell {
  position: relative;
  min-width: 100px;
}
.cap-cell-pct { display: block; font-weight: 700; font-size: 13px; }
.cap-cell-detail { display: block; font-size: 10px; color: var(--text-muted); margin-top: 1px; }
.cap-cell-danger { background: rgba(239,68,68,0.1); color: #b91c1c; }
.cap-cell-warn   { background: rgba(245,158,11,0.08); color: #92400e; }
.cap-cell-ok     { background: rgba(34,197,94,0.05); }
.cap-cell-empty  { color: var(--text-muted); }

.cap-util-bar { height: 3px; background: rgba(15,109,137,0.12); border-radius: 2px; margin-top: 3px; overflow: hidden; }
.cap-util-fill { height: 100%; background: var(--brand); border-radius: 2px; transition: width 0.3s; }
.cap-util-fill.over { background: var(--danger); }

.cap-row-danger { border-left: 3px solid #ef4444; }
.cap-row-warn   { border-left: 3px solid #f59e0b; }
.cap-row-idle   { border-left: 3px solid #94a3b8; opacity: 0.75; }
.cap-total-cell { background: rgba(15,109,137,0.05); }
.cap-matrix-total td { background: rgba(15,109,137,0.08); font-weight: 700; }

.cap-line-summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.cap-line-summary-table th,
.cap-line-summary-table td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}
.cap-line-summary-table th {
  background: var(--surface);
  font-weight: 700;
  font-size: 11.5px;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
  z-index: 1;
}
.cap-line-summary-table td.num { text-align: right; }

.cap-status-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cap-status-danger { background: rgba(239,68,68,0.12); color: #b91c1c; }
.cap-status-warn   { background: rgba(245,158,11,0.12); color: #92400e; }
.cap-status-idle   { background: rgba(148,163,184,0.15); color: #475569; }
.cap-status-ok     { background: rgba(34,197,94,0.1); color: #166534; }

.cap-shift-panel {
  margin: 12px 20px 16px;
  padding: 16px;
  border: 1px solid rgba(245, 158, 11, 0.24);
  border-radius: 22px;
  background:
    linear-gradient(135deg, rgba(255, 247, 237, 0.94), rgba(236, 253, 245, 0.68)),
    var(--card);
  box-shadow: 0 14px 34px rgba(15, 43, 89, 0.08);
}

.cap-shift-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 12px;
}

.cap-shift-head h3,
.cap-shift-empty h3 {
  margin: 6px 0 0;
  font-size: 16px;
  line-height: 1.25;
}

.cap-shift-head p,
.cap-shift-empty p {
  max-width: 680px;
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.55;
}

.cap-shift-table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  table-layout: fixed;
  background: rgba(255, 255, 255, 0.72);
  border-radius: 16px;
  overflow: hidden;
}

.cap-shift-table th,
.cap-shift-table td {
  padding: 9px 10px;
  border: 1px solid rgba(144, 165, 196, 0.18);
  font-size: 11px;
  vertical-align: top;
}

.cap-shift-table th {
  background: rgba(255, 251, 235, 0.92);
  color: #7c4a03;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.cap-shift-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cap-shift-lot {
  display: block;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 10px;
}

.cap-shift-empty {
  border-color: rgba(144, 165, 196, 0.2);
  background: rgba(255, 255, 255, 0.72);
}

.capacity-table-top,
.capacity-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.capacity-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn.mini {
  min-height: 34px;
  padding: 8px 12px;
  font-size: 12px;
}

.filter-summary {
  flex: 1 1 320px;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(15, 109, 137, 0.08), rgba(16, 179, 163, 0.06));
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.plan-month-filter {
  display: grid;
  gap: 10px;
  padding: 0 18px 16px;
  border-bottom: 1px solid var(--line);
}

.plan-month-filter-label {
  color: var(--brand);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.plan-month-filter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.plan-month-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
}

.plan-month-chip span {
  min-width: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(15, 109, 137, 0.08);
  color: var(--brand);
  font-size: 11px;
}

.plan-month-chip.active {
  border-color: rgba(14, 43, 89, 0.28);
  background: linear-gradient(135deg, rgba(14, 43, 89, 0.96), rgba(15, 109, 137, 0.92));
  color: #fff;
}

.plan-month-chip.active span {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.plan-month-filter-summary {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.excel-source-panel {
  margin-top: 16px;
  overflow: hidden;
}

.excel-source-body {
  display: grid;
  gap: 18px;
  padding: 18px 22px 22px;
}

.excel-upload-grid {
  display: grid;
  grid-template-columns: minmax(300px, 420px) auto minmax(320px, 1fr);
  gap: 14px;
  align-items: end;
}

.excel-file-picker input {
  width: 100%;
}

.excel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.excel-status {
  min-height: 48px;
}

.excel-status.ok {
  color: var(--ok);
}

.excel-status.err {
  color: var(--danger);
}

.excel-help-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.excel-help-grid article {
  min-height: 150px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.84), rgba(234, 247, 250, 0.68));
}

.excel-help-grid .material-symbols-outlined {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(15, 109, 137, 0.1);
  color: var(--brand);
}

.excel-help-grid h3 {
  margin: 12px 0 8px;
  font-size: 15px;
}

.excel-help-grid p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.excel-import-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.excel-summary-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
}

.excel-summary-card strong {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 13px;
}

.excel-summary-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.excel-summary-card.ok strong {
  color: var(--ok);
}

.excel-summary-card.missing strong {
  color: var(--danger);
}

.catalog-top-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 390px);
  grid-template-areas:
    "main chart";
  gap: 16px;
  align-items: start;
}

.stock-top-grid {
  display: grid;
  grid-template-columns: minmax(620px, 1fr) minmax(420px, 520px);
  gap: 16px;
  align-items: start;
}

.stock-top-main {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.sales-top-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) 470px;
  gap: 16px;
  align-items: stretch;
}

.sales-top-main {
  display: grid;
  gap: 16px;
}

.sales-ratio-panel {
  height: 100%;
}

.sales-ratio-panel {
  overflow: hidden;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(226, 247, 248, 0.9));
}

.sales-ratio-panel .table-top {
  padding: 18px 18px 6px;
}

.sales-ratio-panel h2 {
  font-size: 21px;
  line-height: 1.2;
}

.sales-ratio-wrap {
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 14px;
  padding: 0 18px 18px;
  min-height: 220px;
}

.sales-pie-wrap {
  min-height: 200px;
}

.sales-ratio-legend {
  align-content: center;
  max-height: 214px;
  overflow: auto;
  padding-right: 4px;
}

.sales-ratio-legend .catalog-legend-item {
  padding: 8px 10px;
  border-radius: 13px;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.sales-ratio-legend .catalog-legend-item:hover,
.sales-ratio-legend .catalog-legend-item:focus {
  border-color: rgba(36, 124, 157, 0.35);
  box-shadow: 0 10px 24px rgba(31, 55, 90, 0.12);
  outline: none;
  transform: translateY(-1px);
}

.sales-controls {
  align-items: end;
}

.sales-controls label {
  flex: 0 1 210px;
}

.sales-controls .filter-summary {
  flex-basis: 100%;
}

.stock-analysis-panel,
.stock-turnover-panel {
  overflow: hidden;
}

.stock-analysis-panel {
  min-height: 100%;
}

.stock-analysis-panel .table-top {
  padding-bottom: 8px;
}

.stock-analysis-panel .compact-ratio-wrap {
  grid-template-columns: 210px minmax(0, 1fr);
  padding: 0 16px 16px;
}

.stock-analysis-panel .compact-pie-wrap {
  min-height: 210px;
}

.stock-turnover-panel {
  grid-column: 1 / -1;
}

.stock-turnover-body {
  padding: 16px 18px 18px;
}

.stock-turnover-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: stretch;
}

.stock-turnover-chart-block {
  min-width: 0;
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(247, 250, 255, 0.92), rgba(255, 255, 255, 0.76));
}

.stock-turnover-note {
  margin-top: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.stock-warning-inline {
  margin-top: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 249, 239, 0.72), rgba(255, 255, 255, 0.82));
}

.stock-warning-inline-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.stock-warning-inline-head h3 {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  line-height: 1.3;
  text-align: right;
}

.stock-warning-copy {
  margin: 0 0 12px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
}

.stock-warning-list {
  display: grid;
  gap: 8px;
  max-height: 238px;
  overflow: auto;
  padding-right: 4px;
}

.stock-warning-item {
  display: grid;
  grid-template-columns: 210px minmax(140px, 1fr) 92px;
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.stock-warning-item:hover,
.stock-warning-item:focus {
  border-color: rgba(15, 109, 137, 0.34);
  box-shadow: 0 10px 24px rgba(14, 40, 84, 0.1);
  outline: none;
  transform: translateY(-1px);
}

.stock-warning-item strong {
  display: block;
  color: var(--brand-deep);
  font-size: 12px;
  line-height: 1.35;
  max-width: 100%;
}

.stock-warning-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.stock-warning-name {
  min-width: 0;
}

.stock-warning-name strong,
.stock-warning-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stock-warning-bar-track {
  height: 18px;
  overflow: hidden;
  border-radius: 0;
  background: rgba(31, 142, 205, 0.12);
}

.stock-warning-bar-fill {
  width: 0;
  height: 100%;
  background: #1f8ecd;
}

.stock-warning-value {
  display: grid;
  gap: 2px;
  justify-items: end;
  text-align: right;
}

.stock-warning-value strong {
  font-size: 12px;
  color: #1f355a;
}

.stock-warning-value span {
  font-size: 10px;
  font-weight: 800;
  color: var(--muted);
}

.stock-warning-badge {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #d16f14, #de4f3d);
}

.stock-warning-item.stock-risk-warn {
  border-color: transparent;
  background: transparent;
}

.stock-warning-item.stock-risk-warn .stock-warning-bar-fill {
  background: #d9861d;
}

.stock-warning-item.stock-risk-danger {
  border-color: transparent;
  background: transparent;
}

.stock-warning-item.stock-risk-danger .stock-warning-bar-fill {
  background: #de4f3d;
}

.stock-warning-item.stock-risk-critical {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.stock-warning-item.stock-risk-critical .stock-warning-bar-fill {
  background: #b42318;
}

.stock-warning-item.stock-risk-slow .stock-warning-bar-fill {
  background: #1f8ecd;
}

.stock-warning-item.stock-risk-warn .stock-warning-badge {
  background: linear-gradient(135deg, #d16f14, #f2aa2c);
}

.stock-warning-item.stock-risk-danger .stock-warning-badge {
  background: linear-gradient(135deg, #de4f3d, #b42318);
}

.stock-warning-item.stock-risk-critical .stock-warning-badge {
  background: linear-gradient(135deg, #7a1712, #de4f3d);
}

tr.stock-risk-warn td {
  background: rgba(255, 248, 232, 0.74);
}

tr.stock-risk-danger td {
  background: rgba(255, 242, 239, 0.82);
}

tr.stock-risk-critical td {
  background: rgba(255, 230, 225, 0.9);
  color: #8f1f16;
  font-weight: 800;
}

.stock-detail-turnover {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(247, 250, 255, 0.98), rgba(255, 255, 255, 0.98));
}

.stock-detail-headless {
  padding: 16px 18px;
}

.stock-detail-turnover-body {
  padding: 12px 16px 16px;
}

.spike-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.spike-summary-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(238, 248, 251, 0.94));
  box-shadow: var(--shadow-soft);
}

.spike-summary-card span,
.spike-summary-card small {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.spike-summary-card strong {
  display: block;
  margin: 8px 0 4px;
  color: var(--ink);
  font-size: 30px;
  line-height: 1;
}

.manual-spike-panel {
  margin-bottom: 16px;
}

.manual-spike-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 18px 14px;
}

.manual-spike-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
  padding: 0 18px 0;
}

.manual-spike-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.manual-spike-form input,
.manual-spike-form select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.manual-spike-status {
  margin: 12px 0;
  color: var(--muted);
  font-weight: 700;
}

.manual-spike-scroll {
  max-height: 340px;
}

.manual-entry-dialog {
  display: none;
}

.manual-entry-dialog.open {
  display: block;
  position: fixed;
  z-index: 110;
  inset: 0;
  background: rgba(10, 18, 38, 0.48);
}

.manual-entry-card {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(980px, calc(100vw - 48px));
  max-height: min(86vh, 760px);
  overflow: auto;
  transform: translate(-50%, -50%);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: 0 28px 90px rgba(16, 29, 61, 0.26);
  backdrop-filter: blur(18px);
}

.manual-entry-card .table-top {
  padding: 16px 18px 12px;
}

.spike-plan {
  min-width: 340px;
  white-space: normal;
  line-height: 1.6;
}

.spike-flag {
  display: inline-flex;
  margin: 2px 4px 2px 0;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(222, 79, 61, 0.1);
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
}

.spike-class {
  display: inline-flex;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(15, 109, 137, 0.1);
  color: #0f6d89;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.25;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.catalog-top-main {
  grid-area: main;
  display: grid;
  gap: 16px;
  min-width: 0;
}

.manual-catalog-panel {
  display: none;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  min-width: 0;
}

.manual-catalog-panel.open {
  display: block;
  position: fixed;
  z-index: 100;
  top: 50%;
  left: 50%;
  width: min(1120px, calc(100vw - 48px));
  max-height: min(86vh, 820px);
  overflow: auto;
  transform: translate(-50%, -50%);
  box-shadow: 0 28px 90px rgba(16, 29, 61, 0.26), 0 0 0 9999px rgba(10, 18, 38, 0.48);
}

.manual-catalog-panel .table-top {
  padding: 16px 18px 10px;
}

.manual-catalog-panel .table-top h2 {
  font-size: 18px;
  margin-top: 8px;
}

.manual-catalog-body {
  padding: 0 18px 16px;
}

/* ── LOGIN OVERLAY ─────────────────────────────────────────── */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 12% 8%, rgba(16, 179, 163, 0.18), transparent 28%),
    radial-gradient(circle at 88% 18%, rgba(15, 109, 137, 0.2), transparent 26%),
    linear-gradient(180deg, #f0f5fd 0%, #e4edf9 100%);
}

.login-overlay.hidden {
  display: none;
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(144,165,196,0.22);
  border-radius: 28px;
  padding: 36px 36px 32px;
  box-shadow: 0 24px 80px rgba(14,40,84,0.14);
  backdrop-filter: blur(16px);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.login-brand .brand-icon {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--brand-deep), var(--brand));
  display: grid;
  place-items: center;
  color: #fff;
}

.login-brand h2 {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 700;
  color: var(--brand-deep);
}

.login-brand p {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.login-title {
  margin: 0 0 22px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.login-field input,
.login-card input[type="text"],
.login-card input[type="password"] {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--line-strong);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.18s;
}

.login-field input:focus,
.login-card input:focus {
  border-color: var(--brand);
}

.password-wrapper {
  position: relative;
}

.password-wrapper input {
  padding-right: 46px;
}

.toggle-pwd-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  display: grid;
  place-items: center;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.15s;
}

.toggle-pwd-btn:hover { color: var(--brand); }

/* inside account-form the password-wrapper needs sizing */
.account-form .password-wrapper input { width: 100%; height: 38px; }

.login-error {
  margin-bottom: 14px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(222,79,61,0.08);
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
}

.login-submit-btn {
  width: 100%;
  height: 46px;
  font-size: 15px;
  margin-top: 4px;
}

/* ── SIDEBAR USER BAR ──────────────────────────────────────── */
.sidebar-user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 10px 8px 6px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-user-avatar {
  flex-shrink: 0;
  color: rgba(255,255,255,0.55);
  font-size: 32px;
  display: grid;
  place-items: center;
}

.sidebar-user-avatar .material-symbols-outlined { font-size: 32px; }

.sidebar-user-details {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.sidebar-user-name {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  margin-top: 3px;
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.7);
}

.sidebar-user-role.role-owner { background: rgba(212,142,22,0.28); color: #f5c842; }
.sidebar-user-role.role-admin { background: rgba(15,109,137,0.32); color: #6dd7f0; }
.sidebar-user-role.role-member { background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.65); }

.sidebar-logout-btn {
  flex-shrink: 0;
  color: rgba(255,255,255,0.5) !important;
}

.sidebar-logout-btn:hover {
  color: rgba(255,255,255,0.9) !important;
  background: rgba(255,255,255,0.1) !important;
}

.layout.sidebar-collapsed .sidebar-user-details,
.layout.sidebar-collapsed .sidebar-user-name,
.layout.sidebar-collapsed .sidebar-user-role { display: none; }

/* ── ACCOUNTS VIEW ─────────────────────────────────────────── */
.accounts-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 0 0 12px;
  box-shadow: 0 4px 20px rgba(14,40,84,0.06);
}

.accounts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.accounts-table thead tr {
  background: linear-gradient(90deg, var(--brand-deep), var(--brand));
  color: #fff;
}

.accounts-table thead th {
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}

.accounts-table thead th:first-child { border-radius: 0; }

.toggle-pwd-col-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.7);
  vertical-align: middle;
  padding: 0 0 0 4px;
  line-height: 1;
}
.toggle-pwd-col-btn:hover { color: #fff; }
.toggle-pwd-col-btn .material-symbols-outlined { font-size: 15px; vertical-align: middle; }

.pwd-cell { font-family: monospace; font-size: 13px; letter-spacing: 0.03em; }
.pwd-cell-inner { display: flex; align-items: center; gap: 4px; }
.pwd-row-eye {
  opacity: 1;
  padding: 3px 5px;
  border-radius: 6px;
  color: var(--brand);
  background: rgba(15,109,137,0.08);
  border: 1px solid rgba(15,109,137,0.2);
}
.pwd-row-eye:hover { background: rgba(15,109,137,0.18); }
.pwd-row-eye .material-symbols-outlined { font-size: 16px; display: block; }

.accounts-table tbody tr {
  border-bottom: 1px solid var(--line);
  transition: background 0.12s;
}

.accounts-table tbody tr:hover { background: rgba(15,109,137,0.04); }
.accounts-table tbody tr:last-child { border-bottom: none; }

.accounts-table tbody td {
  padding: 11px 14px;
  vertical-align: middle;
}

.role-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.role-badge.owner { background: rgba(212,142,22,0.14); color: #b87a0a; }
.role-badge.admin { background: rgba(15,109,137,0.12); color: var(--brand); }
.role-badge.member { background: rgba(21,154,102,0.12); color: var(--ok); }

.accounts-action-btns {
  display: flex;
  gap: 6px;
  align-items: center;
}

.accounts-action-btns .icon-btn {
  width: 30px;
  height: 30px;
  font-size: 16px;
}

.accounts-action-btns .icon-btn .material-symbols-outlined { font-size: 17px; }

/* ── ACCOUNT FORM MODAL ────────────────────────────────────── */
.account-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.account-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.account-form-grid .span2 { grid-column: span 2; }

.account-form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.account-form input,
.account-form select {
  height: 38px;
  padding: 0 10px;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
}

.account-form input:focus,
.account-form select:focus { border-color: var(--brand); }

.account-form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 4px;
}

/* ── HISTORY DOT & MODAL ───────────────────────────────────── */
.history-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 3px;
  vertical-align: middle;
  cursor: pointer;
  flex-shrink: 0;
}
.history-dot:hover { background: var(--brand); }

.row-history-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 60px;
}

.history-entry {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(15,109,137,0.05);
  border-left: 3px solid var(--brand);
}

.history-entry-icon {
  color: var(--brand);
  font-size: 18px;
  margin-top: 1px;
  flex-shrink: 0;
}

.history-entry-body { flex: 1; min-width: 0; }

.history-entry-who {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
}

.history-entry-time {
  font-size: 11.5px;
  color: var(--muted);
  margin-left: 6px;
}

.history-entry-detail {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
}

.history-entry-values {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  margin-top: 4px;
}

.history-val-before {
  text-decoration: line-through;
  color: var(--danger);
  font-weight: 600;
}
.history-val-after {
  color: var(--ok);
  font-weight: 700;
}

/* owner-locked filter */
#ownerFilter:disabled, select[disabled] {
  opacity: 0.75;
  cursor: not-allowed;
}
.owner-lock-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--brand);
  background: rgba(15,109,137,0.1);
  padding: 3px 8px;
  border-radius: 999px;
  margin-left: 6px;
}

@media (max-width: 680px) {
  .account-form-grid { grid-template-columns: 1fr; }
  .account-form-grid .span2 { grid-column: span 1; }
  .login-card { padding: 24px 20px 20px; }
}

/* ══════════════════════════════════════════════════════════════
   VIEWER MODE — read-only restrictions
══════════════════════════════════════════════════════════════ */
.viewer-mode #applyLogicBtn,
.viewer-mode #previewLogicBtn,
.viewer-mode #resetLogicBtn,
.viewer-mode #clearChangeLogBtn,
.viewer-mode #addManualCatalogBtn,
.viewer-mode .excel-import-actions button:not(.btn-secondary),
.viewer-mode [data-view="excel"] .btn.primary { display: none !important; }

.viewer-mode .logic-form-grid input,
.viewer-mode .table-edit-input { pointer-events: none; background: var(--bg) !important; color: var(--muted); }

.viewer-mode .plan-cell { cursor: default; }

/* viewer badge */
.role-badge.viewer { background: rgba(97,112,141,0.13); color: var(--muted); }
.sidebar-user-role.role-viewer { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.55); }

/* viewer banner */
.viewer-banner {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(97,112,141,0.12);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin-left: 12px;
}
.viewer-mode .viewer-banner { display: inline-flex; }

/* ══════════════════════════════════════════════════════════════
   UI REDESIGN — cleaner & more polished
══════════════════════════════════════════════════════════════ */

/* ── Sidebar improvements ─────────────────────────────────── */
.brand-card {
  background: rgba(255,255,255,0.06);
  border-radius: 16px;
  padding: 12px 10px;
  margin-bottom: 10px;
  border: 1px solid rgba(255,255,255,0.08);
}

.brand-card h2 { font-size: 13px; font-weight: 700; margin: 0 0 2px; }
.brand-card p  { font-size: 10px; line-height: 1.4; margin: 0; opacity: 0.65; }

.nav-title {
  font-size: 9.5px;
  letter-spacing: 0.12em;
  font-weight: 700;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  padding: 0 6px;
  margin: 8px 0 4px;
}

.nav-list a {
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 10px;
  gap: 9px;
  transition: background 0.15s, color 0.15s;
}

.nav-list a .material-symbols-outlined { font-size: 17px; }

.nav-list a:hover:not(.active) {
  background: rgba(255,255,255,0.07);
  color: #fff;
}

.nav-list a.active {
  background: linear-gradient(90deg, rgba(15,109,137,0.55), rgba(16,179,163,0.3));
  color: #fff;
  font-weight: 600;
}

/* ── Hero / section header ────────────────────────────────── */
.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 18px;
  background: linear-gradient(135deg, rgba(255,255,255,0.9) 0%, rgba(240,247,255,0.95) 100%);
  border: 1px solid var(--line);
  border-radius: 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 12px rgba(14,40,84,0.05);
}

.eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand);
  background: rgba(15,109,137,0.09);
  padding: 3px 9px;
  border-radius: 999px;
  display: inline-block;
  margin-bottom: 6px;
}

.hero h1 {
  font-size: 22px;
  font-weight: 800;
  margin: 0 0 5px;
  line-height: 1.2;
  color: var(--brand-deep);
}

.hero-subtitle { font-size: 13px; color: var(--muted); margin: 0; max-width: 560px; line-height: 1.5; }

.hero-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: nowrap;
}

.source-box {
  font-size: 11px;
  text-align: left;
  padding: 7px 11px;
  border-radius: 12px;
}

.source-box span { color: var(--muted); font-weight: 600; font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ── Section tags ─────────────────────────────────────────── */
.section-tag {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand);
  background: rgba(15,109,137,0.09);
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 6px;
}

/* ── Filter / controls bar ────────────────────────────────── */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 18px;
  background: rgba(255,255,255,0.75);
  border: 1px solid var(--line);
  border-radius: 16px;
  margin-bottom: 16px;
  backdrop-filter: blur(8px);
  align-items: flex-end;
}

.controls label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.controls input,
.controls select {
  height: 34px;
  padding: 0 10px;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  min-width: 120px;
  transition: border-color 0.15s;
}

.controls input:focus,
.controls select:focus { border-color: var(--brand); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  height: 36px;
  padding: 0 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--line-strong);
  background: rgba(255,255,255,0.9);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.btn:hover {
  background: #fff;
  border-color: rgba(15,109,137,0.35);
  box-shadow: 0 2px 8px rgba(14,40,84,0.08);
}

.btn.primary {
  background: linear-gradient(135deg, var(--brand-deep), var(--brand));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 10px rgba(15,109,137,0.3);
}

.btn.primary:hover {
  background: linear-gradient(135deg, #0c2249, var(--brand-deep));
  box-shadow: 0 4px 14px rgba(15,109,137,0.38);
}

.btn.danger { border-color: rgba(222,79,61,0.35); color: var(--danger); }
.btn.danger:hover { background: rgba(222,79,61,0.06); border-color: var(--danger); }

/* ── Table panels ─────────────────────────────────────────── */
.table-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 20px 12px;
  gap: 12px;
  flex-wrap: wrap;
}

.table-top h2 {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

/* ── KPI Cards ───────────────────────────────────────────── */
.focus-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px 20px;
  box-shadow: 0 2px 12px rgba(14,40,84,0.05);
  transition: box-shadow 0.18s, transform 0.18s;
}

.focus-card:hover {
  box-shadow: 0 6px 24px rgba(14,40,84,0.1);
  transform: translateY(-1px);
}

/* ── Content layout spacing ───────────────────────────────── */
.content { gap: 0; }

section > section { margin-bottom: 16px; }

/* ── Icon buttons ─────────────────────────────────────────── */
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1.5px solid var(--line-strong);
  background: rgba(255,255,255,0.9);
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: #fff;
  color: var(--brand);
  border-color: rgba(15,109,137,0.35);
}

.manual-linked-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed rgba(102, 126, 164, 0.36);
}

.manual-linked-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}

.manual-linked-head h3 {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.25;
}

.manual-catalog-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.manual-catalog-sync-grid {
  margin-top: 10px;
}

.manual-catalog-grid label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.manual-catalog-grid input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font: inherit;
  outline: none;
}

.manual-catalog-grid input:focus {
  border-color: rgba(15, 109, 137, 0.55);
  box-shadow: 0 0 0 4px rgba(15, 109, 137, 0.1);
}

.manual-catalog-endpoint {
  grid-column: 1 / -1;
}

.manual-catalog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.table-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.add-inline-btn,
.icon-action-btn {
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  box-shadow: 0 10px 24px rgba(28, 46, 86, 0.08);
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.add-inline-btn {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.icon-action-btn {
  width: 38px;
  height: 38px;
  border-radius: 14px;
  font-size: 24px;
  font-weight: 800;
}

.add-inline-btn:hover,
.icon-action-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(15, 109, 137, 0.52);
  background: rgba(231, 247, 249, 0.96);
}

.manual-catalog-status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.manual-catalog-status.ok {
  color: var(--ok);
  font-weight: 700;
}

.manual-catalog-status.err {
  color: var(--danger);
  font-weight: 700;
}

.catalog-chart-panel {
  padding: 18px;
  align-self: start;
  min-width: 0;
}

.catalog-distribution-panel {
  grid-area: chart;
  position: sticky;
  top: 18px;
}

.catalog-chart-wrap {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.catalog-distribution-panel .catalog-chart-wrap {
  grid-template-columns: 1fr;
  gap: 12px;
}

#lotView:not(.hidden) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 430px);
  gap: 16px;
  align-items: start;
}

#lotView > .hero,
#lotView > .controls {
  grid-column: 1 / 2;
}

#lotView > .panel.table-panel:first-of-type {
  grid-column: 2 / 3;
  grid-row: 1 / span 2;
  height: 100%;
}

#lotView > .panel.table-panel:last-of-type {
  grid-column: 1 / -1;
}

#lotView .compact-ratio-wrap {
  grid-template-columns: 1fr;
  gap: 12px;
}

#lotView .compact-pie-wrap {
  min-height: 220px;
}

#capacityView:not(.hidden) {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(360px, 430px) minmax(360px, 430px);
  gap: 16px;
  align-items: stretch;
}

#capacityView > .hero {
  grid-column: 1 / 2;
  min-height: 170px;
}

#capacityView > .catalog-chart-panel {
  grid-column: 2 / 3;
  min-height: 170px;
}

.capacity-guidance-panel {
  grid-column: 3 / 4;
  min-height: 170px;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.capacity-guidance-panel h2 {
  margin: 12px 0 10px;
  font-size: 22px;
  line-height: 1.16;
}

.capacity-guidance-panel p {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.65;
}

#capacityView > .table-panel {
  grid-column: 1 / -1;
}

#capacityView .catalog-chart-panel .table-top {
  padding: 0 0 8px;
}

#capacityView .catalog-chart-panel h2 {
  font-size: 20px;
  line-height: 1.2;
}

#capacityView .compact-ratio-wrap {
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 12px;
}

#capacityView .compact-pie-wrap {
  min-height: 180px;
}

#capacityView .compact-pie-wrap canvas {
  max-width: 200px;
  max-height: 200px;
}

#capacityRatioLegend .catalog-legend-item {
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

#capacityRatioLegend .catalog-legend-item:hover,
#capacityRatioLegend .catalog-legend-item:focus {
  border-color: rgba(15, 109, 137, 0.42);
  box-shadow: 0 10px 24px rgba(14, 40, 84, 0.1);
  outline: none;
  transform: translateY(-1px);
}

.catalog-pie-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 210px;
  padding: 0;
}

.catalog-distribution-panel .catalog-pie-wrap {
  min-height: 190px;
}

.catalog-distribution-panel canvas {
  max-width: 220px;
  max-height: 220px;
}

.catalog-distribution-panel .catalog-legend {
  max-height: 210px;
  overflow: auto;
  padding-right: 4px;
}

.catalog-legend {
  display: grid;
  gap: 8px;
}

.catalog-legend-item {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
}

.catalog-legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 999px;
}

.catalog-legend-label {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.catalog-legend-value {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.catalog-chart-empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.compact-ratio-wrap {
  grid-template-columns: 220px minmax(0, 1fr);
}

.compact-pie-wrap {
  min-height: 220px;
}

.turnover-panel {
  grid-column: 1 / 2;
}

.turnover-wrap {
  min-height: 320px;
  padding: 14px 12px 10px;
}

.logic-source-panel {
  padding: 18px 22px 22px;
}

.logic-hero {
  align-items: stretch;
  flex-wrap: wrap;
}

.logic-hero .hero-copy {
  flex: 1 1 620px;
}

.logic-source-panel-hero {
  flex: 0 1 430px;
  min-width: 340px;
  max-width: 520px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.86), rgba(234, 247, 250, 0.74));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.52);
}

.logic-source-head {
  margin-bottom: 10px;
}

.logic-source-head h2 {
  margin: 8px 0 0;
  color: var(--text);
  font-size: 17px;
  line-height: 1.25;
}

.logic-source-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding-right: 4px;
}

.logic-source-item {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.82);
  overflow: hidden;
}

.logic-source-item summary {
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  list-style: none;
}

.logic-source-item summary::-webkit-details-marker {
  display: none;
}

.logic-source-item summary::after {
  content: "expand_more";
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(15, 109, 137, 0.08);
  color: var(--brand);
  font-family: "Material Symbols Outlined";
  font-size: 18px;
  line-height: 1;
}

.logic-source-item[open] summary::after {
  content: "expand_less";
}

.logic-source-title {
  color: var(--brand-deep);
  font-size: 14px;
  line-height: 1.25;
  font-weight: 800;
}

.logic-source-sheet {
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(19, 35, 63, 0.06);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.logic-source-detail {
  padding: 0 14px 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.logic-source-detail p {
  margin: 0 0 10px;
}

.logic-source-detail dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.logic-source-detail dl > div {
  display: grid;
  gap: 4px;
}

.logic-source-detail dt {
  color: var(--text);
  font-weight: 800;
}

.logic-source-detail dd {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
}

.logic-source-detail dd span {
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(15, 109, 137, 0.08);
  color: var(--brand-deep);
  font-size: 11px;
  font-weight: 700;
}

.logic-source-link {
  margin-top: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  border-radius: 12px;
  background: var(--brand-deep);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.logic-source-link .material-symbols-outlined {
  font-size: 16px;
}

.logic-source-item a:not(.logic-source-link) {
  color: var(--brand);
  word-break: break-all;
  text-decoration: none;
}

.logic-source-item small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.insights {
  display: grid;
  grid-template-columns: minmax(720px, 1fr) clamp(430px, 29vw, 500px);
  gap: 16px;
  align-items: start;
  transition: grid-template-columns 0.22s ease;
}

.insights.alerts-collapsed {
  grid-template-columns: minmax(720px, 1fr) 72px;
}

.overview-main-stack {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.focus-card,
.signal-panel,
.chart-panel {
  padding: 18px;
}

.focus-card {
  grid-column: auto;
}

.focus-head,
.signal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.focus-head h3,
.signal-head h3 {
  margin: 10px 0 0;
  font-size: 18px;
  line-height: 1.18;
}

.signal-title-toggle {
  cursor: pointer;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 800;
  text-align: inherit;
}

.signal-title-toggle::after {
  content: "keyboard_double_arrow_right";
  display: inline-grid;
  place-items: center;
  margin-left: 8px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(15, 109, 137, 0.08);
  color: var(--brand);
  font-family: "Material Symbols Outlined";
  font-size: 18px;
  vertical-align: middle;
}

.chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(19, 35, 63, 0.06);
  color: #44536e;
  font-size: 11px;
  font-weight: 700;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.kpi {
  min-height: 88px;
  padding: 12px 14px 10px;
  border-radius: 16px;
  border: 1px solid rgba(223, 228, 244, 0.85);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 251, 255, 0.94));
  box-shadow: 0 10px 24px rgba(15, 32, 68, 0.05);
}

.kpi.actionable {
  cursor: pointer;
}

.kpi:nth-child(1) {
  background: linear-gradient(135deg, rgba(255, 242, 239, 0.98), rgba(255, 249, 247, 0.94));
}

.kpi:nth-child(2) {
  background: linear-gradient(135deg, rgba(255, 248, 226, 0.98), rgba(255, 252, 243, 0.94));
}

.kpi:nth-child(3) {
  background: linear-gradient(135deg, rgba(237, 250, 255, 0.98), rgba(247, 252, 255, 0.94));
}

.kpi:nth-child(4) {
  background: linear-gradient(135deg, rgba(240, 247, 255, 0.98), rgba(248, 251, 255, 0.94));
}

.kpi:nth-child(5) {
  background: linear-gradient(135deg, rgba(240, 255, 249, 0.98), rgba(248, 255, 252, 0.94));
}

.kpi.hidden-kpi {
  display: none;
}

.kpi-head {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--brand-deep);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
}

.kpi-head .material-symbols-outlined {
  width: 24px;
  height: 24px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.65);
  font-size: 16px;
}

.kpi .value {
  margin-top: 8px;
  font-size: clamp(16px, 1.28vw, 21px);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.04em;
}

.kpi .note {
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
}

.chart-wrap {
  padding: 18px 16px 10px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(245, 249, 255, 0.88), rgba(255, 255, 255, 0.62));
  border: 1px solid rgba(144, 165, 196, 0.16);
}

.chart-wrap.large {
  min-height: 360px;
  overflow-x: auto;
}

.chart-panel {
  grid-column: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel-head h3 {
  margin: 10px 0 0;
  font-size: 18px;
  line-height: 1.2;
}

.chart-panel .panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.line-chart-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0 14px;
}

.line-chart-summary article {
  min-height: 74px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(241, 248, 255, 0.78));
}

.line-chart-summary span,
.line-chart-summary em {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  line-height: 1.35;
}

.line-chart-summary strong {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 20px;
  line-height: 1.15;
}

.line-chart-summary article.ok {
  border-color: rgba(21, 154, 102, 0.24);
  background: linear-gradient(135deg, rgba(240, 253, 248, 0.96), rgba(255, 255, 255, 0.8));
}

.line-chart-summary article.danger {
  border-color: rgba(222, 79, 61, 0.28);
  background: linear-gradient(135deg, rgba(255, 243, 240, 0.96), rgba(255, 255, 255, 0.82));
}

.line-chart-summary article.danger strong,
.line-chart-summary article.danger em {
  color: var(--danger);
}

.chart-action-filter {
  min-width: 180px;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.chart-action-filter select {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
}

.signal-panel {
  grid-column: auto;
  grid-row: auto;
  display: grid;
  align-content: start;
  padding: 18px 16px 16px;
  position: sticky;
  top: 18px;
  transition: padding 0.2s ease, min-height 0.2s ease;
}

.signal-panel.collapsed {
  min-height: 420px;
  padding: 14px 10px;
  overflow: hidden;
}

.signal-panel.collapsed .signal-head {
  height: 100%;
  margin: 0;
  justify-content: center;
  align-items: center;
}

.signal-panel.collapsed .section-tag,
.signal-panel.collapsed .alert-grid {
  display: none;
}

.signal-panel.collapsed h3 {
  margin: 0;
}

.signal-panel.collapsed .signal-title-toggle {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
  text-align: center;
}

.signal-panel.collapsed .signal-title-toggle::after {
  content: "keyboard_double_arrow_left";
  margin: 8px 0 0;
  transform: rotate(90deg);
}

.alert-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.alert-card {
  padding: 14px 16px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  min-height: 112px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.alert-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(18, 35, 63, 0.08);
  border-color: var(--line-strong);
}

.alert-top {
  margin-bottom: 10px;
}

.alert-value {
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
}

.alert-text {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.38;
}

.alert-text strong {
  display: block;
  margin-bottom: 4px;
  color: var(--brand-deep);
  font-size: 12px;
}

#inventoryChart {
  display: block;
  min-width: 100%;
}

.alert-card.err {
  background: linear-gradient(180deg, rgba(255, 247, 246, 0.98), rgba(255, 255, 255, 0.94));
  border-color: rgba(222, 79, 61, 0.2);
}

.alert-card.info {
  background: linear-gradient(180deg, rgba(241, 248, 255, 0.98), rgba(255, 255, 255, 0.94));
  border-color: rgba(54, 122, 197, 0.18);
}

.alert-card.warn {
  background: linear-gradient(180deg, rgba(255, 249, 239, 0.98), rgba(255, 255, 255, 0.94));
  border-color: rgba(212, 142, 22, 0.2);
}

.alert-card.ok {
  background: linear-gradient(180deg, rgba(243, 252, 249, 0.98), rgba(255, 255, 255, 0.94));
  border-color: rgba(21, 154, 102, 0.2);
}

.alert-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-icon {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 18px;
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.78);
}

.alert-card.err .alert-icon { color: var(--danger); }
.alert-card.warn .alert-icon { color: var(--warn); }
.alert-card.ok .alert-icon { color: var(--ok); }
.alert-card.info .alert-icon { color: var(--brand); }

.alert-value {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.05;
}

.alert-card.err .alert-value { color: var(--danger); }
.alert-card.warn .alert-value { color: var(--warn); }
.alert-card.ok .alert-value { color: var(--brand-deep); }

.alert-text {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.table-panel {
  overflow: hidden;
}

.report-panel {
  overflow: hidden;
}

.sheet-shell {
  margin: 0 18px 18px;
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid rgba(149, 176, 118, 0.25);
  background: #ffffff;
}

.sheet-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  background: linear-gradient(180deg, #f4fbf1, #edf8e7);
  border-bottom: 1px solid rgba(149, 176, 118, 0.25);
}

.sheet-chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 999px;
  background: #dff2d6;
  color: #2c6a34;
  font-size: 12px;
  font-weight: 700;
}

.sheet-note {
  color: #577060;
  font-size: 12px;
}

.sheet-table {
  min-width: 1080px;
}

.sheet-table th {
  background: #eef8e9;
  color: #284229;
  border-bottom: 1px solid rgba(126, 156, 102, 0.4);
}

.sheet-table td,
.sheet-table th {
  text-align: left;
}

.table-top {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.table-top h2 {
  margin: 10px 0 0;
  font-size: 18px;
  line-height: 1.2;
}

.table-scroll {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 10px 8px;
  border-right: 1px solid rgba(144, 165, 196, 0.14);
  border-bottom: 1px solid rgba(144, 165, 196, 0.14);
  font-size: 11px;
  white-space: normal;
  word-break: break-word;
  text-align: center;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(244, 248, 254, 0.98);
  color: #506082;
  font-weight: 700;
  user-select: none;
  position: sticky;
}

td.name {
  min-width: 180px;
  text-align: left;
}

.table-name-action {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-align: left;
}

.table-name-action:hover {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 3px;
}

th.resizable {
  position: sticky;
  padding-right: 18px;
}

.th-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.th-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-resizer {
  width: 10px;
  align-self: stretch;
  cursor: col-resize;
  position: relative;
  flex: 0 0 10px;
}

.col-resizer::after {
  content: "";
  position: absolute;
  top: 5px;
  bottom: 5px;
  left: 4px;
  width: 2px;
  border-radius: 999px;
  background: rgba(80, 96, 130, 0.24);
}

th:hover .col-resizer::after {
  background: rgba(15, 109, 137, 0.55);
}

.warn {
  color: var(--warn);
  font-weight: 700;
}

.err {
  color: var(--danger);
  font-weight: 700;
}

.plan-cell {
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 650;
  min-width: 64px;
  padding: 7px 10px;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.plan-qlxk-row td {
  background: rgba(245, 239, 255, 0.48);
}

.plan-qlxk-row td.name {
  box-shadow: inset 4px 0 0 rgba(126, 51, 202, 0.58);
}

.plan-cell-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
}

.plan-cell:hover {
  background: rgba(15, 109, 137, 0.08);
  box-shadow: inset 0 0 0 1px rgba(15, 109, 137, 0.16);
}

.plan-cell.has-plan {
  background: rgba(214, 145, 25, 0.12);
  color: var(--warn);
}

.plan-cell.has-plan:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(214, 145, 25, 0.14), inset 0 0 0 1px rgba(214, 145, 25, 0.22);
}

.plan-cell.risk {
  background: rgba(222, 79, 61, 0.13);
  color: var(--danger);
  box-shadow: inset 0 0 0 1px rgba(222, 79, 61, 0.2);
}

.plan-cell.risk:hover {
  box-shadow: 0 8px 18px rgba(222, 79, 61, 0.14), inset 0 0 0 1px rgba(222, 79, 61, 0.3);
}

.plan-cell.business-signal {
  box-shadow: inset 0 0 0 1px rgba(214, 145, 25, 0.24), 0 0 0 3px rgba(214, 145, 25, 0.08);
}

.plan-cell.qlxk-risk {
  background: rgba(126, 51, 202, 0.12);
  color: #7e33ca;
  box-shadow: inset 0 0 0 1px rgba(126, 51, 202, 0.26), 0 0 0 3px rgba(126, 51, 202, 0.08);
}

.plan-cell.qlxk-risk:hover {
  box-shadow: 0 8px 18px rgba(126, 51, 202, 0.14), inset 0 0 0 1px rgba(126, 51, 202, 0.34);
}

.plan-cell.manual {
  background: rgba(31, 142, 205, 0.12);
  color: #176fa4;
  box-shadow: inset 0 0 0 1px rgba(31, 142, 205, 0.24);
}

.plan-cell.manual.risk {
  background: linear-gradient(135deg, rgba(222, 79, 61, 0.13), rgba(31, 142, 205, 0.12));
  color: var(--danger);
}

.plan-cell.capacity-adjusted {
  box-shadow: inset 0 0 0 1px rgba(15, 109, 137, 0.24), 0 0 0 3px rgba(15, 109, 137, 0.08);
}

.plan-cell.smoothed-adjusted {
  box-shadow: inset 0 0 0 1px rgba(16, 179, 163, 0.28), 0 0 0 3px rgba(16, 179, 163, 0.08);
}

.plan-cell.capacity-over {
  background: rgba(222, 79, 61, 0.15);
  color: var(--danger);
}

/* ── Proposal (chờ duyệt) cell ─────────────────────────────── */
.plan-cell.has-proposal {
  background: rgba(245, 158, 11, 0.18) !important;
  border-color: #f59e0b !important;
  color: #92400e !important;
  font-weight: 700;
}
.proposal-dot {
  display: inline-block;
  width: 7px; height: 7px;
  margin-left: 5px;
  border-radius: 999px;
  background: #f59e0b;
  vertical-align: middle;
}

/* ── Role checkboxes in account form ───────────────────────── */
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 12.5px; font-weight: 600; color: var(--brand-deep); }
.role-checkboxes { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.role-checkboxes label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; cursor: pointer;
}
.role-checkboxes input[type=checkbox] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--brand); }

.manual-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 999px;
  background: currentColor;
  vertical-align: middle;
}

.capacity-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 999px;
  border: 2px solid currentColor;
  vertical-align: middle;
}

.smooth-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 6px;
  border-radius: 3px;
  border: 2px solid currentColor;
  transform: rotate(45deg);
  vertical-align: middle;
}

.business-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 2px;
  background: currentColor;
  transform: rotate(45deg);
  vertical-align: middle;
}

.qlxk-dot {
  display: inline-grid;
  place-items: center;
  width: 14px;
  height: 14px;
  margin-left: 6px;
  border-radius: 999px;
  background: currentColor;
  color: #fff;
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
  vertical-align: middle;
}

.qlxk-dot::before {
  content: "!";
}

.qlxk-risk-row td {
  background: rgba(245, 239, 255, 0.86);
}

.plan-edit-input {
  width: 82px;
  border: 1px solid rgba(31, 142, 205, 0.35);
  border-radius: 999px;
  padding: 7px 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 750;
  text-align: center;
  outline: none;
  box-shadow: 0 8px 18px rgba(31, 142, 205, 0.14);
}

.plan-edit-input:focus {
  border-color: rgba(31, 142, 205, 0.8);
  box-shadow: 0 0 0 4px rgba(31, 142, 205, 0.12);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(16, 24, 40, 0.46);
}

.modal-card {
  width: min(680px, 100%);
  border-radius: 28px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 32px 90px rgba(10, 20, 42, 0.22);
  backdrop-filter: blur(18px);
}

.modal-card.modal-wide {
  width: min(1760px, calc(100vw - 24px));
}

.resizable-modal {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: min(760px, calc(100vw - 24px));
  min-height: 420px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  resize: both;
  overflow: hidden;
}

.resizable-modal::after {
  content: "open_in_full";
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: rgba(15, 109, 137, 0.1);
  color: var(--brand);
  font-family: "Material Symbols Outlined";
  font-size: 17px;
  pointer-events: none;
}

.resizable-modal .modal-head {
  flex: 0 0 auto;
}

.resizable-modal .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-bottom: 38px;
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
}

.modal-head {
  border-bottom: 1px solid var(--line);
}

.modal-head-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 24px;
}

.modal-body {
  padding: 14px 18px 18px;
}

.detail-table-scroll {
  max-height: min(70vh, 760px);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.modal-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.modal-form label:last-child {
  grid-column: 1 / -1;
}

.stock-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.stock-detail-item {
  padding: 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(247, 250, 255, 0.98), rgba(255, 255, 255, 0.98));
}

.stock-detail-item h3 {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stock-detail-item p {
  margin: 10px 0 0;
  font-size: 30px;
  font-weight: 800;
}

.plan-explain {
  display: grid;
  gap: 10px;
}

.plan-explain-warning {
  padding: 10px 14px;
  border: 1px solid rgba(222, 79, 61, 0.22);
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(255, 242, 240, 0.98), rgba(255, 250, 247, 0.96));
  color: var(--danger);
  line-height: 1.45;
}

.plan-explain-warning.business {
  border-color: rgba(214, 145, 25, 0.28);
  background: linear-gradient(135deg, rgba(255, 248, 232, 0.98), rgba(255, 253, 245, 0.96));
  color: #a36508;
}

.plan-explain-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.plan-explain-item {
  min-height: 58px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(247, 250, 255, 0.98), rgba(255, 255, 255, 0.98));
}

.plan-explain-item span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.25;
}

.plan-explain-item strong {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.18;
}

.plan-formula {
  padding: 12px 14px;
  border: 1px solid rgba(15, 109, 137, 0.16);
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(235, 248, 252, 0.92), rgba(255, 255, 255, 0.98));
  color: var(--ink);
}

.plan-formula p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.formula-steps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.formula-step {
  padding: 9px 11px;
  border: 1px solid rgba(15, 109, 137, 0.14);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
}

.formula-step span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.formula-step strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.25;
}

.formula-step small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.35;
}

@media (max-width: 1360px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .insights {
    grid-template-columns: 1fr;
  }

  .stock-top-grid {
    grid-template-columns: 1fr;
  }

  .stock-turnover-panel {
    grid-column: auto;
  }

  .stock-turnover-body {
    grid-template-columns: 1fr;
  }

  .sales-top-grid {
    grid-template-columns: 1fr;
  }

  .excel-upload-grid,
  .excel-help-grid {
    grid-template-columns: 1fr;
  }

  .excel-import-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .logic-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .logic-rollup-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .logic-form-grid,
  .logic-preview-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .logic-card.highlight {
    grid-column: span 2;
  }

  .kpis {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .line-chart-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .signal-panel,
  .chart-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .alert-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .catalog-top-grid,
  #lotView:not(.hidden),
  #capacityView:not(.hidden) {
    grid-template-columns: 1fr;
    grid-template-areas: none;
  }

  .catalog-top-main,
  .manual-catalog-panel,
  .catalog-distribution-panel,
  #lotView > .hero,
  #lotView > .controls,
  #lotView > .panel.table-panel:first-of-type,
  #lotView > .panel.table-panel:last-of-type,
  #capacityView > .hero,
  #capacityView > .catalog-chart-panel,
  .capacity-guidance-panel,
  #capacityView > .table-panel {
    grid-area: auto;
    grid-column: auto;
    grid-row: auto;
  }

  .catalog-distribution-panel {
    position: static;
  }

  #capacityView .compact-ratio-wrap,
  #lotView .compact-ratio-wrap {
    grid-template-columns: 220px minmax(0, 1fr);
  }
}

@media (max-width: 860px) {
  .layout {
    padding: 14px;
  }

  .hero {
    flex-direction: column;
  }

  .hero h1 {
    font-size: 34px;
  }

  .controls {
    padding: 14px;
  }

  .kpis,
  .line-chart-summary,
  .logic-form-grid,
  .logic-grid,
  .logic-rollup-grid,
  .logic-preview-grid,
  .modal-form,
  .plan-explain-grid,
  .stock-detail-grid,
  .spike-summary-grid,
  .manual-spike-form {
    grid-template-columns: 1fr;
  }

  .logic-card.highlight {
    grid-column: auto;
  }

  .catalog-chart-wrap {
    grid-template-columns: 1fr;
  }

  .compact-ratio-wrap {
    grid-template-columns: 1fr;
  }

  .manual-catalog-grid {
    grid-template-columns: 1fr;
  }

  .manual-catalog-endpoint {
    grid-column: auto;
  }

  .catalog-top-grid {
    grid-template-columns: 1fr;
    grid-template-areas: none;
  }

  .catalog-distribution-panel {
    grid-column: auto;
    grid-row: auto;
    position: static;
  }

  #capacityView .compact-ratio-wrap,
  #lotView .compact-ratio-wrap {
    grid-template-columns: 1fr;
  }

  .sales-ratio-wrap {
    grid-template-columns: 1fr;
  }

  .sales-controls label,
  .sales-controls .filter-summary {
    flex-basis: 100%;
  }

  .excel-import-summary {
    grid-template-columns: 1fr;
  }

  .kpi {
    min-height: auto;
  }
}

/* Capacity report redesign */
#capacityView:not(.hidden) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

#capacityView > .hero {
  grid-column: 1 / -1;
  min-height: auto;
  padding: 18px 24px;
}

#capacityView > .catalog-chart-panel,
#capacityView > .capacity-guidance-panel {
  display: none;
}

#capacityView > .table-panel {
  grid-column: 1 / -1;
}

#capacityView > .cap-report-panel {
  order: 2;
  background: transparent;
  border: 0;
  box-shadow: none;
  overflow: visible;
}

#capacityView > .table-panel:not(.cap-report-panel) {
  order: 3;
}

#capacityReportContainer {
  display: grid;
  gap: 16px;
}

.cap-file-grid,
.cap-health-kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.cap-file-card {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 66px;
  padding: 14px 18px;
  border: 2px dashed #22c55e;
  border-radius: 16px;
  background: #effdf4;
  color: #047336;
}

.cap-file-card .material-symbols-outlined {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #dcfce7;
  color: #16a34a;
}

.cap-file-card strong {
  display: block;
  font-size: 13px;
  font-weight: 800;
}

.cap-file-card small {
  display: block;
  margin-top: 3px;
  color: #15803d;
  font-size: 11px;
}

.cap-file-card button {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: #7c92b0;
  font-size: 20px;
  cursor: pointer;
}

.cap-read-summary {
  padding: 18px;
  border: 1px solid rgba(144, 165, 196, 0.28);
  border-radius: 14px;
  background: #ffffff;
}

.cap-read-summary h3,
.cap-detail-head h3 {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 12px;
  color: #101a34;
  font-size: 14px;
}

.cap-read-cols {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px;
}

.cap-read-cols strong {
  display: block;
  margin-bottom: 7px;
  font-size: 12px;
}

.cap-read-blue { color: #1d4ed8; }
.cap-read-green { color: #08a34b; }

.cap-read-cols ul {
  margin: 0;
  padding-left: 16px;
  color: #506383;
  font-size: 11px;
  line-height: 1.55;
}

.cap-health-kpis {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.cap-health-card {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 100px;
  padding: 18px 22px;
  border-radius: 12px;
}

.cap-health-card > .material-symbols-outlined {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 10px 22px rgba(14, 40, 84, 0.08);
}

.cap-health-card small {
  color: #657796;
  font-size: 12px;
}

.cap-health-card strong {
  display: block;
  margin-top: 4px;
  font-size: 28px;
  line-height: 1;
}

.cap-health-card em {
  display: block;
  margin-top: 6px;
  color: #7a8ca8;
  font-size: 11px;
  font-style: normal;
}

.cap-health-card.danger { background: #fff1f1; color: #ef4444; }
.cap-health-card.warn { background: #fff7eb; color: #f97316; }
.cap-health-card.ok { background: #effdf4; color: #16a34a; }

.cap-line-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.cap-line-card {
  text-align: left;
  min-height: 188px;
  padding: 17px 18px 14px;
  border: 1px solid rgba(144, 165, 196, 0.24);
  border-radius: 11px;
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(14, 40, 84, 0.08);
  cursor: pointer;
}

.cap-line-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(14, 40, 84, 0.12);
}

.cap-line-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.cap-line-card-top span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #101a34;
  font-weight: 900;
}

.cap-line-card-top i,
.cap-line-code span::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
}

.cap-line-card-top b {
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}

.cap-line-card.danger .cap-line-card-top b { background: #fff1f1; color: #ef4444; border: 1px solid #fecaca; }
.cap-line-card.warn .cap-line-card-top b { background: #fff7eb; color: #f97316; border: 1px solid #fed7aa; }
.cap-line-card.ok .cap-line-card-top b { background: #effdf4; color: #16a34a; border: 1px solid #bbf7d0; }

.cap-line-card > strong {
  display: block;
  margin-top: 18px;
  font-size: 30px;
  line-height: 1;
}

.cap-line-card.danger > strong { color: #ef4444; }
.cap-line-card.warn > strong { color: #f97316; }
.cap-line-card.ok > strong { color: #09a64f; }

.cap-line-card small,
.cap-line-card em {
  display: block;
  margin-top: 7px;
  color: #7890ad;
  font-size: 11px;
  font-style: normal;
}

.cap-line-progress {
  height: 5px;
  margin: 13px 0 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf2f7;
}

.cap-line-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: currentColor;
}

.cap-spark-bars {
  display: flex;
  align-items: end;
  gap: 5px;
  height: 30px;
  margin-top: 12px;
}

.cap-spark-bars span {
  width: 12px;
  border-radius: 3px;
  background: #cbd5e1;
}

.cap-spark-bars .danger { background: #ef4444; }
.cap-spark-bars .warn { background: #fb923c; }
.cap-spark-bars .ok { background: #48b976; }
.cap-spark-bars .idle { background: #dbe4ee; }

.cap-detail-section {
  overflow: hidden;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(14, 40, 84, 0.07);
}

.cap-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 12px;
}

.cap-detail-head p {
  margin: 0;
  color: #7a8ca8;
  font-size: 12px;
}

.cap-detail-head span {
  color: #0f6d89;
  font-size: 12px;
  font-weight: 800;
}

.cap-health-matrix {
  min-width: 1240px;
  border-collapse: collapse;
}

.cap-health-matrix th {
  background: #111b33 !important;
  color: #eaf2ff !important;
  border-color: #24304c !important;
}

.cap-health-matrix td {
  border-color: #e4ebf3;
}

.cap-health-matrix .cap-line-code {
  min-width: 130px;
  color: #101a34;
}

.cap-line-code span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #101a34;
}

.cap-line-code span::before {
  background: var(--dot);
}

.cap-health-matrix .cap-status-badge {
  margin-left: 8px;
  text-transform: none;
}

.cap-health-matrix .cap-report-cell strong {
  display: block;
  font-size: 12px;
}

.cap-health-matrix .cap-cell-danger {
  background: #ffecec;
  color: #e11d48;
}

.cap-health-matrix .cap-cell-warn {
  background: #fff5e6;
  color: #f97316;
}

.cap-health-matrix .cap-cell-ok {
  background: #ecfdf4;
  color: #059447;
}

.cap-health-matrix .cap-cell-empty {
  background: #f9fbfd;
}

@media (max-width: 920px) {
  .cap-file-grid,
  .cap-read-cols,
  .cap-health-kpis {
    grid-template-columns: 1fr;
  }
}
