/* ==========================================================================
   CWARE Connect — design tokens
   --------------------------------------------------------------------------
   Neutral slate palette + CWARE navy as the primary brand surface. WhatsApp
   green is reserved for the conversation thread bubbles only (contextual);
   everything else (nav, buttons, active states) uses --brand / --accent.
   ========================================================================== */
:root {
  /* surfaces */
  --bg:        #f6f8fa;            /* slate-50 */
  --panel:     #ffffff;
  --border:    #e2e8f0;            /* slate-200 */
  --border-soft:#eef1f5;
  --nav-bg:    #ffffff;
  --nav-border:#e2e8f0;

  /* text */
  --text:      #0f172a;            /* slate-900 */
  --muted:     #64748b;            /* slate-500 */
  --muted-2:   #94a3b8;            /* slate-400 */
  --nav-text:  #1e293b;            /* slate-800 */

  /* brand */
  --brand:     #15205c;            /* CWARE navy */
  --brand-700: #1c2d6b;
  --brand-50:  #eef2ff;
  --accent:    #1f78c8;            /* CWARE blue (logo's blue arrow) */
  --accent-d:  #15205c;

  /* status (desaturated) */
  --status-ok:    #16a34a;
  --status-warn:  #d97706;
  --status-err:   #dc2626;
  --status-info:  #2563eb;
  --status-mute:  #6b7280;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; line-height: 1.45;
  color: var(--text); background: var(--bg);
  font-feature-settings: "cv11", "ss01";   /* nicer Inter alternates */
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Layout — sidebar spans both rows; top bar only sits over main ===== */
.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "side top" "side main";
  height: 100dvh; overflow: hidden;
}
.app > .top  { grid-area: top;  }
.app > .side { grid-area: side; }
.app > .main { grid-area: main; overflow: auto; padding: 20px 24px; }

/* ===== Top bar ===== */
.top {
  background: var(--panel); border-bottom: 1px solid var(--nav-border);
  display: flex; align-items: center; gap: 10px;
  padding: 12px 24px; color: var(--nav-text);
}
.top .spacer { flex: 1; }

/* Bell */
.top-bell {
  position: relative; background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 8px; cursor: pointer; color: #475569;
}
.top-bell:hover { background: #f8fafc; }
.top-bell-badge {
  position: absolute; top: -4px; right: -4px;
  background: #dc2626; color: #fff; font-size: 10px; font-weight: 700;
  padding: 1px 5px; border-radius: 8px; min-width: 16px; text-align: center;
}

/* User chip */
.top-user {
  display: flex; align-items: center; gap: 10px; padding: 4px 12px 4px 4px;
  border: 1px solid var(--border); border-radius: 30px; background: #fff;
}
.top-user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: #16a34a; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 11px; letter-spacing: 0.02em;
}
.top-user-name { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.1; }
.top-user-role { font-size: 11px; color: var(--muted); }
.top-user-out  { font-size: 16px; color: var(--muted); text-decoration: none; padding-left: 4px; border-left: 1px solid var(--border-soft); }
.top-user-out:hover { color: var(--text); }

/* ===== Tenant picker (top right) ===== */
.tenant-picker {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 13px; font-weight: 500; cursor: pointer; user-select: none;
  background: #fff; color: var(--text);
}
.tenant-picker:hover { background: #f9fbfd; }
.tenant-picker[aria-disabled="true"] { cursor: default; opacity: 0.85; }
.tenant-picker .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--status-ok);
}
.tenant-picker .chev { color: var(--muted-2); font-size: 11px; }
.tenant-picker .menu {
  position: absolute; right: 0; top: calc(100% + 4px);
  background: #fff; border: 1px solid var(--border); border-radius: 4px;
  min-width: 240px; padding: 4px;
  box-shadow: 0 4px 16px rgba(15,23,42,0.08); z-index: 50;
}
.tenant-picker .opt {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 3px; font-size: 13px;
  color: var(--nav-text); cursor: pointer; font-weight: 400;
}
.tenant-picker .opt:hover { background: var(--bg); }
.tenant-picker .opt.active { background: var(--brand-50); color: var(--brand); font-weight: 600; }
.tenant-picker .opt .slug { color: var(--muted); font-family: ui-monospace, monospace; font-size: 11px; }

.user-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 4px; font-size: 13px; font-weight: 500; color: var(--text);
}
.user-chip .role {
  font-size: 9px; padding: 1px 6px; border-radius: 2px;
  background: var(--brand); color: #fff; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
}

/* ===== Side rail ===== */
.side {
  background: var(--panel); border-right: 1px solid var(--nav-border);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}

/* Brand at top of sidebar */
.side .brand {
  display: flex; align-items: baseline; gap: 6px;
  padding: 4px 6px 16px; text-decoration: none; flex-shrink: 0;
}
.side .brand .brand-img  { width: 100%; height: auto; display: block; }
.side .brand .brand-logo { font-size: 22px; font-weight: 800; color: #16a34a; letter-spacing: -0.02em; }
.side .brand .brand-sub  { font-size: 11px; font-weight: 700; color: #16a34a; letter-spacing: 0.18em; }

/* Nav rows */
.side .nav { display: flex; flex-direction: column; gap: 1px; flex-shrink: 0; }
.side .nav-row {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  font-size: 13px; color: #475569; text-decoration: none; font-weight: 500;
}
.side .nav-row:hover { background: rgba(158, 203, 118, 0.2); color: #4d7a2c; text-decoration: none; }
.side .nav-row:hover .ic { color: #4d7a2c; opacity: 1; }
.side .nav-row.active { background: #15205c; color: #fff; }
.side .nav-row.active .ic { color: #fff; opacity: 1; }
.side .nav-row .ic { width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; color: #64748b; opacity: 0.85; flex-shrink: 0; }
.side .nav-row .lbl { flex: 1; }
.side .nav-row .nav-badge {
  background: #16a34a; color: #fff;
  font-size: 10px; font-weight: 700;
  padding: 1px 7px; border-radius: 10px;
  min-width: 18px; text-align: center;
}
.side .nav-row.active .nav-badge { background: #fff; color: #15205c; }

.side .section { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted-2); padding: 14px 10px 4px; font-weight: 600; flex-shrink: 0; }
.side .spacer { flex: 1; }

/* WABA card */
.side .waba-card { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-top: 14px; flex-shrink: 0; }
.side .waba-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px; }
.side .waba-icon { width: 32px; height: 32px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.side .waba-title { font-size: 12px; font-weight: 600; line-height: 1.2; color: var(--text); }
.side .waba-status { font-size: 11px; color: #16a34a; display: flex; align-items: center; gap: 5px; margin-top: 2px; }
.side .waba-status .dot { width: 6px; height: 6px; border-radius: 50%; background: #16a34a; }
.side .waba-status .dot.off { background: #94a3b8; }
.side .waba-quality { display: inline-flex; align-items: center; gap: 5px; font-weight: 500; }
.side .waba-quality .q-dot { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; }
.side .waba-quality.q-high   { color: #16a34a; } .side .waba-quality.q-high   .q-dot { background: #16a34a; }
.side .waba-quality.q-med    { color: #d97706; } .side .waba-quality.q-med    .q-dot { background: #d97706; }
.side .waba-quality.q-low    { color: #dc2626; } .side .waba-quality.q-low    .q-dot { background: #dc2626; }
.side .waba-quality.q-unknown{ color: #94a3b8; } .side .waba-quality.q-unknown .q-dot { background: #94a3b8; }
/* One row per linked WhatsApp number in the sidebar card. */
.side .waba-num { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 0; border-top: 1px solid var(--border); }
.side .waba-num:first-of-type { border-top: 0; }
.side .waba-num-phone { font-size: 12px; color: var(--text); }
.side .waba-row { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); padding: 3px 0; }
.side .waba-row .v { color: var(--text); font-weight: 500; }
.side .waba-row .v.mono { font-family: ui-monospace, monospace; font-size: 11px; }

/* ===== Dashboard rows — all share the same 6-col grid so cards align ===== */
.kpi-grid,
.row-2,
.row-3 {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
/* Use :nth-of-type(div) to skip the <style> elements that Card.razor /
   Kpi.razor render inline (Blazor leaves them as siblings, which would
   otherwise throw off :nth-child counting). */
.row-2 > div:nth-of-type(1) { grid-column: span 4; min-width: 0; }
.row-2 > div:nth-of-type(2) { grid-column: span 2; min-width: 0; }
.row-3 > div                { grid-column: span 2; min-width: 0; }
.kpi-grid > div             { min-width: 0; }

/* Help card */
.side .help-card {
  position: relative; background: #15205c; color: #fff;
  border-radius: 10px; padding: 12px; margin-top: 10px;
  display: flex; flex-direction: column; gap: 6px; text-decoration: none;
  flex-shrink: 0;
}
.side .help-card:hover { background: #1c2d6b; text-decoration: none; }
.side .help-icon { color: #fff; opacity: 0.9; }
.side .help-title { font-size: 13px; font-weight: 600; color: #fff; }
.side .help-sub   { font-size: 11px; color: #cbd5e1; }
.side .help-btn   { display: inline-block; background: #1f78c8; color: #fff; text-align: center; padding: 7px; border-radius: 6px; font-size: 12px; font-weight: 600; margin-top: 4px; }

/* ===== Page chrome ===== */
h1 { margin: 0 0 16px; font-size: 18px; font-weight: 600; letter-spacing: -0.005em; color: var(--text); }
/* Blazor's <FocusOnNavigate> programmatically focuses the page h1 after every
   route change for screen-reader announcements. Hide the visual ring — h1 isn't
   keyboard-interactive so this doesn't affect accessibility. */
h1:focus, h1:focus-visible { outline: none; }
h1 .sub { font-weight: 400; font-size: 13px; color: var(--muted); margin-left: 8px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 0; overflow: hidden; }
.card .head {
  padding: 10px 14px; border-bottom: 1px solid var(--border-soft);
  display: flex; gap: 10px; align-items: center; background: #fafbfc;
}
.card .head h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.empty { color: var(--muted); padding: 28px 20px; text-align: center; font-size: 13px; }

/* ===== Tables (denser) ===== */
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th {
  text-align: left; color: var(--muted); font-weight: 600;
  padding: 7px 12px; border-bottom: 1px solid var(--border);
  background: var(--bg); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
}
table.t td { padding: 7px 12px; border-bottom: 1px solid var(--border-soft); }
table.t tr:last-child td { border-bottom: 0; }
table.t tr:hover td { background: #f9fbfd; }
.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; font-size: 12px; }

/* In-row text-button actions (Edit / Reset password / Delete / etc.). The hover
   was previously inheriting whatever color was nearest, which made some buttons
   appear white. Keep the row-button's own color, just underline on hover. */
button.link { background: none; }
button.link:hover { text-decoration: underline; }   /* preserve own color — no opacity fade */
button.link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

/* ===== Status tags — desaturated, dot + label ===== */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 7px; border-radius: 3px; font-size: 11px; font-weight: 500;
  border: 1px solid transparent;
}
.tag::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85;
}
.tag.active   { background: #ecfdf5; color: #047857; border-color: #d1fae5; }
.tag.draft    { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.tag.archived { background: #f3f4f6; color: #6b7280; border-color: #e5e7eb; }

/* ===== Generic buttons (any page can opt in) ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 4px; font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid transparent; transition: background 0.1s; }
.btn-brand     { background: var(--brand); color: #fff; }
.btn-brand:hover    { background: var(--brand-700); }
.btn-neutral   { background: #fff; color: var(--text); border-color: var(--border); }
.btn-neutral:hover  { background: var(--bg); }
.btn-danger    { background: #fff; color: var(--status-err); border-color: #fecaca; }
.btn-danger:hover   { background: #fef2f2; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Blazor error UI ===== */
#blazor-error-ui {
  background: #fef2f2; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.1);
  display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000; color: var(--status-err);
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
