:root {
  color-scheme: light;
  --primary: #145c36;
  --primary-strong: #0d4427;
  --primary-soft: #e7f2eb;
  --gold: #b87912;
  --gold-soft: #fff3d4;
  --coral: #b53e35;
  --ink: #18201d;
  --muted: #5d6964;
  --line: #dce2df;
  --surface: #f5f7f6;
  --white: #fff;
  --sidebar: #17231e;
  --shadow: 0 12px 30px rgb(22 42 32 / 10%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--surface); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
svg { width: 18px; height: 18px; flex: 0 0 auto; stroke-width: 2; }
[hidden] { display: none !important; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 42%) minmax(360px, 1fr);
  background: var(--white);
}
.auth-brand {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  padding: clamp(34px, 6vw, 84px);
  color: var(--white);
  background: var(--primary);
}
.auth-brand img { width: 76px; height: 76px; object-fit: contain; filter: drop-shadow(0 5px 12px rgb(0 0 0 / 18%)); }
.auth-brand div { display: grid; gap: 3px; }
.auth-brand strong { font-size: clamp(30px, 4vw, 52px); line-height: 1; }
.auth-brand span { color: #d2e7da; font-size: 15px; }
.auth-form { width: min(440px, calc(100% - 48px)); margin: auto; display: grid; gap: 18px; }
.auth-form header { margin-bottom: 8px; }
.auth-form h1 { margin: 0 0 8px; font-size: 28px; }
.auth-form p { margin: 0; color: var(--muted); }
.auth-form-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; }
.auth-home-link { flex: 0 0 auto; text-decoration: none; }
.language-field { width: min(210px, 100%); }
.auth-form label, .dialog-fields label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 650; }
.input-wrap { position: relative; display: block; }
.input-wrap svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.input-wrap input { padding-left: 42px; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--white);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgb(20 92 54 / 12%); }
textarea { min-height: 110px; resize: vertical; }
.form-error { color: var(--coral) !important; font-size: 13px; line-height: 1.45; }

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 9px 14px;
  font-weight: 700;
  text-decoration: none;
}
.button.primary { color: var(--white); background: var(--primary); }
.button.primary:hover { background: var(--primary-strong); }
.button.secondary { color: var(--primary); background: var(--primary-soft); }
.button.ghost { color: var(--ink); border-color: var(--line); background: var(--white); }
.button.danger { color: var(--coral); background: #faecea; }
.button.small { min-height: 32px; padding: 5px 9px; font-size: 12px; }
.button.wide { width: 100%; min-height: 46px; }
.button.auth-home-link { min-height: 44px; }
.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  color: inherit;
  background: transparent;
}
.icon-button:hover { background: rgb(127 127 127 / 12%); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 246px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 14px 14px;
  color: #e8f0ec;
  background: var(--sidebar);
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 22px; }
.sidebar-brand img { width: 42px; height: 42px; object-fit: contain; }
.sidebar-brand div { display: grid; }
.sidebar-brand strong { font-size: 17px; }
.sidebar-brand span { color: #8fa79b; font-size: 11px; font-weight: 700; text-transform: uppercase; }
#main-nav { display: grid; gap: 4px; }
.nav-item {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 0;
  border-radius: 6px;
  padding: 0 11px;
  color: #b8c7c0;
  text-align: left;
  background: transparent;
}
.nav-item:hover { color: var(--white); background: rgb(255 255 255 / 7%); }
.nav-item.active { color: var(--white); background: #28513d; }
.admin-home-link { margin-bottom: 7px; border: 1px solid rgb(255 255 255 / 12%); color: #d2e7da; text-decoration: none; }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 14px 6px 2px; border-top: 1px solid rgb(255 255 255 / 10%); }
.user-summary { min-width: 0; flex: 1; display: flex; align-items: center; gap: 9px; }
.user-summary div { min-width: 0; display: grid; }
.user-summary strong, .user-summary span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-summary strong { font-size: 13px; }
.user-summary div span { color: #8fa79b; font-size: 11px; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: var(--primary-strong); background: #d6ecdf; font-size: 12px; font-weight: 800; }

.workspace { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 94%);
  backdrop-filter: blur(12px);
}
.context-picker { min-width: 0; display: flex; align-items: center; gap: 8px; }
.context-picker svg { color: var(--primary); }
.context-picker select { min-width: 220px; max-width: 420px; min-height: 38px; border: 0; padding: 7px 28px 7px 0; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.language-select { width: auto; min-width: 76px; min-height: 36px; padding: 6px 28px 6px 9px; font-size: 12px; font-weight: 750; }
.connection-status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
.connection-status > span { width: 7px; height: 7px; border-radius: 50%; background: #39a66c; }
.connection-status.loading > span { background: var(--gold); }
.connection-status.error > span { background: var(--coral); }

.main-content { width: min(1440px, 100%); margin: 0 auto; padding: 30px 30px 54px; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-header p, .dialog header p { margin: 0 0 5px; color: var(--primary); font-size: 10px; font-weight: 850; }
.page-header h1 { margin: 0; font-size: 27px; }
.page-actions { display: flex; gap: 8px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 28px; }
.metric-card { min-height: 122px; display: grid; align-content: space-between; gap: 15px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--white); }
.metric-card > div { display: flex; align-items: center; justify-content: space-between; }
.metric-card svg { color: var(--primary); }
.metric-card strong { font-size: 28px; line-height: 1; }
.metric-card span { color: var(--muted); font-size: 12px; font-weight: 650; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, .8fr); gap: 22px; }
.section-block { min-width: 0; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-heading h2 { margin: 0; font-size: 18px; }
.activity-list { border-top: 1px solid var(--line); }
.activity-item { display: flex; gap: 11px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.activity-icon { width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: var(--primary); background: var(--primary-soft); }
.activity-item div { min-width: 0; display: grid; gap: 3px; }
.activity-item strong { font-size: 13px; }
.activity-item span { color: var(--muted); font-size: 12px; }

.data-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.search-box { position: relative; width: min(360px, 100%); }
.search-box svg { position: absolute; top: 50%; left: 12px; transform: translateY(-50%); color: var(--muted); }
.search-box input { padding-left: 40px; background: var(--white); }
.record-count { color: var(--muted); font-size: 12px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--white); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); background: #fafbfa; font-size: 11px; font-weight: 800; text-transform: uppercase; white-space: nowrap; }
td { font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfb; }
.cell-primary { display: grid; gap: 3px; }
.cell-primary strong { font-size: 13px; }
.cell-primary span { color: var(--muted); font-size: 11px; }
.row-actions { display: flex; justify-content: flex-end; gap: 5px; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; width: fit-content; min-height: 24px; border-radius: 5px; padding: 3px 8px; color: var(--primary); background: var(--primary-soft); font-size: 11px; font-weight: 750; white-space: nowrap; }
.badge.gold { color: #875709; background: var(--gold-soft); }
.badge.red { color: var(--coral); background: #faecea; }
.badge.gray { color: var(--muted); background: #edf0ee; }
.empty-state { display: grid; place-items: center; gap: 10px; min-height: 280px; padding: 30px; text-align: center; border: 1px dashed #c9d3ce; border-radius: 8px; background: var(--white); }
.empty-state > span { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%; color: var(--primary); background: var(--primary-soft); }
.empty-state h2, .empty-state p { margin: 0; }
.empty-state h2 { font-size: 17px; }
.empty-state p { max-width: 360px; color: var(--muted); font-size: 13px; }
.loading-state { min-height: 300px; display: grid; place-items: center; color: var(--muted); }
.spinner { width: 25px; height: 25px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.settings-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 360px); gap: 22px; }
.settings-panel { padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--white); }
.settings-panel h2 { margin: 0 0 16px; font-size: 17px; }
.definition-list { display: grid; gap: 0; }
.definition-list > div { display: flex; justify-content: space-between; gap: 18px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.definition-list > div:last-child { border-bottom: 0; }
.definition-list span { color: var(--muted); }
.definition-list strong { text-align: right; }

.dialog { width: min(580px, calc(100% - 28px)); max-height: calc(100vh - 40px); border: 0; border-radius: 8px; padding: 0; color: var(--ink); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgb(11 24 17 / 55%); backdrop-filter: blur(2px); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.dialog header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.dialog h2 { margin: 0; font-size: 20px; }
.dialog-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 20px; overflow: auto; }
.dialog-fields label.full { grid-column: 1 / -1; }
.checkbox-field { display: flex !important; align-items: center; gap: 9px !important; min-height: 44px; }
.checkbox-field input { width: 18px; min-height: 18px; }
.dialog .form-error { margin: 0; padding: 0 20px 12px; }
.dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; display: flex; align-items: center; gap: 9px; max-width: min(420px, calc(100% - 32px)); padding: 12px 15px; border-radius: 7px; color: var(--white); background: var(--primary-strong); box-shadow: var(--shadow); font-size: 13px; font-weight: 650; }
.toast.error { background: #7f2923; }
.mobile-only { display: none; }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid, .settings-layout { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { min-height: 190px; align-items: center; padding: 28px; }
  .auth-brand strong { font-size: 32px; }
  .auth-form { padding: 34px 0; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); width: 246px; transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 19; display: block; background: rgb(8 19 13 / 50%); }
  .mobile-only { display: inline-grid; }
  .topbar { padding: 0 14px; }
  .context-picker { flex: 1; }
  .context-picker select { width: 100%; min-width: 0; }
  .connection-status { display: none; }
  .language-select { min-width: 70px; }
  .main-content { padding: 23px 15px 42px; }
  .page-header { align-items: flex-start; }
  .page-header h1 { font-size: 23px; }
  .page-actions .button span { display: none; }
  .page-actions .button { width: 40px; padding: 0; }
  .data-toolbar { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; }
  .dialog-fields { grid-template-columns: 1fr; }
  .dialog-fields label.full { grid-column: auto; }
}

@media (max-width: 480px) {
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric-card { min-height: 108px; padding: 13px; }
  .metric-card strong { font-size: 24px; }
  .auth-brand img { width: 62px; height: 62px; }
  .auth-brand span { font-size: 13px; }
  .auth-form-toolbar { align-items: center; }
  .auth-home-link { width: 44px; padding-inline: 0; }
  .auth-home-link span { display: none; }
}
