:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1d2522;
  --muted: #6b746f;
  --line: #dfe4df;
  --soft: #eef2ed;
  --accent: #1f7a5a;
  --accent-strong: #145e45;
  --warn: #bd6b16;
  --danger: #b64242;
  --info: #315d91;
  --shadow: 0 12px 32px rgba(25, 36, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1100px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #17231e;
  color: #f8fbf7;
  padding: 18px 14px;
}

.brand-block {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand-mark,
.login-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #f1c66d;
  color: #17231e;
  font-weight: 800;
}

.brand-block strong,
.brand-block span {
  display: block;
}

.brand-block span {
  margin-top: 3px;
  color: rgba(248, 251, 247, 0.68);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 4px;
  padding-top: 16px;
}

.nav-item {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  background: transparent;
  color: rgba(248, 251, 247, 0.78);
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.nav-icon {
  font-size: 15px;
}

.nav-count {
  min-width: 24px;
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(248, 251, 247, 0.82);
  font-size: 12px;
  text-align: center;
}

.workspace {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 76px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 244, 0.94);
  backdrop-filter: blur(10px);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.content {
  display: grid;
  gap: 18px;
  padding: 22px 28px 36px;
}

.toolbar,
.section-head,
.form-row,
.table-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar,
.data-section,
.metric,
.chart-box,
.login-panel,
.editor-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.toolbar {
  justify-content: space-between;
  padding: 12px;
}

.action-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.filter-toolbar {
  box-shadow: none;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 12px;
}

.metric {
  padding: 14px;
  box-shadow: none;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1.1;
}

.metric small {
  color: var(--muted);
}

.chart-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
}

.chart-box {
  min-height: 340px;
  padding: 14px;
  box-shadow: none;
}

.chart-box h2,
.data-section h2,
.editor-panel h2 {
  margin: 0;
  font-size: 15px;
}

.chart {
  height: 288px;
  margin-top: 12px;
}

.data-section {
  overflow: hidden;
}

.section-head {
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  min-height: 44px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--soft);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #fafbf9;
}

tr:hover td {
  background: #fbfcfa;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--info);
  background: #e8f0f8;
  font-size: 12px;
}

.status.ok {
  color: var(--accent-strong);
  background: #e3f2e9;
}

.status.warn {
  color: var(--warn);
  background: #fff2df;
}

.status.danger {
  color: var(--danger);
  background: #fdeaea;
}

input,
select,
textarea {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--ink);
}

textarea {
  min-height: 76px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.primary-button,
.ghost-button,
.icon-button,
.text-button,
.danger-button {
  min-height: 36px;
  border-radius: 7px;
  border: 1px solid transparent;
  padding: 8px 12px;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  padding: 0;
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
}

.text-button {
  padding: 0;
  background: transparent;
  color: var(--accent-strong);
}

.danger-button {
  background: var(--danger);
  color: #ffffff;
}

.login-view {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #17231e;
}

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

.login-panel {
  display: grid;
  gap: 16px;
  width: 380px;
  padding: 28px;
}

.login-panel h1 {
  margin: 0;
  font-size: 22px;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  max-width: 360px;
  border-radius: 8px;
  padding: 12px 14px;
  background: #17231e;
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

.modal-overlay[hidden] {
  display: none;
}

.modal-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(720px, 100%);
  max-height: min(780px, calc(100vh - 44px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 22px 70px rgba(20, 31, 26, 0.28);
  overflow: hidden;
}

.modal-head,
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-foot {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
  background: #fbfcfa;
}

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

.modal-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.modal-body {
  overflow: auto;
  padding: 16px;
}

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

.modal-grid .wide {
  grid-column: span 2;
}

.empty {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.editor-panel {
  padding: 16px;
  box-shadow: none;
}

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

.editor-grid .wide {
  grid-column: span 3;
}

.pagination {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
}

.skeleton {
  min-height: 140px;
  border-radius: 8px;
  background: linear-gradient(90deg, #eef2ed 25%, #f8faf7 37%, #eef2ed 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

@media (max-width: 900px) {
  body {
    min-width: 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 10px;
  }

  .brand-block {
    grid-template-columns: 36px 1fr;
    padding-bottom: 10px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .nav-list {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    padding-top: 10px;
  }

  .nav-item {
    grid-template-columns: 20px 1fr;
  }

  .nav-count {
    display: none;
  }

  .topbar,
  .content {
    padding-left: 14px;
    padding-right: 14px;
  }

  .metric-grid,
  .chart-grid,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .editor-grid .wide {
    grid-column: auto;
  }
}

/* Factory-style admin shell */
body {
  min-width: 0;
}

.app-shell {
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
  grid-template-columns: 1fr;
  min-height: 100vh;
}

.global-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  padding: 0 18px;
  box-shadow: 0 1px 0 rgba(25, 36, 31, 0.03);
}

.global-header .brand-block {
  display: grid;
  grid-template-columns: 36px 40px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0;
  border-bottom: 0;
  color: var(--ink);
}

.global-header .brand-mark {
  width: 40px;
  height: 40px;
}

.global-header .brand-block span {
  color: var(--muted);
}

.header-toggle {
  width: 36px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.account-chip {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 148px;
  max-width: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 9px 5px 5px;
  background: #fbfcfa;
}

.account-avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #e3f2e9;
  color: var(--accent-strong);
  font-weight: 800;
}

.account-text {
  min-width: 0;
}

.account-text strong,
.account-text small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-text strong {
  font-size: 13px;
}

.account-text small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.layout-body {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 0;
  transition: grid-template-columns 0.18s ease;
}

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

.sidebar {
  position: sticky;
  top: 64px;
  align-self: start;
  height: calc(100vh - 64px);
  overflow: hidden auto;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  padding: 14px 10px;
}

.nav-list {
  display: grid;
  grid-auto-flow: row;
  grid-auto-columns: auto;
  gap: 4px;
  overflow: visible;
  padding-top: 0;
}

.nav-item {
  grid-template-columns: 28px minmax(0, 1fr);
  min-height: 42px;
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 24px;
}

.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-count {
  display: none;
}

.nav-parent {
  grid-template-columns: 28px minmax(0, 1fr) 20px;
}

.nav-chevron {
  transition: transform 0.18s ease;
  text-align: center;
}

.nav-group.expanded .nav-chevron {
  transform: rotate(180deg);
}

.nav-children {
  display: none;
  gap: 2px;
  padding: 2px 0 4px 38px;
}

.nav-group.expanded .nav-children {
  display: grid;
}

.nav-child {
  min-height: 34px;
  border: 0;
  border-left: 2px solid rgba(255, 255, 255, 0.15);
  padding: 6px 12px;
  background: transparent;
  color: rgba(248, 251, 247, 0.68);
  text-align: left;
}

.nav-child:hover,
.nav-child.active {
  border-left-color: var(--accent);
  color: #ffffff;
}

.app-shell.sidebar-collapsed .nav-item {
  grid-template-columns: 1fr;
  justify-items: center;
  padding: 8px;
}

.app-shell.sidebar-collapsed .nav-label,
.app-shell.sidebar-collapsed .nav-count,
.app-shell.sidebar-collapsed .nav-chevron,
.app-shell.sidebar-collapsed .nav-children {
  display: none;
}

.workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
}

.topbar {
  position: static;
  min-height: 72px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  backdrop-filter: none;
}

.tabs-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  padding: 6px 10px;
}

.tab-item {
  display: inline-grid;
  grid-template-columns: minmax(0, auto) 18px;
  align-items: center;
  gap: 6px;
  max-width: 190px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 6px 4px 10px;
  background: #ffffff;
  color: var(--muted);
}

.tab-item.active {
  border-color: rgba(31, 122, 90, 0.32);
  background: #eaf5ef;
  color: var(--accent-strong);
}

.tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.tab-close {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  padding: 0;
}

.tab-close:hover {
  background: rgba(23, 35, 30, 0.08);
}

.content {
  min-width: 0;
}

@media (max-width: 1100px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }

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

@media (max-width: 760px) {
  .global-header {
    padding: 0 10px;
  }

  .global-header .brand-block {
    grid-template-columns: 36px 36px minmax(0, 1fr);
  }

  .global-header .brand-mark {
    width: 36px;
    height: 36px;
  }

  .account-chip {
    min-width: 40px;
    width: 40px;
    padding: 3px;
  }

  .account-text {
    display: none;
  }

  .header-actions .ghost-button {
    padding-left: 9px;
    padding-right: 9px;
  }

  .layout-body,
  .app-shell.sidebar-collapsed .layout-body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 64px;
    bottom: 0;
    left: 0;
    z-index: 24;
    width: 248px;
    height: auto;
    transform: translateX(0);
    transition: transform 0.18s ease;
    box-shadow: 14px 0 30px rgba(0, 0, 0, 0.18);
  }

  .app-shell.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
  }

  .app-shell.sidebar-collapsed .nav-item {
    grid-template-columns: 28px minmax(0, 1fr);
    justify-items: stretch;
    padding: 8px 10px;
  }

  .app-shell.sidebar-collapsed .nav-label {
    display: block;
  }

  .topbar {
    min-height: 66px;
    padding: 12px 14px;
  }

  .topbar h1 {
    font-size: 19px;
  }

  .tabs-bar {
    padding-left: 8px;
    padding-right: 8px;
  }

  .content {
    padding: 14px;
  }

  .metric-grid,
  .chart-grid,
  .modal-grid,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .modal-grid .wide {
    grid-column: auto;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar,
  .toolbar-group {
    display: grid;
    grid-template-columns: 1fr;
  }
}
