:root {
  --navy: #1F3A4A;
  --navy-dark: #16293480;
  --rust: #A13A2E;
  --rust-dark: #832E24;
  --cream: #F7F3EC;
  --slate: #2B3E4A;
  --white: #FFFFFF;
  --grey: #6B7680;

  --bg: var(--cream);
  --surface: var(--white);
  --border: #E4DCC9;
  --text: var(--navy);
  --text-muted: var(--grey);
  --row-alt: var(--cream);
  --row-hover: #F0E9D8;
}

html[data-theme="dark"] {
  --bg: #12202A;
  --surface: #1B2E3A;
  --border: #2C4351;
  --text: #EDEFF1;
  --text-muted: #9FB0BA;
  --row-alt: #182A35;
  --row-hover: #22394A;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.15s ease, color 0.15s ease;
}

a { color: var(--rust); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Top brand bar ─────────────────────────────────────────────────────── */
.shell-header {
  background: var(--navy);
  border-bottom: 4px solid var(--rust);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0.6rem 1.5rem;
}

.shell-brand { display: flex; align-items: center; gap: 0.9rem; }
.shell-brand img { height: 56px; width: auto; display: block; }

.shell-brand .brand-text h1 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: 0.08em;
  color: var(--white);
  font-weight: 800;
}

.shell-brand .brand-text p {
  margin: 0;
  font-size: 0.78rem;
  font-style: italic;
  letter-spacing: 0.03em;
  color: #D6C79A;
}

.shell-nav { display: flex; align-items: center; flex-wrap: wrap; gap: 1.1rem; row-gap: 0.5rem; }
.shell-nav a {
  color: var(--cream);
  font-size: 0.9rem;
  font-weight: 600;
}
.shell-nav a:hover { color: var(--white); text-decoration: none; }
.shell-nav .btn {
  background: var(--rust);
  color: var(--white) !important;
  padding: 0.4rem 0.9rem;
  border-radius: 4px;
  font-weight: 700;
}
.shell-nav .btn:hover { background: var(--rust-dark); }

.theme-toggle {
  background: transparent;
  border: 1.5px solid #4A6272;
  color: var(--cream);
  border-radius: 999px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle:hover { border-color: var(--rust); }
.theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }

/* ── Page shell ────────────────────────────────────────────────────────── */
.shell-main { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem 3rem; }

.shell-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(31, 58, 74, 0.08);
}

/* ── Dashboard header ──────────────────────────────────────────────────── */
.dash-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.dash-head h2 { margin: 0 0 0.15rem; font-size: 1.5rem; }
.dash-sub { margin: 0; color: var(--text-muted); font-size: 0.92rem; }

/* ── Stat cards ────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
}
.stat-card.stat-alert { border-color: var(--rust); }
.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.stat-value { font-size: 1.7rem; font-weight: 800; }
.stat-value.stat-green { color: #2E8B57; }
.stat-value.stat-red { color: var(--rust); }

/* ── Search ────────────────────────────────────────────────────────────── */
.search-input {
  width: 100%;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}
.search-input:focus { outline: none; border-color: var(--rust); }

/* ── Form inputs (Django-rendered) ───────────────────────────────────────── */
input[type="text"], input[type="email"], input[type="number"],
input[type="date"], input[type="datetime-local"], select, textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}
label { display: block; margin-bottom: 0.9rem; font-size: 0.82rem; color: var(--text-muted); }
.remove-row { color: var(--rust); font-weight: 700; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ── Searchable customer picker (Add Lead form) ──────────────────────────── */
.customer-search-results {
  display: none;
  position: absolute;
  z-index: 20;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.customer-search-item {
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.customer-search-item:hover { background: var(--row-hover); }

/* ── Status pills ──────────────────────────────────────────────────────── */
.pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--white);
}
.pill-blue   { background: #2E75B6; }
.pill-teal   { background: #00707F; }
.pill-purple { background: #5C2D91; }
.pill-amber  { background: #C5761E; }
.pill-green  { background: #2E8B57; }
.pill-grey   { background: #6B7680; }
.pill-red    { background: #A13A2E; }

/* ── Inline lead-status picker — looks like a pill, acts like a select ──── */
.pill-select {
  display: inline-block;
  width: auto;
  padding: 0.2rem 1.6rem 0.2rem 0.6rem;
  border-radius: 999px;
  border: none;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--white);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--white) 50%), linear-gradient(135deg, var(--white) 50%, transparent 50%);
  background-position: right 0.7rem top 55%, right 0.45rem top 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.pill-select option { color: var(--text); background: var(--surface); }

/* ── Empty state ───────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
}
.empty-state img { height: 64px; opacity: 0.85; margin-bottom: 1rem; }
.empty-state h3 { margin: 0 0 0.3rem; }
.empty-state p { color: var(--text-muted); margin: 0 0 1.2rem; }

/* ── Table ─────────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.shell-table { border-collapse: collapse; width: 100%; min-width: 640px; }
table.shell-table th, table.shell-table td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  font-size: 14px;
}
table.shell-table th {
  background: var(--navy);
  color: var(--white);
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.04em;
}
table.shell-table th a { color: inherit; text-decoration: none; white-space: nowrap; }
table.shell-table th a:hover { text-decoration: underline; }
table.shell-table tr:nth-child(even) { background: var(--row-alt); }
table.shell-table tr:hover { background: var(--row-hover); }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  background: var(--rust);
  color: var(--white);
  padding: 0.55rem 1.1rem;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.9rem;
}
.btn:hover { background: var(--rust-dark); text-decoration: none; }
.btn-outline {
  background: transparent;
  color: var(--navy);
  border: 1.5px solid var(--navy);
}
.btn-outline:hover { background: var(--navy); color: var(--white); }

/* ── Footer ────────────────────────────────────────────────────────────── */
.shell-footer {
  background: var(--slate);
  color: #B9C4CC;
  text-align: center;
  font-size: 0.8rem;
  padding: 1.2rem;
  margin-top: 2rem;
}

/* ── Login page ────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: calc(100vh - 90px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.login-card {
  text-align: center;
  padding: 2.5rem 3rem;
  max-width: 420px;
}
.login-card img { height: 120px; margin-bottom: 1rem; }
.login-card h2 { margin: 0 0 0.2rem; color: var(--text); }
.login-card .motto { font-style: italic; color: var(--text-muted); margin-bottom: 1.8rem; }
.login-error { color: var(--rust); font-weight: 600; margin-bottom: 1rem; }

/* ── Collapsible "dropdown" sections (e.g. Recent Orders) ────────────────── */
.order-dropdown { padding: 1.1rem 1.2rem; }
.order-dropdown summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
  list-style: none;
}
.order-dropdown summary::-webkit-details-marker { display: none; }
.order-dropdown summary::before {
  content: "\25b6";
  display: inline-block;
  margin-right: 0.5rem;
  font-size: 0.7rem;
  color: var(--rust);
  transition: transform 0.15s ease;
}
.order-dropdown[open] summary::before { transform: rotate(90deg); }

/* ── Glossary info trigger + modal ────────────────────────────────────────── */
.info-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  color: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  margin-left: 4px;
  vertical-align: middle;
  border: none;
}
.info-trigger:hover { background: rgba(255,255,255,0.45); }
.glossary-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.glossary-overlay.open { display: flex; }
.glossary-box {
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 1.6rem;
  max-width: 420px;
  width: 100%;
  position: relative;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}
.glossary-box h3 { margin: 0 0 0.7rem; color: var(--rust); }
.glossary-box p { margin: 0; line-height: 1.5; }
.glossary-close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}
.glossary-close:hover { color: var(--rust); }

/* ── Small screens (phones / narrow tablets) ─────────────────────────────── */
@media (max-width: 640px) {
  .shell-header { padding: 0.6rem 1rem; }
  .shell-brand img { height: 42px; }
  .shell-brand .brand-text h1 { font-size: 1.1rem; }
  .shell-brand .brand-text p { font-size: 0.7rem; }
  .shell-nav { gap: 0.7rem; }
  .shell-main { padding: 1.2rem 1rem 2rem; }
  .stat-value { font-size: 1.35rem; }
  .login-card { padding: 2rem 1.3rem; max-width: 100%; }
  .login-card img { height: 90px; }
  .dash-head { align-items: flex-start; }
}
