:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #64748b;
  --line: #dbe3ec;
  --sidebar: #111827;
  --sidebar-soft: #1f2937;
  --green: #15803d;
  --green-soft: #dcfce7;
  --orange: #c76a0a;
  --orange-soft: #ffedd5;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --purple: #7e22ce;
  --purple-soft: #f3e8ff;
  --shadow: 0 18px 45px rgba(15, 23, 42, .08);
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

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

body.auth-locked .app-shell {
  filter: blur(4px);
  pointer-events: none;
  user-select: none;
}

.auth-lock {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(135deg, rgba(17, 24, 39, .96), rgba(20, 83, 45, .9));
}

.auth-lock[hidden] { display: none; }

.auth-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 30px 70px rgba(0, 0, 0, .28);
}

.auth-card h1, .auth-card p { margin: 0; }
.auth-card p { color: var(--muted); }
.auth-card label { font-weight: 700; color: var(--muted); font-size: .84rem; }
.auth-card input { width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; font-size: 1.1rem; }
.auth-error { color: var(--red); font-weight: 700; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 16px;
  background: var(--sidebar);
  color: #eef4ff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #1c8c47, #48b47a);
  color: #fff;
  font-weight: 800;
}

.brand h1 { margin: 0; font-size: 1rem; line-height: 1.15; }
.brand p { margin: 3px 0 0; color: #afbdd0; font-size: .8rem; }

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

.nav button {
  width: 100%;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #dbe8fb;
  text-align: left;
  padding: 11px 12px;
  font-weight: 700;
}

.nav button:hover,
.nav button.active {
  background: #fff;
  color: var(--sidebar);
}

.side-status {
  margin-top: auto;
  display: grid;
  gap: 5px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--sidebar-soft);
  color: #dbe8fb;
  font-size: .84rem;
}

.side-status span { color: #afbdd0; }

.main {
  min-width: 0;
  padding: 22px;
}

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

.topbar h2 { margin: 0; font-size: 1.9rem; }
.topbar p { margin: 4px 0 0; color: var(--muted); }

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

.search-box {
  position: relative;
  min-width: min(440px, 42vw);
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  background: #fff;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 40;
  max-height: 380px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}

.search-result {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 10px;
  border-radius: var(--radius);
}

.search-result:hover { background: var(--bg); }
.search-result span { display: block; color: var(--muted); font-size: .84rem; }

.btn, .icon-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 10px 13px;
  font-weight: 700;
}

.btn:hover, .icon-btn:hover { background: var(--bg); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: var(--red-soft); border-color: #fecaca; color: var(--red); }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; padding: 0; }

.notice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
}

.hidden { display: none !important; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

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

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

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel h3, .panel p { margin: 0; }
.panel p { color: var(--muted); font-size: .9rem; margin-top: 4px; }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.field {
  min-width: 150px;
  display: grid;
  gap: 5px;
}

.field.wide { min-width: min(420px, 100%); flex: 1; }
.field label { color: var(--muted); font-size: .78rem; font-weight: 800; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px 11px;
}

.field textarea { min-height: 96px; resize: vertical; }

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

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

.kpi {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 15px;
  text-align: left;
  box-shadow: var(--shadow);
}

button.kpi:hover { border-color: var(--green); }
.kpi-label { color: var(--muted); font-size: .78rem; font-weight: 800; text-transform: uppercase; }
.kpi-value { margin-top: 8px; font-size: 1.8rem; font-weight: 850; }
.kpi-note { margin-top: 4px; color: var(--muted); font-size: .86rem; }

.table-wrap {
  overflow: auto;
  max-width: 100%;
}

table {
  width: 100%;
  min-width: 880px;
  border-collapse: collapse;
  font-size: .9rem;
}

th, td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: var(--muted);
  text-align: left;
  font-size: .76rem;
  text-transform: uppercase;
}

tr.clickable:hover { background: #f8fafc; }

.cell-main { font-weight: 800; }
.cell-sub { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 800;
}

.badge.green { color: var(--green); background: var(--green-soft); }
.badge.orange { color: var(--orange); background: var(--orange-soft); }
.badge.red { color: var(--red); background: var(--red-soft); }
.badge.blue { color: var(--blue); background: var(--blue-soft); }
.badge.purple { color: var(--purple); background: var(--purple-soft); }

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

.list-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 11px;
  text-align: left;
}

button.list-item:hover { border-color: var(--green); background: #fbfdfb; }
.empty { padding: 18px; color: var(--muted); text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

.import-box {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.summary-box {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.check-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.7;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 23, 42, .32);
  opacity: 0;
  pointer-events: none;
  transition: .16s ease;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 90;
  width: min(760px, 100vw);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: -22px 0 55px rgba(15, 23, 42, .18);
  transform: translateX(104%);
  transition: .2s ease;
}

.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.drawer-head h2, .drawer-head p { margin: 0; }
.drawer-head p { color: var(--muted); margin-top: 4px; }
.drawer-body { padding: 18px; overflow: auto; display: grid; gap: 14px; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tabs button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 8px 10px;
  font-weight: 800;
}

.tabs button.active { background: var(--sidebar); color: #fff; border-color: var(--sidebar); }

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

.data-point {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fbfdff;
}

.data-point span { display: block; color: var(--muted); font-size: .76rem; font-weight: 800; }
.data-point strong { display: block; margin-top: 4px; word-break: break-word; }

.note {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px;
  background: #fff;
}

.note p { margin: 6px 0 0; color: var(--ink); }

dialog {
  width: min(620px, calc(100vw - 24px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: 0 30px 70px rgba(15, 23, 42, .22);
}

dialog::backdrop { background: rgba(15, 23, 42, .36); }
.dialog-head, .dialog-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.dialog-foot { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; }
.dialog-head h3 { margin: 0; }
.dialog-body { padding: 16px; display: grid; gap: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 110;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  background: var(--sidebar);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: .18s ease;
}

.toast.open {
  transform: translate(-50%, 0);
  opacity: 1;
}

@media (max-width: 1040px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-status { margin-top: 0; }
  .topbar, .top-actions { flex-direction: column; align-items: stretch; }
  .search-box { min-width: 0; width: 100%; }
  .kpi-grid, .grid.two, .data-grid { grid-template-columns: 1fr; }
  .main { padding: 16px; }
}

@media print {
  .sidebar, .topbar, .filters, .drawer, .drawer-backdrop, .auth-lock, .toast { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; }
  .panel { box-shadow: none; break-inside: avoid; }
}
