:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --success: #15803d;
  --success-soft: #ecfdf3;
  --warning: #a16207;
  --warning-soft: #fffbeb;
  --shadow: 0 8px 28px rgba(15, 23, 42, .06);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0,1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 18px 14px;
  background: #fff; border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 3px 8px 16px; border-bottom: 1px solid var(--line); }
.brand-mark {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: grid; place-items: center;
  border-radius: 10px; background: var(--accent); color: #fff;
  font-weight: 800; font-size: 13px;
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 14px; }
.brand span { color: var(--muted); font-size: 11px; margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 4px; overflow: auto; }
.nav-item {
  position: relative; min-height: 42px;
  border: 0; border-radius: 9px; background: transparent;
  color: #374151; text-align: left; padding: 10px 12px 10px 15px;
  font-size: 13px; font-weight: 600;
}
.nav-item:hover { background: #f3f4f6; color: #111827; }
.nav-item.active { background: var(--accent-soft); color: #1d4ed8; font-weight: 700; }
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 9px; bottom: 9px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-separator { margin: 14px 10px 5px; color: #9ca3af; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.nav-separator.auth-admin-nav { display: none; }
.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.version { color: #9ca3af; text-align: center; font-size: 10px; }

.workspace { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 28px; background: rgba(255,255,255,.95); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.topbar-title { min-width: 0; }
.topbar-title h1 { margin: 3px 0 0; font-size: 23px; line-height: 1.2; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eyebrow { color: #9ca3af; font-size: 9px; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 9px; margin-left: auto; }
.menu-btn { display: none; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--text); }
.content { width: min(100%, 1540px); margin: 0 auto; padding: 24px 28px 60px; }

.primary-btn, .secondary-btn, .ghost-btn, .danger-btn {
  min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: 9px; padding: 8px 13px; border: 1px solid transparent;
  font-size: 12px; font-weight: 700; line-height: 1.1;
}
.primary-btn { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary-btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.secondary-btn { background: #fff; border-color: var(--line-strong); color: #1f2937; }
.secondary-btn:hover { background: #f9fafb; }
.ghost-btn { background: transparent; color: var(--muted); }
.danger-btn { background: #fff; border-color: #fecaca; color: var(--danger); }
.danger-btn:hover { background: var(--danger-soft); }
.file-btn input { display: none; }

.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4,minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3,minmax(0,1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2,minmax(0,1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(15,23,42,.03); padding: 18px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.metric-label { color: var(--muted); font-size: 11px; font-weight: 700; }
.metric { margin: 8px 0 4px; font-size: 28px; line-height: 1.08; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.metric-note { color: #9ca3af; font-size: 10px; margin-top: 5px; }
.section { margin-top: 24px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 18px; line-height: 1.2; letter-spacing: -.015em; }
.help { color: var(--muted); font-size: 11px; line-height: 1.5; }
.section-head .help { margin-top: 5px; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stacked-sections { display: grid; gap: 28px; }
.embedded-section { min-width: 0; }

.table-wrap { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(15,23,42,.03); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 11px 14px; border-bottom: 1px solid #edf0f3; text-align: left; vertical-align: middle; }
th { background: #f8fafc; color: #6b7280; font-size: 10px; font-weight: 750; white-space: nowrap; }
td { color: #1f2937; font-size: 12px; line-height: 1.4; }
tbody tr:hover { background: #fbfdff; }
tr:last-child td { border-bottom: 0; }

.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 8px; background: #f3f4f6; color: #4b5563; font-size: 10px; font-weight: 700; white-space: nowrap; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.muted { background: #f3f4f6; color: #6b7280; }

.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { color: #4b5563; font-size: 10px; font-weight: 700; }
input, select, textarea {
  width: 100%; min-height: 40px; border: 1px solid var(--line-strong); border-radius: 9px;
  background: #fff; color: var(--text); padding: 9px 11px; outline: none; font-size: 12px;
}
input:focus, select:focus, textarea:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(37,99,235,.10); }
textarea { min-height: 92px; resize: vertical; }
.actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 15px; }

.object-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.object-heading { min-width: 0; }
.object-heading h2 { margin: 0 0 4px; font-size: 21px; letter-spacing: -.02em; }
.tabs { display: flex; gap: 6px; overflow: auto; padding-bottom: 5px; margin-bottom: 18px; }
.tab { flex: 0 0 auto; min-height: 36px; border: 1px solid var(--line); background: #fff; color: #4b5563; border-radius: 9px; padding: 8px 11px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.tab:hover { background: #f8fafc; }
.tab.active { background: var(--accent-soft); border-color: #bfdbfe; color: #1d4ed8; }
.object-info-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 0; padding: 0; overflow: hidden; }
.info-item { display: grid; gap: 6px; min-height: 92px; padding: 18px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.info-item:nth-child(3n) { border-right: 0; }
.info-item:nth-last-child(-n+3) { border-bottom: 0; }
.info-item span { color: var(--muted); font-size: 10px; font-weight: 700; }
.info-item strong { color: var(--text); font-size: 13px; line-height: 1.45; font-weight: 650; }
.summary-metrics .card { min-height: 118px; }

.empty { padding: 30px; text-align: center; color: var(--muted); }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 80; padding: 11px 15px; border-radius: 10px; background: #111827; color: #fff; font-size: 12px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

.modal-backdrop { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; background: rgba(15,23,42,.48); }
.modal { width: min(760px,100%); max-height: 90vh; overflow: auto; background: #fff; border-radius: 16px; box-shadow: 0 28px 80px rgba(15,23,42,.2); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 17px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-body { padding: 20px; }
.icon-btn { border: 0; background: transparent; color: #6b7280; font-size: 23px; }

body.auth-locked .app-shell { visibility: hidden; }
.auth-gate { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 24px; background: linear-gradient(145deg,#eff6ff 0%,#f8fafc 48%,#eef2ff 100%); }
.auth-card { width: min(440px,100%); background: #fff; border: 1px solid #dbe4f0; border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { color: #111827; }
.auth-kicker { color: var(--accent); }
.auth-brand .brand-mark { background: var(--accent); color: #fff; }
.user-avatar { background: var(--accent-soft) !important; color: #1d4ed8 !important; }
.user-chip { border-color: var(--line) !important; background: #fff !important; }

@media (max-width: 1180px) {
  .grid.cols-4 { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .object-info-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .info-item:nth-child(3n) { border-right: 1px solid var(--line); }
  .info-item:nth-child(2n) { border-right: 0; }
  .info-item:nth-last-child(-n+3) { border-bottom: 1px solid var(--line); }
  .info-item:nth-last-child(-n+2) { border-bottom: 0; }
}

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 50; left: 0; top: 0; width: 280px; transform: translateX(-105%); transition: .2s ease; box-shadow: 12px 0 32px rgba(15,23,42,.12); }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-grid; place-items: center; }
  .topbar { min-height: 64px; padding: 10px 14px; }
  .topbar-title h1 { font-size: 20px; max-width: 46vw; }
  .content { padding: 18px 14px 48px; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .object-head { align-items: flex-start; flex-direction: column; }
  .object-info-grid { grid-template-columns: 1fr; }
  .info-item, .info-item:nth-child(2n), .info-item:nth-child(3n), .info-item:nth-last-child(-n+2), .info-item:nth-last-child(-n+3) { border-right: 0; border-bottom: 1px solid var(--line); }
  .info-item:last-child { border-bottom: 0; }
  .section-head { align-items: flex-start; flex-direction: column; }
  .section-head > .inline { width: 100%; }
  .section-head > .inline > * { flex: 1 1 auto; }
}
