:root {
  --ink: #10243a;
  --ink-2: #3a4b60;
  --muted: #6b7a8c;
  --line: #dbe3ec;
  --paper: #f5f7fa;
  --card: #ffffff;
  --navy: #0f2740;
  --navy-2: #173b5f;
  --gold: #c99a2e;
  --red: #b23a3a;
  --green: #2e7d5b;
  --blue: #2b6cb0;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(15, 39, 64, 0.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}
.hidden { display: none !important; }
h1, h2, h3, h4 { margin: 0 0 0.5rem; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }
a { color: var(--blue); }
small { color: var(--muted); font-weight: 400; }
.error { color: var(--red); min-height: 1.2em; margin: 0.4rem 0 0; }
.fineprint { color: var(--muted); font-size: 0.78rem; margin-top: 1rem; }
.lede { color: var(--ink-2); }

/* Auth */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(201, 154, 46, 0.22), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(23, 59, 95, 0.35), transparent 55%),
    linear-gradient(160deg, #0b1e33 0%, #10243a 55%, #143451 100%);
}
.auth-card {
  width: min(460px, 100%);
  background: var(--card);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}
.brand-large {
  width: 54px; height: 54px; border-radius: 14px;
  background: var(--navy); color: var(--gold);
  display: grid; place-items: center; font-weight: 800; letter-spacing: 0.5px;
  margin-bottom: 0.75rem;
}
.auth-card h1 { font-size: 1.9rem; letter-spacing: -0.02em; }
.auth-card h1 span, .brand strong span { color: var(--gold); }
.auth-links { display: flex; justify-content: space-between; gap: 1rem; margin: 1rem 0; flex-wrap: wrap; }
.link { background: none; border: 0; color: var(--blue); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; }
.stack { display: grid; gap: 0.8rem; }
.stack label, .field { display: grid; gap: 0.3rem; font-weight: 600; color: var(--ink-2); font-size: 0.86rem; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.62rem 0.7rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(43, 108, 176, 0.25); border-color: var(--blue); }
textarea { min-height: 90px; resize: vertical; }
button { font: inherit; cursor: pointer; }
button.primary {
  background: var(--navy); color: #fff; border: 0; border-radius: 10px;
  padding: 0.7rem 1rem; font-weight: 700;
}
button.primary:hover { background: var(--navy-2); }
button.ghost {
  background: transparent; border: 1px solid var(--line); border-radius: 9px;
  padding: 0.45rem 0.65rem; color: var(--ink-2);
}
button.ghost:hover { border-color: var(--navy); color: var(--navy); }
button.ghost.full { width: 100%; }
button.danger { background: var(--red); color: #fff; border: 0; border-radius: 9px; padding: 0.5rem 0.8rem; }
button.small { padding: 0.32rem 0.55rem; font-size: 0.8rem; }

/* Shell */
.shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--navy); color: #e8eef6;
  display: flex; flex-direction: column; gap: 1rem;
  padding: 1.1rem 0.9rem; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 0.65rem; align-items: center; }
.mark.small { width: 40px; height: 40px; border-radius: 11px; background: rgba(255,255,255,0.08); color: var(--gold); display: grid; place-items: center; font-weight: 800; }
.brand strong { display: block; font-size: 0.95rem; }
.brand small { color: #9db1c7; display: block; }
.nav { display: grid; gap: 0.25rem; margin-top: 0.4rem; }
.nav a {
  color: #c9d7e7; text-decoration: none; padding: 0.55rem 0.7rem; border-radius: 9px;
  display: flex; align-items: center; gap: 0.55rem; font-size: 0.9rem;
}
.nav a:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav a.active { background: rgba(201,154,46,0.16); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.sidebar-foot { margin-top: auto; display: grid; gap: 0.5rem; }
.user-chip { background: rgba(255,255,255,0.06); border-radius: 10px; padding: 0.6rem 0.7rem; font-size: 0.82rem; color: #c9d7e7; }
.user-chip strong { color: #fff; display: block; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 0.8rem; padding: 0.8rem 1.2rem;
  background: rgba(255,255,255,0.9); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10; backdrop-filter: blur(8px);
}
.search { flex: 1; max-width: 520px; }
.search input { background: #f3f6fa; }
.top-actions { display: flex; align-items: center; gap: 0.4rem; margin-left: auto; }
.menu-toggle { display: none; }
.pill { background: #fff4d6; color: #7a5a0b; border-radius: 999px; padding: 0.25rem 0.6rem; font-size: 0.75rem; font-weight: 700; }
.badge { background: var(--red); color: #fff; border-radius: 999px; padding: 0.05rem 0.4rem; font-size: 0.7rem; }
.view { padding: 1.3rem 1.4rem 3rem; max-width: 1250px; width: 100%; }

/* Content */
.page-head { display: flex; align-items: flex-start; gap: 1rem; justify-content: space-between; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; box-shadow: var(--shadow);
}
.card h2, .card h3 { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.kpi { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; }
.kpi small { font-size: 0.78rem; font-weight: 600; }
.muted { color: var(--muted); }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.82rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.status { display: inline-block; border-radius: 999px; padding: 0.16rem 0.55rem; font-size: 0.72rem; font-weight: 700; background: #eef2f7; color: var(--ink-2); }
.status.OPEN, .status.ISSUED, .status.ACTIVE, .status.APPROVED, .status.SENT { background: #e4f3ec; color: var(--green); }
.status.DRAFT, .status.PENDING, .status.PENDING_APPROVAL, .status.REQUESTED { background: #fff4d6; color: #7a5a0b; }
.status.CLOSED, .status.PAID, .status.SIGNED, .status.CONSENTED { background: #e7edf7; color: var(--blue); }
.status.SUSPENDED, .status.REJECTED, .status.VOID, .status.OVERDUE, .status.EXPIRED { background: #fbe7e7; color: var(--red); }
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.split { display: grid; grid-template-columns: 1.6fr 1fr; gap: 1rem; }
.list { display: grid; gap: 0.55rem; }
.list-item { border: 1px solid var(--line); border-radius: 10px; padding: 0.65rem 0.75rem; background: #fbfcfe; }
.list-item strong { display: block; }
.tabs { display: flex; gap: 0.35rem; border-bottom: 1px solid var(--line); margin: 0.8rem 0; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 0.5rem 0.7rem; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--navy); border-color: var(--gold); font-weight: 700; }
.inline-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.6rem; align-items: end; }
.inline-form .wide { grid-column: span 2; }
.notif-panel {
  position: fixed; right: 1.2rem; top: 4.2rem; width: min(380px, calc(100vw - 2rem));
  background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  max-height: 60vh; overflow: auto; padding: 0.5rem; z-index: 30;
}
.notif-panel .list-item { cursor: pointer; }
.toast {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 100;
  background: var(--navy); color: #fff; border-radius: 10px; padding: 0.7rem 1rem;
  box-shadow: var(--shadow); max-width: 380px;
}
.toast.bad { background: var(--red); }
.timeline { display: grid; gap: 0.5rem; }
.timeline .item { border-left: 3px solid var(--gold); padding-left: 0.7rem; }
.empty { color: var(--muted); padding: 1rem 0; }
.warning { background: #fff8e8; border: 1px solid #f0d9a8; border-radius: 10px; padding: 0.7rem 0.8rem; color: #6b4f0c; }
.danger-zone { border-color: #f0c9c9; background: #fffafa; }
.checkbox { display: flex; gap: 0.45rem; align-items: center; font-weight: 500; }
.checkbox input { width: auto; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.stat-row { display: flex; justify-content: space-between; gap: 1rem; padding: 0.35rem 0; border-bottom: 1px dashed var(--line); }
.stat-row:last-child { border-bottom: 0; }

@media (max-width: 1000px) {
  .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; transform: translateX(-100%); transition: transform 0.2s ease; z-index: 50; }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-block; }
  .grid.two, .grid.three, .grid.four { grid-template-columns: 1fr; }
  .view { padding: 1rem; }
  .topbar { padding: 0.65rem 0.8rem; }
  .search { max-width: none; }
}
