:root {
  --navy: #0b1f33;
  --navy-2: #132a44;
  --navy-3: #1a3a58;
  --navy-ink: #7aa0b8;
  --teal: #1a6f8b;
  --teal-bright: #5ec8d8;
  --gold: #c9a227;
  --bg: #f3f6f9;
  --surface: #ffffff;
  --text: #15202b;
  --muted: #5c6b7a;
  --line: #dce4eb;
  --accent: #1a6f8b;
  --accent-text: #ffffff;
  --ok: #0f7b4c;
  --warn: #9a6700;
  --danger: #b42318;
  --danger-bg: #fff4f2;
  --sidebar-w: 248px;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 31, 51, 0.06), 0 8px 24px rgba(11, 31, 51, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #145a72; }

.icon {
  width: 1.15em;
  height: 1.15em;
  display: inline-block;
  vertical-align: -0.18em;
  flex-shrink: 0;
}

/* App shell */
body.is-app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, var(--navy) 0%, #081624 100%);
  color: #d7e6ef;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow: auto;
}
.sidebar a { color: inherit; text-decoration: none; }
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  color: #fff !important;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 1.05rem;
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--navy-3);
  color: var(--teal-bright);
  display: grid;
  place-items: center;
}
.brand-mark .icon { width: 20px; height: 20px; }
.icon-lg { width: 1.5rem; height: 1.5rem; }
.sprite-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.nav-group { padding: 8px 12px 4px; }
.nav-label {
  margin: 10px 10px 6px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--navy-ink);
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: #c5d7e4;
  font-size: 14px;
  font-weight: 500;
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.is-active {
  background: rgba(94, 200, 216, 0.14);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--teal-bright);
}
.nav-link .icon { opacity: 0.9; }

.sidebar-foot {
  margin-top: auto;
  padding: 16px 12px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 12px;
  font-size: 12px;
  color: var(--navy-ink);
  word-break: break-all;
}
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--navy-3);
  color: var(--teal-bright);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.sidebar-foot form { margin: 0; }
.sidebar-foot .nav-link,
.sidebar-foot button.nav-link {
  width: 100%;
  background: transparent;
  border: 0;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.app-main { min-width: 0; display: flex; flex-direction: column; }
.topbar-mobile {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--navy);
  color: #fff;
}
.topbar-mobile .brand { padding: 0; }
.nav-toggle {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 32px 48px; width: 100%; }
h1 { font-size: 1.55rem; margin: 0 0 6px; letter-spacing: -0.03em; font-weight: 700; }
h2 { font-size: 1rem; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 0.95rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.eyebrow {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teal);
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head p { margin: 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.panel + .panel, .panel + h2, h2 + .panel { margin-top: 16px; }
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 24px 0 12px;
}
.section-title .icon { color: var(--teal); }

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar input, .toolbar select {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  min-width: 160px;
}
.toolbar input { min-width: 220px; }

.btn, button.btn, input[type="submit"].btn, input[type="submit"] {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
}
.btn:hover { background: #145a72; color: #fff; text-decoration: none; }
.btn.secondary { background: #e8eef3; color: var(--navy); }
.btn.secondary:hover { background: #d7e2ea; color: var(--navy); }
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.btn.danger { background: var(--danger); }
.btn-block { width: 100%; justify-content: center; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.card.warn { border-color: #f0b4ae; background: var(--danger-bg); }
.card .value { font-size: 1.65rem; font-weight: 700; letter-spacing: -0.03em; }
.card .label { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #e8f4f7;
  color: var(--teal);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.stat-icon .icon { width: 20px; height: 20px; }
.stat-card.warn .stat-icon { background: #fdecea; color: var(--danger); }

.timeline-item {
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}
.timeline-item:last-child { border-bottom: 0; }
.timeline-item p { margin: 6px 0 0; font-size: 14px; }
.pill {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  background: #eef3f7;
  border-radius: 999px;
  padding: 2px 8px;
  margin-right: 4px;
}
.pill.danger { color: var(--danger); background: #fdecea; font-weight: 600; }
.row-danger td { background: var(--danger-bg); }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
th {
  color: var(--muted);
  font-weight: 650;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #f7fafc;
}
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f7fbfd; }
.row-danger:hover td { background: #ffebe8; }

.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { margin-top: 18px; display: flex; gap: 8px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(26, 111, 139, 0.25);
  border-color: var(--teal);
}
input[type="checkbox"] { width: auto; margin-right: 8px; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row label { margin: 0; color: var(--text); }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li {
  padding: 10px 14px;
  background: #e7f5ea;
  border: 1px solid #c6e4ce;
  color: #14532d;
  border-radius: 8px;
  margin-bottom: 8px;
}

.kanban {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}
.kanban-col {
  background: #eef3f7;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 280px;
}
.kanban-col h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.deal {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(11,31,51,0.05);
}
.deal strong { display: block; margin-bottom: 4px; }
.deal form { margin-top: 8px; }

.empty-state {
  text-align: center;
  padding: 36px 20px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty-state img { display: block; margin: 0 auto 14px; max-width: 240px; }
.empty-state h3 { margin-bottom: 6px; }
.empty-state .btn { margin-top: 10px; }

code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12.5px;
  background: #eef3f7;
  padding: 2px 6px;
  border-radius: 4px;
}

/* Auth / login */
body.is-auth { background: var(--navy); }
.auth-split {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  min-height: 100vh;
}
.auth-brand {
  padding: 48px 56px;
  color: #d7e6ef;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(94,200,216,0.18), transparent 50%),
    linear-gradient(165deg, var(--navy) 0%, #081624 100%);
}
.auth-brand h1 { color: #fff; font-size: 2rem; margin: 12px 0 8px; }
.auth-brand p { max-width: 420px; color: #9bb4c6; }
.auth-hero { width: min(100%, 480px); margin-top: 32px; border-radius: 16px; box-shadow: 0 24px 60px rgba(0,0,0,0.28); }
.auth-panel {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin-bottom: 6px; }
.auth-card form p { margin: 0 0 14px; }
.auth-card form p label { margin-bottom: 6px; }
.errorlist { color: var(--danger); font-size: 13px; padding-left: 16px; margin: 4px 0 0; }

@media (max-width: 980px) {
  body.is-app { display: block; }
  .sidebar {
    position: fixed;
    z-index: 40;
    width: var(--sidebar-w);
    transform: translateX(-110%);
    transition: transform 0.2s ease;
  }
  body.nav-open .sidebar { transform: none; }
  .topbar-mobile { display: flex; }
  .cards, .kanban, .grid-2, .form-grid, .auth-split { grid-template-columns: 1fr; }
  .wrap { padding: 20px 16px 40px; }
  .auth-brand { display: none; }
  body.is-auth { background: var(--bg); }
}
