:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-muted: #eef2ee;
  --ink: #17201c;
  --muted: #65716b;
  --line: #d9dfd9;
  --accent: #0f7b68;
  --accent-dark: #064f43;
  --accent-2: #2720a0;
  --warning: #a76612;
  --danger: #b42318;
  --ok: #197a3a;
  --purple: #2a1762;
  --shadow: 0 16px 36px rgba(23, 32, 28, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

[hidden] {
  display: none !important;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 18px 14px;
  background: #15211d;
  color: #f4f7f3;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 18px;
}

.brand-logo {
  width: 86px;
  height: 36px;
  object-fit: contain;
  border-radius: 4px;
  background: #f4f7f3;
  padding: 4px;
}

.brand-title {
  font-weight: 800;
}

.brand-subtitle {
  color: #aebbb3;
  font-size: 12px;
}

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

.nav-item {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #e9eee9;
  text-align: left;
}

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

.nav-item.primary {
  margin-top: 8px;
  background: #f2b84b;
  color: #17201c;
  font-weight: 700;
}

.workspace {
  min-width: 0;
  padding: 22px 26px 38px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 18px;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 10px;
  font-size: 15px;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.current-user-card {
  display: grid;
  align-content: center;
  min-width: 260px;
  min-height: 50px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.current-user-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.current-user-card strong {
  margin-top: 2px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.15;
  white-space: nowrap;
}

.action-button,
.ghost-button,
.icon-button,
.mini-button,
.danger-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
}

.action-button {
  padding: 0 14px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.ghost-button {
  padding: 0 12px;
}

.link-button {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-weight: 800;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-button:hover {
  color: var(--accent-2);
}

.danger-button {
  padding: 0 12px;
  border-color: #f0b8b1;
  background: #fff4f2;
  color: var(--danger);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 50px;
  padding: 0;
  font-weight: 800;
}

.topbar-actions > .action-button,
.topbar-actions > .ghost-button,
.topbar-actions > .icon-button {
  min-height: 50px;
}

.mini-button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.action-button:hover,
.ghost-button:hover,
.icon-button:hover,
.mini-button:hover,
.danger-button:hover {
  filter: brightness(0.97);
}

.filters {
  display: grid;
  grid-template-columns: minmax(160px, 240px) minmax(220px, 420px);
  gap: 10px;
  margin: 14px 0 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 10px 26px rgba(23, 32, 28, 0.04);
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(39, 32, 160, 0.12);
}

input[type="checkbox"] {
  width: auto;
  min-height: auto;
}

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

.section-grid {
  display: grid;
  gap: 18px;
}

.table-screen {
  align-content: start;
}

.section-actions,
.inline-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

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

.metric {
  min-height: 116px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(23, 32, 28, 0.04);
}

.metric.clickable {
  position: relative;
}

.metric.clickable:hover {
  border-color: var(--accent);
  box-shadow: 0 12px 26px rgba(15, 123, 104, 0.12);
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-value {
  margin-top: 8px;
  font-size: 25px;
  font-weight: 850;
  line-height: 1.1;
  letter-spacing: 0;
}

.metric-foot {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.metric.ok .metric-value {
  color: var(--ok);
}

.metric.warning .metric-value {
  color: var(--warning);
}

.metric.danger .metric-value {
  color: var(--danger);
}

.panel {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-panel {
  display: flex;
  flex-direction: column;
  min-height: 620px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.panel-header p {
  margin-bottom: 0;
  color: var(--muted);
}

.two-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

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

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

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.large-table {
  flex: 1;
  min-height: 520px;
  max-height: calc(100vh - 350px);
  overflow: auto;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 10px 11px;
  border-bottom: 1px solid #e8ede8;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f0f4ef;
  color: #39443f;
  font-size: 12px;
  font-weight: 800;
}

tbody tr:hover {
  background: #fbfcf9;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

.nowrap {
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e9eef0;
  color: #31403a;
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  background: #dff1e5;
  color: var(--ok);
}

.badge.warning {
  background: #fff0d4;
  color: var(--warning);
}

.badge.danger {
  background: #fce1dc;
  color: var(--danger);
}

.progress {
  width: 130px;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4e9e4;
}

.progress > span {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  max-width: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.bar-chart {
  display: grid;
  gap: 9px;
}

.bar-row {
  display: grid;
  grid-template-columns: 84px minmax(140px, 1fr) 112px;
  align-items: center;
  gap: 12px;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4e9e4;
}

.bar-track span {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.form-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.tab-button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.tab-button.active {
  border-color: var(--accent);
  background: #dff1ec;
  color: #064f43;
  font-weight: 800;
}

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

.form-grid .span-2,
.filter-grid .span-2 {
  grid-column: span 2;
}

.form-grid .span-3,
.filter-grid .span-3 {
  grid-column: span 3;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.callout {
  padding: 12px 14px;
  border: 1px solid #f1d59c;
  border-radius: var(--radius);
  background: #fff7e8;
  color: #65400f;
}

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

.directory-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 120px 84px;
  align-items: end;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #edf1ed;
}

.directory-row:last-child {
  border-bottom: 0;
}

.inline-edit {
  min-width: 150px;
}

.inline-date {
  min-width: 148px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: #17201c;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(23, 32, 28, 0.48);
}

.modal {
  width: min(1120px, 100%);
  max-height: min(88vh, 920px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 26px 70px rgba(23, 32, 28, 0.28);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-header h2 {
  margin-bottom: 0;
}

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-logo {
  width: 150px;
  height: auto;
  object-fit: contain;
}

@media (max-width: 1180px) {
  .filters {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

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

  .two-columns,
  .three-columns,
  .four-columns,
  .form-grid,
  .filter-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .span-2,
  .form-grid .span-3,
  .filter-grid .span-2,
  .filter-grid .span-3 {
    grid-column: auto;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 12px;
  }

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

  .brand-logo {
    width: 78px;
  }

  .workspace {
    padding: 16px 12px 28px;
  }

  .topbar,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .current-user-card {
    min-width: 0;
  }

  .topbar-actions > .action-button,
  .topbar-actions > .ghost-button,
  .topbar-actions > .icon-button {
    width: 100%;
  }

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

  .table-panel {
    min-height: 520px;
  }

  .large-table {
    min-height: 420px;
    max-height: 70vh;
  }

  .modal-backdrop {
    padding: 10px;
  }

  .directory-row {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 23px;
  }

  .metric-value {
    font-size: 22px;
  }
}
