:root {
  --bg: #f4f7f5;
  --panel: #ffffff;
  --text: #17211d;
  --muted: #64756e;
  --line: #dce6e1;
  --brand: #206a5d;
  --brand-dark: #174d44;
  --warn: #b04846;
  --soft: #eef6f2;
  --gold: #f4d35e;
  --shadow: 0 14px 36px rgba(30, 60, 48, .08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 15px;
}

body { overflow-x: hidden; }

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .58;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.55;
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(32, 106, 93, .55);
  box-shadow: 0 0 0 3px rgba(32, 106, 93, .1);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

h1, h2, h3, p {
  margin-top: 0;
}

h1 { font-size: 26px; line-height: 1.2; margin-bottom: 6px; }
h2 { font-size: 21px; line-height: 1.25; margin-bottom: 6px; }
h3 { font-size: 17px; line-height: 1.35; margin-bottom: 0; }
p { line-height: 1.65; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(360px, 470px);
  gap: 32px;
  align-items: center;
  padding: 48px;
}

.auth-left {
  max-width: 620px;
}

.auth-badge,
.brand-badge,
.eyebrow,
.stage-badge,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--soft);
  color: var(--brand);
  font-weight: 700;
  font-size: 12px;
}

.auth-title {
  margin: 18px 0 12px;
  font-size: 38px;
}

.auth-subtitle {
  max-width: 520px;
  color: var(--muted);
  font-size: 16px;
}

.auth-right {
  display: grid;
  gap: 16px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  background: #ffffff;
  border-right: 1px solid var(--line);
}

.brand h1 {
  margin: 10px 0 4px;
  font-size: 20px;
}

.brand p,
.small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.nav {
  display: grid;
  gap: 7px;
}

.nav button {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 11px 12px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-weight: 700;
}

.nav button:hover,
.nav button.active {
  background: var(--soft);
  color: var(--brand);
}

.user-box {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.main {
  min-width: 0;
  padding: 22px 28px 44px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.section-head,
.item-head,
.log-row,
.task-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-head {
  margin-bottom: 14px;
}

.row-actions,
.btn-row,
.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.form-grid,
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
  font-weight: 700;
}

.btn:hover {
  border-color: rgba(32, 106, 93, .45);
  background: #f8fbf9;
}

.btn-primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-dark);
  color: #fff;
}

.btn-light {
  background: #f8fbf9;
}

.pill {
  border: 1px solid var(--line);
  background: #fff;
}

.pill.active {
  border-color: rgba(32, 106, 93, .35);
  background: var(--soft);
}

.stage-badge.risk,
.risk {
  color: var(--warn);
  background: rgba(176, 72, 70, .09);
}

.stage-new_lead { color: #2f6fa3; background: rgba(47, 111, 163, .1); }
.stage-trial_booked { color: #8a6216; background: rgba(244, 211, 94, .22); }
.stage-trial_done { color: #6c4fa3; background: rgba(108, 79, 163, .12); }
.stage-active { color: var(--brand); background: var(--soft); }
.stage-renewal_due { color: #a35b2f; background: rgba(163, 91, 47, .11); }

.stat-card {
  min-height: 116px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat-value {
  margin: 8px 0 4px;
  font-size: 28px;
  font-weight: 800;
}

.task-row,
.item,
.log-row {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 10px;
}

.list {
  display: grid;
  gap: 10px;
}

.empty,
.flash,
.notice {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  color: var(--muted);
  padding: 12px;
  line-height: 1.6;
}

.flash {
  border-style: solid;
  border-color: rgba(32, 106, 93, .25);
  background: var(--soft);
  color: var(--brand);
}

.notice {
  border-style: solid;
  border-color: rgba(244, 211, 94, .55);
  background: rgba(244, 211, 94, .16);
  color: #5f4b16;
}

.bar {
  width: 100%;
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1ef;
}

.bar i {
  display: block;
  height: 100%;
  background: var(--brand);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
}

details {
  border-radius: 8px;
}

summary {
  cursor: pointer;
  color: var(--brand);
  font-weight: 700;
}

@media (max-width: 980px) {
  .auth-shell,
  .app-shell {
    grid-template-columns: 1fr;
  }

  .auth-shell {
    padding: 24px;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main {
    padding: 18px;
  }

  .stats-grid,
  .form-grid,
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar,
  .section-head,
  .item-head,
  .task-row,
  .log-row {
    align-items: stretch;
    flex-direction: column;
  }

  .auth-title {
    font-size: 30px;
  }

  .row-actions .btn,
  .btn-row .btn {
    flex: 1 1 auto;
  }
}
