:root {
  --ink: #13212b;
  --muted: #5c6b76;
  --paper: #f4efe6;
  --paper-2: #efe7d8;
  --card: #fffdf8;
  --line: #d9d0c0;
  --accent: #0f6e6a;
  --accent-2: #c45c26;
  --good: #1f7a4c;
  --warn: #b7791f;
  --bad: #a33b2b;
  --sidebar: #102029;
  --sidebar-text: #d7e0e6;
  --shadow: 0 10px 30px rgba(19, 33, 43, 0.06);
  --radius: 16px;
  --font: "Source Sans 3", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 10% -10%, rgba(15,110,106,.12), transparent 60%),
    radial-gradient(700px 380px at 100% 0%, rgba(196,92,38,.10), transparent 55%),
    var(--paper);
}
button, input, select { font: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  font-family: var(--display);
  font-size: 2.4rem;
  margin: 0 0 8px;
}
.login-sub, .eyebrow {
  color: var(--muted);
  margin: 0;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .75rem;
  font-weight: 700;
}
.login-card form {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}
.login-card label {
  display: grid;
  gap: 6px;
  font-size: .92rem;
  font-weight: 600;
}
.login-card input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
}
.login-card button, .btn {
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
}
.error { color: var(--bad); min-height: 1.2em; margin: 0; }

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 10px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #1a9b95, #0c5855);
  color: white;
  font-family: var(--display);
  font-weight: 700;
}
.brand strong { display: block; color: white; font-size: 1.05rem; }
.brand small { color: #91a4b0; }
#nav { display: grid; gap: 4px; flex: 1; }
#nav button {
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
}
#nav button:hover, #nav button.active {
  background: rgba(255,255,255,.08);
  color: white;
}
#logout.ghost, .ghost {
  border: 1px solid rgba(255,255,255,.14);
  background: transparent;
  color: inherit;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}

.main { padding: 28px 28px 48px; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 22px;
}
.topbar h2 {
  font-family: var(--display);
  font-size: clamp(1.6rem, 2.4vw, 2.2rem);
  margin: 4px 0 0;
}
.topbar-meta { color: var(--muted); font-size: .92rem; text-align: right; }

.content { display: grid; gap: 18px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.stat, .card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat { padding: 18px 18px 16px; }
.stat .label { color: var(--muted); font-size: .86rem; font-weight: 600; }
.stat .value {
  font-family: var(--display);
  font-size: 1.9rem;
  margin-top: 6px;
  line-height: 1.1;
}
.stat .hint { color: var(--muted); font-size: .82rem; margin-top: 8px; }

.card { padding: 18px; }
.card h3 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}
.card p { color: var(--muted); line-height: 1.55; }
.callout {
  border-left: 4px solid var(--accent);
  background: #eef7f6;
  padding: 14px 16px;
  border-radius: 0 12px 12px 0;
}
.callout strong { color: var(--ink); }

.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }

.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
}
th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: rgba(15,110,106,.04); }
#conv-rows tr { cursor: pointer; transition: background .15s ease; }
#conv-rows tr.active td {
  background: rgba(15, 110, 106, 0.12);
}
#conv-rows tr.active td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}
#conv-rows tr.active strong { color: var(--accent); }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: .78rem;
  font-weight: 700;
  background: var(--paper-2);
  color: var(--ink);
}
.pill.good { background: #e5f5eb; color: var(--good); }
.pill.warn { background: #f8efd8; color: var(--warn); }
.pill.bad { background: #f8e4e0; color: var(--bad); }
.pill.teal { background: #dff3f1; color: var(--accent); }

.filters {
  display: grid;
  grid-template-columns: 1.4fr repeat(4, 1fr) auto;
  gap: 10px;
  align-items: end;
}
.filters label {
  display: grid;
  gap: 6px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
}
.filters input, .filters select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: white;
}
.detail { display: grid; gap: 16px; }
.conv-list-card { min-width: 0; }
.drawer-root {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
}
.drawer-root.open { pointer-events: auto; }
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 32, 41, 0.42);
  opacity: 0;
  transition: opacity .2s ease;
}
.drawer-root.open .drawer-backdrop { opacity: 1; }
.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: min(480px, 100%);
  background: var(--card);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 40px rgba(19, 33, 43, 0.14);
  transform: translateX(104%);
  transition: transform .22s ease;
  display: flex;
  flex-direction: column;
}
.drawer-root.open .drawer-panel { transform: translateX(0); }
.drawer-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--line);
}
.drawer-header h3 {
  margin: 4px 0 0;
  font-family: var(--display);
  font-size: 1.35rem;
}
.drawer-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink);
}
.drawer-body {
  padding: 18px 20px 28px;
  overflow: auto;
  flex: 1;
}
.kv { display: grid; gap: 8px; }
.kv div {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.kv span { color: var(--muted); }
.list-check { margin: 0; padding-left: 18px; color: var(--muted); }
.list-check li { margin: 6px 0; }
.priority-list { display: grid; gap: 10px; }
.priority-item {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.priority-item .num {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent);
  color: white;
  font-weight: 700;
}
.month-tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.month-tabs button {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.month-tabs button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.month-tabs button.year {
  font-weight: 700;
  border-color: var(--accent-2);
  color: var(--accent-2);
}
.month-tabs button.year.active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: white;
}
.range-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}
.range-tabs button {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 600;
}
.range-tabs button.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
.month-subtabs {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .grid-4, .grid-3, .grid-2, .filters { grid-template-columns: 1fr; }
  .drawer-panel { width: min(100%, 100vw); }
}
