/* ============================================================
   Teams News Broadcaster — Editorial console theme
   Display: Fraunces (serif masthead) · Body: Public Sans
   ============================================================ */

:root {
  --app-sidebar-width: 16.5rem;

  /* Ink / navy identity */
  --ink-900: #0f2233;
  --ink-800: #14293f;
  --ink-700: #1b3a5c;

  /* Brand accent (corporate blue, enriched) */
  --brand: #1f6fb2;
  --brand-600: #1b5f99;
  --brand-700: #164e7f;
  --brand-050: #eaf3fb;

  /* Editorial warm accents */
  --gold: #c98a1a;
  --read: #2f8f5b;
  --urgent: #c2410c;

  /* Neutrals — warm paper */
  --paper: #f6f4ef;
  --paper-2: #efece5;
  --surface: #ffffff;
  --line: #e7e2d8;
  --line-strong: #ddd7ca;
  --text: #1c2530;
  --text-muted: #6b7280;

  --radius: 0.95rem;
  --radius-sm: 0.6rem;
  --shadow-sm: 0 1px 2px rgba(15, 34, 51, 0.05), 0 1px 3px rgba(15, 34, 51, 0.06);
  --shadow: 0 4px 14px -6px rgba(15, 34, 51, 0.14), 0 2px 6px -2px rgba(15, 34, 51, 0.08);
  --shadow-lg: 0 18px 40px -18px rgba(15, 34, 51, 0.30);

  /* Decorative tokens — override these (not hard-coded values) in customer themes */
  --canvas-bg:
    radial-gradient(1200px 600px at 100% -10%, rgba(31, 111, 178, 0.06), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(201, 138, 26, 0.05), transparent 55%);
  --sidebar-bg:
    radial-gradient(120% 60% at 50% -10%, rgba(31, 111, 178, 0.35), transparent 60%),
    linear-gradient(190deg, var(--ink-800) 0%, var(--ink-900) 100%);
  --rail-grad: linear-gradient(180deg, #7ab8ea, var(--gold));
  --avatar-grad: linear-gradient(135deg, #cfe4f6, #f2d79a);
  --accent-grad: linear-gradient(90deg, var(--brand), var(--gold));
  --ring: rgba(31, 111, 178, 0.22);
  --row-hover: rgba(31, 111, 178, 0.06);

  --bs-body-font-family: "Public Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

html { font-size: 15.5px; }

body {
  background-color: var(--paper);
  background-image: var(--canvas-bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--bs-body-font-family);
  -webkit-font-smoothing: antialiased;
  letter-spacing: 0.005em;
}

/* Editorial serif for every heading */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6,
.display-1, .display-2, .display-3, .display-4, .display-5, .display-6 {
  font-family: "Fraunces", ui-serif, Georgia, "Times New Roman", serif;
  font-optical-sizing: auto;
  letter-spacing: -0.01em;
  color: var(--ink-900);
}

/* Tabular figures for all metric numbers */
.stat-card .display-6,
.surface-card .fs-2 {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  letter-spacing: -0.02em;
}

a { text-decoration: none; }

/* ---------- Focus & controls ---------- */
.btn:focus-visible,
.btn:active:focus,
.form-control:focus,
.form-select:focus,
.form-check-input:focus,
.list-group-item-action:focus-visible {
  box-shadow: 0 0 0 0.2rem var(--ring);
  border-color: var(--brand);
}

.btn { border-radius: var(--radius-sm); font-weight: 600; letter-spacing: 0.01em; transition: transform .12s ease, box-shadow .15s ease, background-color .15s ease; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-600);
  --bs-btn-hover-border-color: var(--brand-600);
  --bs-btn-active-bg: var(--brand-700);
  --bs-btn-active-border-color: var(--brand-700);
  box-shadow: 0 6px 14px -8px color-mix(in srgb, var(--brand) 75%, transparent);
}

.btn-outline-secondary {
  --bs-btn-color: var(--text);
  --bs-btn-border-color: var(--line-strong);
  --bs-btn-hover-bg: var(--paper-2);
  --bs-btn-hover-border-color: var(--line-strong);
  --bs-btn-hover-color: var(--ink-900);
}

.form-control, .form-select {
  border-color: var(--line-strong);
  border-radius: var(--radius-sm);
  background-color: #fffefb;
}
.form-control::placeholder { color: #a4a29a; }

.text-accent { color: var(--brand) !important; }

/* ---------- Shell ---------- */
.app-shell { min-height: 100vh; }

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--app-sidebar-width);
  background: var(--sidebar-bg);
  overflow-y: auto;
  z-index: 1030;
  border-right: 1px solid rgba(0, 0, 0, 0.25);
}

/* Masthead */
.app-brand {
  padding: 1.4rem 1.4rem 1.15rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}
.app-brand .brand-mark {
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 1.5rem;
  line-height: 1;
  color: #fff;
  letter-spacing: -0.02em;
}
.app-brand .brand-kicker {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.66rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.52);
}

.app-nav { padding: 1rem 0.85rem; }
.nav-section {
  font-size: 0.64rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.38);
  padding: 0.9rem 0.85rem 0.4rem;
  font-weight: 600;
}

.app-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  position: relative;
  color: rgba(255, 255, 255, 0.72);
  border-radius: var(--radius-sm);
  padding: 0.62rem 0.8rem;
  font-weight: 500;
  transition: background-color .15s ease, color .15s ease;
}
.app-nav .nav-link svg { width: 18px; height: 18px; opacity: 0.85; flex: 0 0 auto; }
.app-nav .nav-link:hover {
  background-color: rgba(255, 255, 255, 0.07);
  color: #fff;
}
.app-nav .nav-link.active {
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--brand) 32%, transparent),
    color-mix(in srgb, var(--brand) 12%, transparent));
  color: #fff;
}
.app-nav .nav-link.active::before {
  content: "";
  position: absolute;
  left: -0.15rem; top: 0.35rem; bottom: 0.35rem;
  width: 3px;
  border-radius: 3px;
  background: var(--rail-grad);
}
.app-nav .nav-link.active svg { opacity: 1; }

/* User chip */
.app-user {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
  padding: 1rem 1.1rem 1.2rem;
}
.user-avatar {
  width: 2.1rem; height: 2.1rem;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 0.8rem;
  color: var(--ink-900);
  background: var(--avatar-grad);
  flex: 0 0 auto;
}

.app-main { margin-left: var(--app-sidebar-width); min-height: 100vh; }

/* ---------- Page header (masthead rule) ---------- */
.page-header {
  background-color: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(140%) blur(6px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1010;
}
.page-header h1 { font-size: 1.5rem; }
.page-header .dateline {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: capitalize;
  letter-spacing: 0.02em;
}

/* ---------- Cards ---------- */
.surface-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.surface-card .card-header { border-bottom: 1px solid var(--line); background: transparent !important; }

.stat-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.4), rgba(255,255,255,0)) ,
    var(--surface);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: transform .16s ease, box-shadow .16s ease;
}
.stat-card::after {
  content: "";
  position: absolute; left: 0; top: 0; height: 3px; width: 100%;
  background: var(--accent-grad);
  opacity: 0.9;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card .text-uppercase {
  letter-spacing: 0.13em !important;
  font-size: 0.68rem;
  font-weight: 600;
}

/* Inner metric tiles (Detail) */
.surface-card .bg-light {
  background: var(--paper) !important;
  border-color: var(--line) !important;
}

/* ---------- Tables ---------- */
.table > :not(caption) > * > * { padding: 0.75rem 1rem; }
.table thead th {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 700;
  border-bottom: 1px solid var(--line-strong);
}
.table-light { --bs-table-bg: var(--paper); }
.table-hover > tbody > tr:hover > * { background-color: var(--row-hover); }

/* ---------- Badges ---------- */
.badge { font-weight: 600; letter-spacing: 0.01em; border-radius: 999px; padding: 0.4em 0.7em; }

/* ---------- Group search / chips ---------- */
.group-search-results { max-height: 18rem; overflow-y: auto; border-color: var(--line-strong) !important; }
.group-search-results .list-group-item { border-left: 0; border-right: 0; }
.group-search-results .list-group-item.active { background: var(--brand); border-color: var(--brand); }

.selected-group-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--brand-050);
  color: var(--brand-700);
  border: 1px solid rgba(31, 111, 178, 0.2);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font-weight: 600;
  font-size: 0.9rem;
}
.selected-group-remove {
  appearance: none; border: 0; background: transparent; color: inherit;
  font-size: 1.15rem; line-height: 1; padding: 0; opacity: 0.65;
}
.selected-group-remove:hover { opacity: 1; }

.campaign-action-bar {
  position: sticky; bottom: 1rem; z-index: 1020;
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-lg);
}

/* ---------- Confirm (standalone) ---------- */
.confirm-shell {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(31, 111, 178, 0.10), transparent 60%),
    linear-gradient(180deg, #fbfaf7 0%, var(--paper-2) 100%);
}
.confirm-container { width: 100%; max-width: 31rem; }

/* ---------- Entrance choreography ---------- */
@keyframes riseIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: no-preference) {
  .app-main main > * { animation: riseIn .45s cubic-bezier(.22,.61,.36,1) both; }
  .app-main main > *:nth-child(1) { animation-delay: .02s; }
  .app-main main > *:nth-child(2) { animation-delay: .08s; }
  .app-main main > *:nth-child(3) { animation-delay: .14s; }
  .app-main main > *:nth-child(4) { animation-delay: .20s; }
  .stat-card { animation: riseIn .5s cubic-bezier(.22,.61,.36,1) both; }
  .row > [class*="col-"]:nth-child(1) .stat-card { animation-delay: .04s; }
  .row > [class*="col-"]:nth-child(2) .stat-card { animation-delay: .10s; }
  .row > [class*="col-"]:nth-child(3) .stat-card { animation-delay: .16s; }
  .row > [class*="col-"]:nth-child(4) .stat-card { animation-delay: .22s; }
}

/* ---------- Brand logo slot ---------- */
.app-brand { display: flex; align-items: center; gap: 0.7rem; }
.brand-logo { height: 2.1rem; width: auto; max-width: 8rem; object-fit: contain; flex: 0 0 auto; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }

/* ---------- Header actions / theme toggle ---------- */
.header-actions { display: flex; align-items: center; gap: 0.75rem; }
.theme-toggle {
  width: 2.3rem; height: 2.3rem;
  display: grid; place-items: center;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  transition: background-color .15s ease, transform .12s ease, color .15s ease;
}
.theme-toggle:hover { background: var(--paper-2); }
.theme-toggle:active { transform: scale(0.94); }
.theme-toggle svg { width: 1.15rem; height: 1.15rem; }
.theme-toggle .icon-moon { display: none; }
[data-bs-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-bs-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ---------- Enhanced group picker ---------- */
.group-picker {
  max-height: 20rem; overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.group-row {
  display: flex; align-items: center; gap: 0.65rem;
  width: 100%; text-align: left;
  border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: var(--text);
  padding: 0.6rem 0.85rem; font-weight: 500;
  transition: background-color .12s ease;
}
.group-row:last-child { border-bottom: 0; }
.group-row:hover { background: var(--row-hover); }
.group-row.selected { background: var(--brand-050); color: var(--brand-700); }
.group-row .check {
  width: 1.2rem; height: 1.2rem; flex: 0 0 auto;
  border: 1.5px solid var(--line-strong); border-radius: 0.35rem;
  display: grid; place-items: center; color: #fff;
  transition: background-color .12s ease, border-color .12s ease;
}
.group-row.selected .check { background: var(--brand); border-color: var(--brand); }
.group-row .check svg { width: 0.8rem; height: 0.8rem; opacity: 0; }
.group-row.selected .check svg { opacity: 1; }
.group-row .group-name { flex: 1 1 auto; min-width: 0; overflow: hidden; }
.group-row .group-name > * { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-row .group-mail { font-size: 0.74rem; font-weight: 400; color: var(--text-muted); }
.group-row.selected .group-mail { color: inherit; opacity: .75; }
.group-row .peek {
  flex: 0 0 auto; font-size: 0.72rem; color: var(--text-muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 0.1rem 0.5rem;
}
.group-row .peek:hover { color: var(--brand); border-color: var(--brand); }

/* ---------- Charts (dependency-free) ---------- */
.chart-card .chart-title {
  font-size: 0.68rem; letter-spacing: 0.13em; text-transform: uppercase;
  font-weight: 600; color: var(--text-muted);
}
.donut-wrap { position: relative; width: 8.5rem; height: 8.5rem; }
.donut-wrap .donut-center {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
}
.donut-wrap .donut-value { font-family: "Fraunces", serif; font-weight: 600; font-size: 1.7rem; line-height: 1; color: var(--ink-900); }
.donut-track { stroke: var(--paper-2); }
.donut-fill { stroke: url(#donutGrad); transition: stroke-dashoffset 1s cubic-bezier(.22,.61,.36,1); }

.hbar { display: grid; grid-template-columns: 6.5rem 1fr 2rem; align-items: center; gap: 0.65rem; margin-bottom: 0.55rem; }
.hbar:last-child { margin-bottom: 0; }
.hbar .hbar-label { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }
.hbar .track { height: 0.55rem; border-radius: 999px; background: var(--paper-2); overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 999px; background: var(--accent-grad); transition: width 0.9s cubic-bezier(.22,.61,.36,1); }
.hbar .hbar-count { font-size: 0.85rem; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

.readbar { height: 0.32rem; width: 4rem; border-radius: 999px; background: var(--paper-2); overflow: hidden; display: inline-block; vertical-align: middle; }
.readbar > span { display: block; height: 100%; border-radius: 999px; }

/* ---------- Dark theme ---------- */
[data-bs-theme="dark"] {
  --ink-900: #eaf1f8;
  --ink-800: #0a1119;
  --ink-700: #0e1826;
  --brand: #57a6e4;
  --brand-600: #74b6ec;
  --brand-700: #97c9f2;
  --brand-050: rgba(87, 166, 228, 0.16);
  --gold: #e0a83a;
  --read: #4cbf85;
  --urgent: #f0793f;
  --paper: #0b131c;
  --paper-2: #131f2b;
  --surface: #16212e;
  --line: #253442;
  --line-strong: #33465a;
  --text: #dbe4ee;
  --text-muted: #91a1b2;
  --canvas-bg:
    radial-gradient(1200px 600px at 100% -10%, rgba(87, 166, 228, 0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(224, 168, 58, 0.06), transparent 55%);
  --sidebar-bg:
    radial-gradient(120% 60% at 50% -10%, rgba(87, 166, 228, 0.20), transparent 60%),
    linear-gradient(190deg, #0c1620 0%, #060b11 100%);
  --ring: rgba(87, 166, 228, 0.28);
  --row-hover: rgba(87, 166, 228, 0.08);
}
[data-bs-theme="dark"] .page-header { background-color: rgba(11, 19, 28, 0.82); }
[data-bs-theme="dark"] .stat-card { background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0)), var(--surface); }
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select { background-color: #0f1a25; color: var(--text); }
[data-bs-theme="dark"] .form-control::placeholder { color: #64717f; }
[data-bs-theme="dark"] .btn-primary {
  --bs-btn-bg: #2f80c4; --bs-btn-border-color: #2f80c4;
  --bs-btn-hover-bg: #3a8ed2; --bs-btn-hover-border-color: #3a8ed2;
  --bs-btn-active-bg: #276fab; --bs-btn-active-border-color: #276fab;
  --bs-btn-color: #fff; --bs-btn-hover-color: #fff;
}
.surface-card .card-footer { background: transparent !important; border-top-color: var(--line); }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .app-sidebar { position: static; width: 100%; }
  .app-main { margin-left: 0; }
  .app-user { margin-top: 0; }
  .page-header { position: static; }
}

/* ---------- Rich text editor ---------- */
.rte {
  border: 1px solid var(--bs-border-color, var(--line));
  border-radius: .5rem;
  overflow: hidden;
  background-color: var(--bs-body-bg);
}
.rte:focus-within { border-color: var(--brand, #1f6fb2); box-shadow: 0 0 0 .2rem var(--ring); }
.rte-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem;
  padding: .4rem .5rem;
  border-bottom: 1px solid var(--line);
  background: var(--row-hover, rgba(0, 0, 0, .03));
}
.rte-btn {
  min-width: 2rem;
  padding: .2rem .45rem;
  border: 1px solid transparent;
  border-radius: .35rem;
  background: transparent;
  color: var(--text, inherit);
  font-size: .9rem;
  line-height: 1.4;
}
.rte-btn:hover { background: var(--bs-body-bg); border-color: var(--line); }
.rte-sep { width: 1px; align-self: stretch; margin: .1rem .25rem; background: var(--line); }
.rte-editor {
  min-height: 12rem;
  max-height: 32rem;
  overflow-y: auto;
  padding: .85rem 1rem;
  outline: none;
}
.rte-editor.is-empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted, #6c757d);
  pointer-events: none;
}
.rte-editor img, .message-html img { max-width: 100%; height: auto; border-radius: .35rem; }
.rte-editor > *:first-child, .message-html > *:first-child { margin-top: 0; }
.rte-editor > *:last-child, .message-html > *:last-child { margin-bottom: 0; }
.rte-editor blockquote, .message-html blockquote {
  margin: .5rem 0;
  padding-left: .9rem;
  border-left: 3px solid var(--line);
  color: var(--text-muted, #6c757d);
}
.message-html table, .rte-editor table { width: 100%; border-collapse: collapse; }
.message-html td, .message-html th, .rte-editor td, .rte-editor th {
  border: 1px solid var(--line);
  padding: .35rem .5rem;
}
