:root {
  --bg: #f5f4ed;
  --surface: rgba(250, 249, 245, 0.96);
  --surface-soft: rgba(250, 249, 245, 0.92);
  --line: rgba(240, 238, 230, 0.8);
  --text: #141413;
  --muted: #5e5d59;
  --accent: #c96442;
  --accent-strong: #d97757;
  --accent-soft: #f5ebe4;
  --accent-ink: #8b4513;
  --slate: #4d4c48;
  --ok: #2a7a56;
  --warn: #9b5a15;
  --danger: #b53333;
  --shadow: 0 8px 32px rgba(20, 20, 18, 0.10), 0 2px 8px rgba(20, 20, 18, 0.06);
  --radius-xl: 16px;
  --radius-md: 12px;
  --sidebar: rgba(20, 20, 19, 0.97);
  --sidebar-soft: rgba(255, 255, 255, 0.06);
  --stone: #87867f;
  --border-warm: #e8e6dc;
  --input-bg: rgba(255, 255, 255, 0.98);
  --card-bg: rgba(250, 249, 245, 0.96);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-tap-highlight-color: transparent; }

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

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ── Background ── */
.app-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 30% 0%, rgba(201, 100, 66, 0.04), transparent 60%);
}

/* ── Shell / layout ── */
.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 22px 18px;
  background: linear-gradient(180deg, #141413 0%, #1e1e1c 100%);
  color: #f7f2ec;
  border-right: 1px solid rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 8px; }

.sidebar-brand {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  padding: 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.06) 0%, rgba(255,255,255,0.02) 100%);
  border: 1px solid rgba(255,255,255,0.06);
}
.brand-mark-img {
  width: 42px;
  height: 42px;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 6px 14px rgba(242, 118, 46, 0.28));
}
.sidebar-brand-copy {
  display: grid;
  gap: 2px;
}
.sidebar-brand-copy .kicker {
  color: rgba(247, 242, 236, 0.46);
  letter-spacing: 0.12em;
  margin: 0;
  font-size: 0.68rem;
}
.sidebar-brand-copy h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: #fff;
}
.sidebar-brand-copy small {
  display: block;
  color: rgba(247, 242, 236, 0.52);
  font-size: 0.82rem;
}

.sidebar-nav {
  flex: 1 1 auto;
  display: grid;
  gap: 4px;
  align-content: start;
}

.nav-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 46px;
  padding: 0 14px 0 16px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: rgba(247, 242, 236, 0.76);
  text-align: left;
  font-size: 0.97rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 180ms ease, color 180ms ease;
}
.nav-btn::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 999px;
  background: transparent;
  transition: background 180ms ease;
}
.nav-btn:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-btn.active { background: rgba(255,255,255,0.09); color: #fff; }
.nav-btn.active::before { background: var(--accent); }
.nav-btn span:last-child {
  font-size: 0.8rem;
  color: rgba(247, 242, 236, 0.46);
  font-weight: 400;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: grid;
  gap: 8px;
}
.sidebar-foot .user-info {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
}
.sidebar-foot .user-info div { font-size: 0.9rem; color: rgba(247, 242, 236, 0.85); }
.sidebar-foot .user-info small { color: rgba(247, 242, 236, 0.46); font-size: 0.78rem; }

/* ── Workspace / main ── */
.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Topbar ── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding: 22px 28px 0;
}
.topbar .brand { flex: 1 1 auto; min-width: 0; }
.topbar .brand .kicker { margin: 0 0 4px; }
.topbar h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.4rem, 2vw, 1.9rem);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0.01em;
}
.topbar-logo {
  height: 34px;
  width: auto;
  display: block;
  opacity: 0.75;
  flex-shrink: 0;
}
.brand-logo-extended {
  height: 38px;
  width: auto;
  display: block;
}

/* ── Main page ── */
.page {
  flex: 1 1 auto;
  padding: 22px 28px 32px;
  display: grid;
  gap: 20px;
  align-content: start;
}

/* ── Kicker / eyebrow ── */
.kicker {
  margin: 0 0 2px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.70rem;
  font-weight: 700;
  color: var(--muted);
}

/* ── Misc text ── */
.small { font-size: 0.88rem; color: var(--muted); line-height: 1.45; }
.mono { font-family: "DM Mono", "Courier New", monospace; }

/* ── Grid helpers ── */
.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: 1fr 320px; }

/* ── Stats / metric cards ── */
.stat {
  padding: 20px;
  border: 1px solid var(--border-warm);
  border-radius: var(--radius-xl);
  background: var(--card-bg);
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
}
.stat strong { font-size: 2rem; font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
.stat-label { font-size: 0.82rem; color: var(--stone); letter-spacing: 0.12px; text-transform: uppercase; }

/* ── Panels ── */
.panel {
  padding: 22px;
  border: 1px solid var(--border-warm);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel h2, .panel h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.panel h2 { font-size: 1.35rem; }
.panel h3 { font-size: 1.1rem; }
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 18px;
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; margin-top: 14px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--border-warm); text-align: left; vertical-align: top; }
th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.12px; color: var(--stone); font-weight: 600; }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 160ms ease, box-shadow 160ms ease;
  background: var(--border-warm);
  color: var(--slate);
  box-shadow: 0 0 0 1px rgba(232, 230, 220, 0.8);
  white-space: nowrap;
}
.btn:hover { box-shadow: 0 0 0 1px #d1cfc5; background: #dfddd3; }
.btn.primary { background: var(--accent); color: #faf9f5; box-shadow: 0 0 0 1px var(--accent); }
.btn.primary:hover { background: #b85a3a; box-shadow: 0 0 0 1px #b85a3a; }
.btn.secondary { background: var(--border-warm); color: var(--slate); }
.btn.danger { background: rgba(181, 51, 51, 0.10); color: var(--danger); box-shadow: none; }
.btn.danger:hover { background: rgba(181, 51, 51, 0.16); }
.btn.full { width: 100%; }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 0.92rem; letter-spacing: 0.12px; }
input, select, textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(56, 152, 236, 0.35);
  border-color: #3898ec;
}
textarea { resize: vertical; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--border-warm);
  color: var(--muted);
}
.badge.ok { background: rgba(42, 122, 86, 0.12); color: var(--ok); }
.badge.pending { background: rgba(201, 100, 66, 0.12); color: var(--accent-ink); }
.badge.warn { background: rgba(155, 90, 21, 0.12); color: var(--warn); }
.badge.danger { background: rgba(181, 51, 51, 0.10); color: var(--danger); }

/* ── Messages ── */
.notice {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: rgba(42, 122, 86, 0.08);
  border: 1px solid rgba(42, 122, 86, 0.20);
  color: var(--ok);
  font-weight: 500;
}
.error {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: rgba(181, 51, 51, 0.08);
  border: 1px solid rgba(181, 51, 51, 0.20);
  color: var(--danger);
  font-weight: 500;
}
.muted-block {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  border: 1px solid var(--border-warm);
  color: var(--muted);
  line-height: 1.6;
}

/* ── Modal viewer ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 19, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}
.modal-shell {
  background: var(--card-bg);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-warm);
  box-shadow: 0 24px 64px rgba(20, 20, 18, 0.18);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
  overflow: hidden;
  width: min(900px, 100%);
}
.modal-viewer { width: min(960px, calc(100vw - 40px)); height: calc(100vh - 60px); }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-warm);
  flex-shrink: 0;
}
.modal-head h3 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 500; font-size: 1.1rem; }
.modal-head .actions { display: flex; gap: 8px; flex-shrink: 0; }
.modal-body { flex: 1 1 auto; overflow: auto; }
.modal-body iframe { width: 100%; height: 100%; border: 0; display: block; }

/* ── Login ── */
.login-wrap {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 32px;
}
.login-shell {
  width: min(420px, 100%);
}
.login-card {
  padding: 36px 32px 32px;
  border: 1px solid var(--border-warm);
  border-radius: var(--radius-xl);
  background: var(--card-bg);
  box-shadow: var(--shadow);
}
.login-brand {
  margin-bottom: 22px;
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-lockup h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.3rem;
  font-weight: 500;
}
.brand-logo-extended {
  height: 40px;
  width: auto;
  display: block;
}
.login-card .grid { display: grid; gap: 14px; margin-top: 4px; }
.login-card .btn { min-height: 46px; margin-top: 4px; }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .topbar { padding: 16px 16px 0; }
  .page { padding: 16px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
}
@media (max-width: 480px) {
  .grid-4 { grid-template-columns: 1fr; }
}

/* Responsive table → card layout on small screens */
@media (max-width: 640px) {
  .responsive-table thead { display: none; }
  .responsive-table tbody tr {
    display: grid;
    gap: 6px;
    padding: 14px;
    border: 1px solid var(--border-warm);
    border-radius: 12px;
    margin-bottom: 10px;
    background: var(--surface-soft);
  }
  .responsive-table tbody tr + tr { border-top: none; }
  .responsive-table td {
    border: 0;
    padding: 0;
    display: grid;
    gap: 2px;
  }
  .responsive-table td[data-label]::before {
    content: attr(data-label);
    font-size: 0.70rem;
    text-transform: uppercase;
    letter-spacing: 0.10em;
    color: var(--stone);
    font-weight: 600;
  }
}

@media (hover: none) {
  .btn:hover { box-shadow: 0 0 0 1px rgba(232, 230, 220, 0.8); background: var(--border-warm); }
  .btn.primary:hover { background: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
}
