/* BulkMail-Agent — Data-Dense Dashboard design system
   Palette: navy + blue + paid-green. Fira Sans / Fira Code.
   Light + dark mode via prefers-color-scheme. */

/* ---- Tokens ---------------------------------------------------------- */
:root {
  /* Webenix Solutions theme — deep navy #0C081E + lime accent #D0F601 */
  --primary: #0c081e;          /* deep navy — nav, headings */
  --accent: #0c081e;           /* navy — links, default buttons */
  --accent-hover: #241d44;
  --brand: #d0f601;            /* lime — brand highlight / hero CTA */
  --brand-hover: #bfe000;
  --on-brand: #0c081e;         /* text on lime */
  --btn-fg: #ffffff;           /* text on default (navy) buttons */
  --success: #059669;          /* green — approve / send */
  --success-hover: #047857;
  --danger: #dc2626;           /* red — reject / delete */
  --danger-hover: #b91c1c;

  --bg: #f9f9f9;
  --surface: #ffffff;
  --surface-2: #f2f3f5;
  --fg: #0c081e;
  --muted-fg: #71717a;
  --border: #dddddf;
  --ring: rgba(208, 246, 1, .55);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, .08), 0 2px 4px -2px rgba(15, 23, 42, .06);

  --radius: 8px;
  --radius-sm: 6px;
  --space: 8px;
  --font: "Fira Sans", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #0c081e;
    --accent: #d0f601;         /* lime reads well as a link/accent on dark */
    --accent-hover: #e4ff4d;
    --brand: #d0f601;
    --brand-hover: #bfe000;
    --on-brand: #0c081e;
    --btn-fg: #0c081e;         /* dark text on lime buttons in dark mode */
    --success: #10b981;
    --success-hover: #34d399;
    --danger: #ef4444;
    --danger-hover: #f87171;

    --bg: #0c081e;
    --surface: #16112e;
    --surface-2: #1f1840;
    --fg: #ece9f5;
    --muted-fg: #a09bb8;
    --border: #2c2550;
    --ring: rgba(208, 246, 1, .5);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, .4);
  }
}

/* ---- Base ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  margin: 0;
  color: var(--fg);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.6rem; font-weight: 600; letter-spacing: -.01em; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; font-weight: 600; margin: 2rem 0 .75rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

hr { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ---- Navbar ---------------------------------------------------------- */
nav {
  background: var(--primary);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: .25rem;
  flex-wrap: wrap;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  padding: .85rem 1rem .85rem 0;
  margin-right: .5rem;
}
.brand svg { width: 22px; height: 22px; flex: none; }
.brand-logo { height: 26px; width: auto; flex: none; }
nav a {
  color: rgba(255, 255, 255, .72);
  font-size: .9rem;
  padding: .85rem .8rem;
  border-bottom: 2px solid transparent;
  transition: color .15s ease, border-color .15s ease;
}
nav a:hover { color: #fff; text-decoration: none; }
nav a.active { color: #fff; border-bottom-color: var(--brand); }
nav .spacer { margin-left: auto; }
nav form { margin: 0; }

/* ---- Layout ---------------------------------------------------------- */
main {
  max-width: 920px;
  margin: 2rem auto;
  padding: 0 1.25rem;
}

/* ---- Cards / panels -------------------------------------------------- */
.card, .draft {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

/* group standalone forms into a consistent panel look */
main > form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
/* inline action forms shouldn't become panels */
main > form[style*="inline"], .draft form { all: revert; }
.draft form { margin: 0; }

/* ---- Forms ----------------------------------------------------------- */
label {
  display: block;
  margin-bottom: 1rem;
  font-size: .85rem;
  font-weight: 500;
  color: var(--fg);
}
input[type=text], input[type=email], input[type=password], input[type=url],
input[type=number], input[type=file], select, textarea {
  width: 100%;
  padding: .55rem .7rem;
  margin-top: .35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-family: inherit;
  color: var(--fg);
  background: var(--surface);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}
textarea { resize: vertical; min-height: 7rem; line-height: 1.5; }
input[type=checkbox] { width: auto; margin-right: .4rem; vertical-align: middle; }
::placeholder { color: var(--muted-fg); opacity: .8; }

p { color: var(--fg); }
main > form p, .draft p { color: var(--muted-fg); font-size: .9rem; }

/* ---- Buttons --------------------------------------------------------- */
button {
  font-family: inherit;
  font-size: .9rem;
  font-weight: 500;
  color: var(--btn-fg);
  background: var(--accent);
  border: 1px solid transparent;
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-right: .5rem;
  min-height: 40px;
  transition: background .15s ease, transform .05s ease, box-shadow .15s ease;
}
button:hover { background: var(--accent-hover); }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }

/* contextual variants — keyed off form action so templates stay clean */
form[action$="/approve"] button,
form[action$="/approve-all"] button { background: var(--success); }
form[action$="/approve"] button:hover,
form[action$="/approve-all"] button:hover { background: var(--success-hover); }

form[action$="/send"] button { background: var(--success); box-shadow: var(--shadow-md); }
form[action$="/send"] button:hover { background: var(--success-hover); }

form[action$="/reject"] button,
form[action$="/delete"] button,
form[action$="/remove"] button,
form[action="/logout"] button {
  background: transparent;
  color: var(--danger);
  border-color: var(--border);
}
form[action$="/reject"] button:hover,
form[action$="/delete"] button:hover,
form[action$="/remove"] button:hover,
form[action="/logout"] button:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

form[action$="/regenerate"] button {
  background: transparent;
  color: var(--fg);
  border-color: var(--border);
}
form[action$="/regenerate"] button:hover { background: var(--surface-2); }

/* ---- Tables ---------------------------------------------------------- */
table {
  border-collapse: collapse;
  width: 100%;
  font-size: .9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
th, td {
  padding: .6rem .8rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted-fg);
}
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td .nowrap, .mono { font-family: var(--mono); }
table button { padding: .35rem .8rem; min-height: 32px; font-size: .82rem; margin: 0; }
table form { display: inline; }

/* ---- Draft cards ----------------------------------------------------- */
.draft { border-left: 4px solid var(--border); }
.draft-approved { border-left-color: var(--success); }
.draft-rejected { border-left-color: var(--danger); opacity: .72; }
.draft-sent { border-left-color: var(--accent); opacity: .82; }
.draft-meta { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .9rem; }
.draft-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .35rem; }

/* ---- Audit trail (history detail) ------------------------------------ */
details { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: .5rem; background: var(--surface-2); }
details summary {
  cursor: pointer;
  padding: .5rem .75rem;
  font-size: .85rem;
  font-weight: 500;
  user-select: none;
}
details[open] summary { border-bottom: 1px solid var(--border); }
details pre {
  margin: 0;
  padding: .75rem;
  font-family: var(--mono);
  font-size: .8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 22rem;
  overflow: auto;
  color: var(--fg);
}

/* ---- Status badges --------------------------------------------------- */
.badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: .22rem .55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted-fg);
}
.badge-pending  { background: #fef3c7; color: #92400e; }
.badge-approved { background: #d1fae5; color: #065f46; }
.badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-sent     { background: #dbeafe; color: #1e40af; }
@media (prefers-color-scheme: dark) {
  .badge-pending  { background: #422006; color: #fcd34d; }
  .badge-approved { background: #052e22; color: #6ee7b7; }
  .badge-rejected { background: #450a0a; color: #fca5a5; }
  .badge-sent     { background: #172554; color: #93c5fd; }
}

/* ---- Feedback -------------------------------------------------------- */
.error {
  color: var(--danger);
  font-weight: 500;
  background: rgba(220, 38, 38, .08);
  border: 1px solid rgba(220, 38, 38, .25);
  border-radius: var(--radius-sm);
  padding: .65rem .85rem;
}
.notice {
  background: rgba(37, 99, 235, .08);
  border: 1px solid rgba(37, 99, 235, .25);
  border-radius: var(--radius-sm);
  padding: .65rem .85rem;
  font-size: .9rem;
}
.flash-ok  { background: rgba(5, 150, 105, .1);  border-color: rgba(5, 150, 105, .35);  color: var(--success-hover); }
.flash-err { background: rgba(220, 38, 38, .08); border-color: rgba(220, 38, 38, .3);   color: var(--danger-hover); }

/* Inline form result + spinner (SMTP save) */
.form-actions { display: flex; align-items: center; gap: .75rem; }
.form-actions button { margin: 0; }
.msg-ok  { color: var(--success-hover); font-size: .9rem; }
.msg-err { color: var(--danger-hover);  font-size: .9rem; }
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Auth / standalone card (login, unsubscribe) -------------------- */
.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.auth-card h1 { margin-bottom: 1.5rem; }
.auth-card form { text-align: left; }
.auth-card button { width: 100%; margin: 0; }
.auth-logo {
  width: 44px; height: 44px;
  margin: 0 auto 1rem;
  color: var(--accent);
}

/* ---- Responsive ------------------------------------------------------ */
@media (max-width: 640px) {
  main { margin: 1.25rem auto; }
  nav { padding: 0 .75rem; }
  nav a { padding: .7rem .55rem; }
  table { font-size: .82rem; }
  th, td { padding: .5rem .55rem; }
}

/* ---- LLM provider cards ---------------------------------------------- */
.provider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}
.provider-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.provider-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .6rem;
}
.provider-name {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
}
.provider-icon {
  height: 22px;
  width: auto;
  max-width: 96px;
  object-fit: contain;
  flex: none;
}
.provider-card .routing {
  margin: 0 0 .9rem;
  padding-left: 1.25rem;
  font-size: .82rem;
  color: var(--muted-fg);
}
.provider-card .routing li { margin: .1rem 0; }
.provider-card form { margin: 0; }
.provider-actions {
  display: flex;
  align-items: center;
  gap: .9rem;
  margin-top: .4rem;
}
.provider-actions form { margin: 0; }
.provider-actions .push-right { margin-left: auto; }

/* ---- Dashboard ------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.stat:hover { border-color: var(--brand); text-decoration: none; }
.stat-value { font-size: 1.9rem; font-weight: 700; color: var(--fg); line-height: 1; }
.stat-label { font-size: .82rem; color: var(--muted-fg); }

.dash-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: 1.75rem; }
.button {
  display: inline-block;
  padding: .6rem 1.15rem;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--btn-fg);
  font-weight: 600;
  font-size: .9rem;
}
.button:hover { background: var(--accent-hover); color: var(--btn-fg); text-decoration: none; }
.button-brand { background: var(--brand); color: var(--on-brand); }
.button-brand:hover { background: var(--brand-hover); color: var(--on-brand); }
.button-secondary { background: var(--surface-2); color: var(--fg); border: 1px solid var(--border); }
.button-secondary:hover { background: var(--surface); color: var(--fg); }

/* ---- Motion preferences ---------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
