/* Sentinel — shared stylesheet
   Adapted from the Mailapp design system: teal accent palette, Fraunces +
   Public Sans type, sidebar app-shell, rounded buttons/badges, dark mode. */

:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --border: #dfe4e1;
  --text: #12181a;
  --text-muted: #5c6b66;
  --accent: #0f6b57;
  --accent-dark: #0b4a3e;
  --accent-tint: #dcece5;
  --danger: #b5342b;
  --danger-bg: #fbecea;
  --danger-border: #f3c6c1;
  --success: #0f6b57;
  --success-bg: #eaf4ef;
  --warn: #9a6400;
  --warn-bg: #fdf3df;
  --radius: 8px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10201c;
    --surface: #16302a;
    --border: #274740;
    --text: #eef4f1;
    --text-muted: #93a8a1;
    --accent: #4fbf9c;
    --accent-dark: #6fd4b1;
    --accent-tint: #1e3d35;
    --danger-bg: #3a1f1c;
    --danger-border: #5a2e29;
    --success-bg: #1a3a2e;
    --warn-bg: #3a2f14;
  }
}
:root[data-theme="dark"] {
  --bg: #10201c;
  --surface: #16302a;
  --border: #274740;
  --text: #eef4f1;
  --text-muted: #93a8a1;
  --accent: #4fbf9c;
  --accent-dark: #6fd4b1;
  --accent-tint: #1e3d35;
  --danger-bg: #3a1f1c;
  --danger-border: #5a2e29;
  --success-bg: #1a3a2e;
  --warn-bg: #3a2f14;
}
:root[data-theme="light"] {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --border: #dfe4e1;
  --text: #12181a;
  --text-muted: #5c6b66;
  --accent: #0f6b57;
  --accent-dark: #0b4a3e;
  --accent-tint: #dcece5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

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

/* App shell / sidebar */
.app-shell {
  display: flex;
  align-items: flex-start;
  min-height: 100vh;
}
.sidebar {
  width: 230px;
  flex-shrink: 0;
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 26px 18px;
}
.sidebar .brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  color: var(--text);
  margin-bottom: 4px;
  padding: 0 10px;
  display: flex;
  align-items: flex-start;
  gap: 7px;
}
.sidebar .brand .brand-stack {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}
.sidebar .brand .brand-strat {
  padding-left: 2.9ch;  /* aligns "Strategist" under the "c" in "Watchdog" */
}
.sidebar .brand-sub {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 24px;
  padding: 0 10px;
}
.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.sidebar nav a {
  color: var(--text-muted);
  font-weight: 500;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}
.sidebar nav a:hover {
  background: var(--bg);
  color: var(--accent);
  text-decoration: none;
}
.sidebar nav a.active {
  background: var(--accent-tint);
  color: var(--accent);
}
.sidebar .logout-link {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
@media (max-width: 720px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    min-height: 0;
    display: flex;
    align-items: center;
    gap: 16px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar .brand {
    margin-bottom: 0;
  }
  .sidebar {
    flex-wrap: wrap;
    padding: 12px 16px;
    row-gap: 8px;
  }
  .sidebar nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .sidebar .brand-sub { display: none; }        /* save space on phones */
  .sidebar .logout-link { margin-top: 0; padding-top: 0; border-top: none; }
  .page { max-width: 100%; margin: 18px auto; padding: 0 16px 40px; }
  .page-header h1 { font-size: 24px; }
  .mail-reading { padding: 16px 16px; }
}

.page {
  flex: 1;
  max-width: 880px;
  margin: 40px auto;
  padding: 0 24px 60px;
}

.auto-check {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 500;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  gap: 12px;
  flex-wrap: wrap;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 26px 24px;
  margin-bottom: 22px;
  box-shadow: 0 2px 6px rgba(18, 24, 26, 0.07), 0 1px 2px rgba(18, 24, 26, 0.05);
}

h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 24px;
  margin: 0 0 6px;
}
h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  margin: 0 0 14px;
}
h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  margin: 18px 0 8px;
}
p.hint {
  color: var(--text-muted);
  font-size: 13.5px;
  margin: 0 0 14px;
}

/* Forms */
label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--text-muted);
}
input[type="text"],
input[type="url"],
input[type="email"],
input[type="password"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 14px;
  background: var(--surface);
  color: var(--text);
}
textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  min-height: 100px;
  resize: vertical;
}
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 107, 87, 0.15);
}

button,
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
button:hover,
.btn:hover {
  background: var(--accent-dark);
}
.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--bg);
}
.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger-border);
}
.btn-danger:hover {
  background: var(--danger-bg);
}
.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}
.btn-mint {
  background: var(--accent-tint);
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn-mint:hover {
  background: var(--accent);
  color: #fff;
}
form.inline {
  display: inline;
}
.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* Alerts */
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  margin-bottom: 16px;
}
.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}
.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #bbf7d0;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
}
td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tr:last-child td {
  border-bottom: none;
}
tr:hover td {
  background: var(--bg);
}
tr.disabled td {
  opacity: 0.55;
}
.pages-list {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.7;
}

/* Badges & pills */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-on {
  background: var(--success-bg);
  color: var(--success);
}
.badge-off {
  background: #f1f2f6;
  color: var(--text-muted);
}
.badge-threat {
  background: var(--danger-bg);
  color: var(--danger);
}
.badge-opportunity {
  background: var(--success-bg);
  color: var(--success);
}
.badge-neutral {
  background: #f1f2f6;
  color: var(--text-muted);
}
.badge-approved {
  background: var(--accent-tint);
  color: var(--accent);
}

/* Briefing cards — left severity stripe */
.briefing-card {
  border-left: 5px solid var(--border);
}
.sev-high {
  border-left-color: var(--danger);
}
.sev-medium {
  border-left-color: #d98c00;
}
.sev-low,
.sev-neutral {
  border-left-color: var(--text-muted);
}
.briefing-card h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 17px;
}
.briefing-summary {
  font-size: 15px;
  font-weight: 600;
  margin: 4px 0 6px;
}
.briefing-reasoning {
  color: var(--text-muted);
  font-size: 13.5px;
  margin: 0 0 4px;
}
/* Two-column briefing: context left, AI output (impact + drafts) right. */
.page-briefings { max-width: 1280px; }
/* Outlook-style master/detail: list left, reading pane right. */
.mail-layout {
  display: grid;
  grid-template-columns: clamp(380px, 44%, 561px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.mail-list { display: flex; flex-direction: column; gap: 8px; }
.mail-row {
  text-align: left; width: 100%; display: block; cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-left: 4px solid var(--border);
  border-radius: 10px; padding: 11px 13px; font-family: inherit;
}
.mail-row:hover { background: var(--bg); }
.mail-row.active { border-left-color: var(--accent); background: var(--accent-tint); }
.mail-row-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.mail-row-title { font-weight: 700; font-size: 14px; }
.mail-row-time { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.mail-row-snip {
  font-size: 12.5px; color: var(--text-muted); margin: 4px 0 8px; line-height: 1.45;
}
.mail-row-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.mail-reading {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 22px 26px; min-height: 420px;
}
.mail-detail { display: none; }
.mail-detail.active { display: block; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.impact-chart { max-width: 460px; }
@media (max-width: 900px) {
  .mail-layout { grid-template-columns: 1fr; }
  /* Phones: the detail is moved (by JS) right under the tapped row, so the
     right pane is empty — hide it and give the detail its own card look. */
  .mail-reading { display: none; }
  .mail-detail.active {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin: 6px 0 10px;
  }
}
.bc-left, .bc-right { min-width: 0; }
.bc-right {
  border-left: 1px solid var(--border);
  padding-left: 22px;
}
@media (max-width: 900px) {
  .briefing-grid { grid-template-columns: 1fr; gap: 14px; }
  .bc-right { border-left: none; padding-left: 0; border-top: 1px solid var(--border); padding-top: 14px; }
}
/* AI market-impact estimate block */
.impact-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 0 0 16px;
}
.impact-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.impact-title { font-weight: 700; font-size: 14px; }
.impact-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.impact-score {
  font-size: 30px; font-weight: 800; line-height: 1;
  display: flex; flex-direction: column; align-items: flex-end;
}
.impact-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; margin-top: 3px; }
.impact-low { color: var(--text-muted); }
.impact-med { color: var(--warn); }
.impact-high { color: var(--accent); }
.impact-chart { width: 100%; height: auto; margin: 12px 0 6px; display: block; }
.impact-area { fill: var(--accent-tint); opacity: 0.75; stroke: none; }
.impact-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.impact-dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.impact-rationale { font-size: 13px; color: var(--text); margin: 4px 0 0; }
.draft-block {
  white-space: pre-wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  margin: 0 0 8px;
}
.edit-block {
  margin: 10px 0 4px;
}
.edit-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.mail-result {
  font-size: 13.5px;
  margin-top: 8px;
  color: var(--text-muted);
}

/* History page — compact grouped rows */
.history-date {
  margin: 24px 0 10px;
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.history-date:first-child {
  margin-top: 0;
}
.history-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.history-row {
  padding: 14px 18px;
  margin-bottom: 0;
  border-left: 5px solid var(--border);
}
.history-row-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.history-title {
  font-weight: 600;
  font-size: 14.5px;
  margin-right: 4px;
}
.history-summary {
  color: var(--text-muted);
  font-size: 13.5px;
  margin: 6px 0 0;
}

/* Admin — wide page + two-column layout */
.page-wide {
  max-width: 1180px;
}
.admin-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 22px;
  align-items: start;
}
@media (max-width: 900px) {
  .admin-grid {
    grid-template-columns: 1fr;
  }
}
.form-panel {
  position: sticky;
  top: 24px;
}
.form-panel .form-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.page-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}
.page-row input {
  margin-bottom: 0;
}
.page-row input[name="page_type"] {
  flex: 0 0 92px;
}
.page-row input[name="page_url"] {
  flex: 1;
  min-width: 0;
}
.page-row .row-del {
  flex: 0 0 auto;
  width: 38px;
  padding: 0;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.page-row .row-del:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-bg);
}

/* Competitor list (right column) */
.comp-list {
  display: flex;
  flex-direction: column;
}
.comp-row {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.comp-row:first-child {
  padding-top: 0;
}
.comp-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.comp-row.disabled {
  opacity: 0.55;
}
.comp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.comp-name {
  font-weight: 600;
  font-size: 14.5px;
}
.comp-name .cid {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 12.5px;
}
.comp-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.page-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}
.page-chip {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
  cursor: default;
}

/* Centered login card */
.center-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 24px 60px -20px rgba(6, 30, 45, 0.2);
}
.login-card .logo {
  text-align: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  margin-bottom: 22px;
  color: var(--text);
}

.social-actions { margin: 6px 0 4px; }
.social-card-preview {
  display: block;
  width: 340px;
  max-width: 100%;
  height: auto;
  margin: 12px 0 4px;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}
.share-hint {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--accent);
  min-height: 1em;
}
.briefing-time {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 2px 0 10px;
}

/* ---------- Run-cycle status ---------- */
.run-status {
  font-size: 13px;
  font-weight: 500;
}
.run-status.running { color: var(--accent); }
.run-status.ok { color: var(--success); }
.run-status.muted { color: var(--text-muted); }
.run-status.err { color: var(--danger); }

/* ---------- History filter bar ---------- */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.filter-bar input[type="text"] {
  flex: 1;
  min-width: 200px;
  margin-bottom: 0;
}
.filter-bar select,
.filter-bar input[type="month"] {
  width: auto;
  margin-bottom: 0;
}
.filter-bar .btn-secondary { padding: 9px 16px; }

/* ---------- Overview page ---------- */
.pill-static {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  white-space: nowrap;
}
.period-select {
  width: auto;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  margin-bottom: 0;
  background: var(--surface);
  cursor: pointer;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}
.stat-card {
  margin-bottom: 0;
  padding: 18px 18px 12px;
}
.stat-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}
.stat-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 8px 0 4px;
}
.stat-num {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.stat-trend {
  font-size: 12.5px;
  font-weight: 600;
}
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }
.spark {
  display: block;
  width: 100%;
  height: 40px;
  margin-top: 4px;
}
.overview-row {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 22px;
}
.overview-row .card { margin-bottom: 22px; }
.ov-title {
  font-size: 16px;
  margin: 0 0 16px;
}
.alert-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.alert-row:first-of-type { border-top: none; }
.alert-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
  background: var(--text-muted);
}
.sev-dot-high { background: var(--danger); }
.sev-dot-medium { background: #d98324; }
.sev-dot-low { background: var(--success); }
.alert-body { flex: 1; min-width: 0; }
.alert-title { font-weight: 600; font-size: 14px; color: var(--text); }
.alert-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.alert-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}
.alert-ago { font-size: 12px; color: var(--text-muted); }
.donut-wrap {
  display: flex;
  align-items: center;
  gap: 22px;
}
.donut {
  width: 140px;
  height: 140px;
  flex-shrink: 0;
}
.donut-num {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  fill: var(--text);
}
.donut-cap {
  font-size: 10px;
  fill: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.donut-legend { flex: 1; }
.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  font-size: 13.5px;
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend-label { flex: 1; color: var(--text); }
.legend-count { font-weight: 600; color: var(--text); }
.timeline {
  display: block;
  width: 100%;
  height: 110px;
}
@media (max-width: 720px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .overview-row { grid-template-columns: 1fr; }
}
