/* ==========================================================================
   CLASSPULSE — Owner Command Center  (local stylesheet, no CDN dependency)
   LIGHT theme. Brand palette matches the logo: blue + green.
   ========================================================================== */

:root {
  --bg:        #D9E8FA;   /* light sky-blue page */
  --bg-2:      #FFFFFF;
  --panel:     #F3F8FF;   /* lightest blue (was white) */
  --panel-2:   #E7F1FE;   /* light blue tint surface */
  --border:    #CBDCF3;   /* blue-tinted lines */
  --border-2:  #B6CCEC;
  --brand:     #2563EB;   /* logo blue */
  --brand-2:   #1D4ED8;   /* darker blue for links/accents */
  --brand-d:   #0B2A6B;   /* NAVY blue — headers / active */
  --brand-l:   #DCEAFF;   /* lightest blue tint — banners / hover / selected */
  --emerald:   #16A34A;   /* logo green */
  --amber:     #D97706;
  --red:       #DC2626;
  --sky:       #0EA5E9;
  --text:      #0F2350;   /* navy text */
  --muted:     #4E5F80;
  --muted-2:   #8090AC;
  --radius:    14px;
  --shadow:    0 6px 20px rgba(11,42,107,.12);   /* navy-tinted shadow */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(37,99,235,.07), transparent 60%),
    radial-gradient(900px 500px at -10% 0%, rgba(22,163,74,.06), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ---------------- Top bar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 16px;                                   /* compact */
  background: linear-gradient(135deg, #06122C, #0B2457);   /* darkest navy */
  box-shadow: 0 1px 10px rgba(3, 8, 26, .40);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand img { height: 40px; width: auto; max-width: 150px; object-fit: contain;
  background: #fff; padding: 3px 7px; border-radius: 9px; }
.brand-meta { display: flex; flex-direction: column; gap: 3px; line-height: 1.1; min-width: 0; }
.brand-meta .firm { font-size: 15px; font-weight: 800; color: #fff; letter-spacing: -.2px;
  max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .brand-meta .branch-sel { align-self: flex-start; background: rgba(255,255,255,.1); color: #fff;
  border: 1px solid rgba(255,255,255,.2); border-radius: 7px; padding: 2px 8px; font-size: 11px;
  font-weight: 600; max-width: 220px; box-shadow: none; }
/* translucent "glass" controls on navy (no white) */
.topbar .btn {
  background: rgba(255,255,255,.10); color: #fff; border: 1px solid rgba(255,255,255,.20);
  box-shadow: none; padding: 7px 12px; font-size: 12.5px; font-weight: 600;
}
.topbar .btn:hover { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.4); }
.topbar .btn.primary { background: var(--brand); border-color: transparent; }   /* one clear accent CTA */
.topbar .btn.primary:hover { filter: brightness(1.1); }
.topbar .icon-btn { padding: 7px 10px; }

.topbar .spacer { flex: 1; }

.control { display: flex; flex-direction: column; gap: 4px; }
.control label { font-size: 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted-2); font-weight: 700; }
select, .btn {
  font-family: inherit;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: .15s;
}
select:hover, .btn:hover { border-color: var(--brand); }
select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,.18); }

.btn.primary { background: linear-gradient(135deg, var(--brand), #1D4ED8); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn i { margin-right: 6px; }
.btn.sm { padding: 6px 10px; font-size: 12px; }

/* ---------------- Tabs ---------------- */
.tabs {
  display: flex; gap: 6px; overflow-x: auto;
  padding: 10px 22px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.tab {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  font-size: 13px; font-weight: 600;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  cursor: pointer; white-space: nowrap;
  transition: .15s;
}
.tab:hover { color: var(--brand); background: var(--brand-l); }
.tab.active {
  color: #fff;
  background: var(--brand);
  border-color: transparent;
  margin-bottom: -1px;
}

/* ---------------- Layout ---------------- */
main { padding: 22px; max-width: 1360px; margin: 0 auto; }
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1050px) { .cols-4 { grid-template-columns: repeat(2,1fr); } .cols-3 { grid-template-columns: 1fr; } .cols-2 { grid-template-columns: 1fr; } }
@media (max-width: 560px)  { .cols-4 { grid-template-columns: 1fr; } }

.section-title { font-size: 15px; font-weight: 700; margin: 26px 0 12px; display: flex; align-items: center; gap: 8px; }
.section-title i { color: var(--brand); }
.section-title:first-child { margin-top: 0; }

/* ---------------- Cards / Panels ---------------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.panel h3 { font-size: 13px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; color: var(--text); }
.panel h3 i { color: var(--brand); }

.kpi {
  background: linear-gradient(180deg, #F7FBFF, #E9F2FE);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative; overflow: hidden;
  box-shadow: var(--shadow);
}
.kpi::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--brand); }
.kpi.emerald::before { background: var(--emerald); }
.kpi.amber::before { background: var(--amber); }
.kpi.red::before { background: var(--red); }
.kpi.sky::before { background: var(--sky); }
.kpi .k-label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; display:flex; align-items:center; gap:7px; }
.kpi .k-label i { color: var(--muted-2); }
.kpi .k-value { font-size: 26px; font-weight: 800; letter-spacing: -.5px; margin: 8px 0 4px; color: var(--text); }
.kpi .k-sub { font-size: 12px; color: var(--muted); }
.up { color: var(--emerald); font-weight: 700; }
.down { color: var(--red); font-weight: 700; }

/* ---------------- Health ring ---------------- */
.health-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.ring {
  --val: 86; --col: var(--emerald);
  width: 132px; height: 132px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--col) calc(var(--val) * 1%), #E5E9F0 0);
  display: grid; place-items: center;
  position: relative;
}
.ring::after { content: ""; position: absolute; inset: 12px; border-radius: 50%; background: var(--panel); }
.ring .ring-inner { position: relative; z-index: 1; text-align: center; }
.ring .ring-inner b { font-size: 32px; font-weight: 800; display: block; line-height: 1; color: var(--text); }
.ring .ring-inner small { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.health-bars { flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: 10px; }
.hbar .hbar-top { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.hbar .hbar-top .cat { font-weight: 600; }
.hbar .hbar-top .sc { color: var(--muted); font-weight: 700; }
.track { height: 7px; background: #E5E9F0; border-radius: 6px; overflow: hidden; }
.track > div { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--brand), var(--emerald)); }
.hbar .status { font-size: 10px; color: var(--muted-2); margin-top: 3px; }

/* ---------------- Tables ---------------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .7px;
  color: var(--muted-2); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px; border-bottom: 1px solid rgba(15,30,56,.06); color: var(--text); }
tbody tr:hover { background: rgba(37,99,235,.04); }
tbody tr:last-child td { border-bottom: none; }
.t-strong { font-weight: 700; }
.t-muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.right { text-align: right; }

/* ---------------- Badges ---------------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.red    { background: rgba(220,38,38,.12);  color: #b91c1c; }
.badge.amber  { background: rgba(217,119,6,.14);  color: #b45309; }
.badge.green  { background: rgba(22,163,74,.14);  color: #15803d; }
.badge.blue   { background: rgba(37,99,235,.12);  color: #1d4ed8; }
.badge.gray   { background: rgba(100,116,139,.14);color: #475569; }

/* ---------------- AI insight cards ---------------- */
.insight {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 12px;
  padding: 16px;
  background: var(--panel);
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.insight.Critical    { border-left-color: var(--red); }
.insight.High        { border-left-color: var(--amber); }
.insight.Opportunity { border-left-color: var(--emerald); }
.insight .i-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.insight .i-cat { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }
.insight .i-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.insight .i-msg { font-size: 13px; color: var(--muted); line-height: 1.55; margin-bottom: 12px; }

/* ---------------- WhatsApp mockup (kept dark like a real phone) ---------------- */
.wa-wrap { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.phone {
  width: 340px; flex: none;
  background: #0b141a; border: 8px solid #05080a; border-radius: 34px;
  box-shadow: 0 12px 40px rgba(15,30,56,.18); overflow: hidden;
}
.phone .wa-head { background: #1f2c33; padding: 14px 16px; display: flex; align-items: center; gap: 10px; }
.phone .wa-head .av { width: 36px; height: 36px; border-radius: 50%; background: #fff; overflow: hidden; display: grid; place-items: center; }
.phone .wa-head .av img { width: 100%; height: 100%; object-fit: contain; padding: 2px; }
.phone .wa-head .nm { font-size: 14px; font-weight: 700; color: #e9edef; }
.phone .wa-head .st { font-size: 11px; color: #8aa0ab; }
.phone .wa-body {
  background: #0b141a url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='4' cy='4' r='1' fill='%23132029'/%3E%3C/svg%3E");
  padding: 16px; min-height: 420px; max-height: 520px; overflow-y: auto;
}
.bubble {
  background: #005c4b; color: #e9edef; border-radius: 10px 10px 10px 2px;
  padding: 10px 12px; font-size: 12.5px; line-height: 1.55; white-space: pre-wrap;
  box-shadow: 0 1px 1px rgba(0,0,0,.3);
}
.bubble .tick { text-align: right; font-size: 10px; color: #8fd0c0; margin-top: 4px; }
.wa-controls { flex: 1; min-width: 260px; }
.toggle-row { display: inline-flex; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 10px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.toggle-row button { background: transparent; border: none; color: var(--muted); font-family: inherit; font-weight: 700; font-size: 13px; padding: 7px 16px; border-radius: 8px; cursor: pointer; }
.toggle-row button.active { background: var(--brand); color: #fff; }

/* ---------------- Connectors ---------------- */
.conn-card { display: flex; flex-direction: column; gap: 10px; }
.conn-card .c-ico { width: 44px; height: 44px; border-radius: 12px; background: rgba(37,99,235,.12); color: var(--brand); display: grid; place-items: center; font-size: 20px; }
.conn-card p { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.result-box {
  margin-top: 10px; background: #F1F5F9; border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; font-size: 12px; color: #15803d;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; white-space: pre-wrap; display: none;
}
.result-box.show { display: block; }

/* ---------------- Loading & toast ---------------- */
.loader { display: grid; place-items: center; min-height: 60vh; }
.spinner { width: 46px; height: 46px; border: 4px solid rgba(37,99,235,.2); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120%);
  background: #FFFFFF; border: 1px solid var(--brand); color: var(--text);
  padding: 12px 20px; border-radius: 12px; font-size: 13px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(15,30,56,.16); z-index: 90; transition: transform .3s ease; display:flex; align-items:center; gap:9px;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast i { color: var(--emerald); }

.user-chip { display: flex; align-items: center; gap: 10px; background: var(--panel-2);
  border: 1px solid var(--border-2); border-radius: 10px; padding: 5px 8px 5px 12px; }
.user-chip .u-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-chip #u-name { font-size: 13px; font-weight: 700; }
.user-chip .u-role { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* ---------------- Modal / forms ---------------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,30,56,.45); backdrop-filter: blur(4px);
  z-index: 80; display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal-overlay.show { display: flex; }
.modal { width: 100%; max-width: 560px; background: var(--panel);
  border: 1px solid var(--border-2); border-radius: 16px; box-shadow: 0 20px 60px rgba(15,30,56,.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--border); }
.modal-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.mtab { background: transparent; border: 1px solid transparent; color: var(--muted); font-family: inherit;
  font-weight: 700; font-size: 12.5px; padding: 7px 12px; border-radius: 9px; cursor: pointer; }
.mtab:hover { color: var(--text); background: rgba(37,99,235,.06); }
.mtab.active { background: var(--brand); color: #fff; }
.mtab i { margin-right: 5px; }
.modal-body { padding: 18px; }
.form-row { display: flex; gap: 12px; }
.form-row > .field { flex: 1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.line-items { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-top: 6px; }
.line-items table { width: 100%; }
.line-items th { padding: 8px 10px; }
.line-items td { padding: 6px 8px; border-bottom: 1px solid rgba(15,30,56,.06); }
.line-items input, .line-items select { width: 100%; background: var(--panel-2); border: 1px solid var(--border-2);
  color: var(--text); border-radius: 7px; padding: 6px 8px; font-family: inherit; font-size: 12.5px; }
.li-remove { color: var(--red); cursor: pointer; background: none; border: none; font-size: 14px; }
.line-total { text-align: right; font-weight: 800; font-size: 16px; margin-top: 10px; }
.modal-body .field { margin-bottom: 12px; }
.modal-body .field > label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted-2); font-weight: 700; margin-bottom: 5px; }
.modal-body .field > input, .modal-body .field > select { width: 100%; background: var(--panel-2);
  border: 1px solid var(--border-2); color: var(--text); border-radius: 9px; padding: 9px 11px;
  font-family: inherit; font-size: 13px; outline: none; }
.modal-body .field > input:focus, .modal-body .field > select:focus { border-color: var(--brand); }

/* ---------------- Reports ---------------- */
.rep-controls { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.rep-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.rep-custom { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.rep-custom input[type=date] { background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text);
  border-radius: 8px; padding: 6px 8px; font-family: inherit; font-size: 12px; }
.rep-subnav { display: flex; gap: 4px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 12px; }
.rsub { background: transparent; border: 1px solid var(--border-2); color: var(--muted); font-family: inherit;
  font-weight: 700; font-size: 12.5px; padding: 7px 14px; border-radius: 9px; cursor: pointer; }
.rsub:hover { color: var(--text); }
.rsub.active { background: var(--brand); color: #fff; border-color: transparent; }
.rep-crumb { margin: 4px 0 14px; font-size: 13px; color: var(--muted); }
.rep-crumb a { color: var(--brand-2); cursor: pointer; }
.rep-crumb a:hover { text-decoration: underline; }
.rep-crumb .sep { color: var(--muted-2); margin: 0 4px; }
.clickrow { cursor: pointer; }
.clickrow:hover { background: rgba(37, 99, 235, .06) !important; }
.rep-hint { font-size: 11px; color: var(--muted-2); margin: 2px 0 10px; }

.chart-box { position: relative; height: 300px; }
.muted-note { font-size: 11px; color: var(--muted-2); margin-top: 8px; }
.demo-flag { font-size: 10px; color: var(--emerald); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }

/* ==========================================================================
   MOBILE / HANDY  (responsive + touch) — desktop layout unchanged
   ========================================================================== */
/* Touch feedback on all tappables (every screen size) */
.btn:active, .tab:active, .rsub:active, .mtab:active, .kpi:active,
.toggle-row button:active, .rep-presets .btn:active { transform: scale(0.97); }
.clickrow:active { background: rgba(37, 99, 235, .12) !important; }
select, .btn, .tab, .rsub, .mtab { touch-action: manipulation; }

@media (max-width: 820px) {
  main { padding: 14px; }
  .topbar { padding: 6px 12px; gap: 8px; }
  .brand img { height: 34px; }
  .brand-meta .firm { max-width: 150px; font-size: 14px; }
  .tabs { padding: 8px 12px 0; -webkit-overflow-scrolling: touch; }
  .tab { padding: 9px 13px; font-size: 12.5px; }
  .panel { padding: 14px; }
  .section-title { font-size: 14px; margin: 20px 0 10px; }
  .kpi .k-value { font-size: 22px; }
  /* wide data tables scroll sideways instead of breaking the layout */
  table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .modal { max-width: 100%; }
  .modal-overlay { padding: 14px 8px; }
  .modal-tabs { gap: 3px; }
  .mtab { padding: 7px 9px; font-size: 12px; }
  .rep-controls { gap: 8px; }
  .health-wrap { justify-content: center; }
  .wa-wrap .phone { width: 100%; max-width: 340px; margin: 0 auto; }
  .user-chip #u-name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (max-width: 480px) {
  main { padding: 11px; }
  .btn { padding: 9px 11px; }               /* bigger tap targets */
  .btn.sm { padding: 8px 10px; }
  .kpi .k-value { font-size: 20px; }
  .form-row { flex-direction: column; gap: 0; }   /* stack form fields */
  .rep-presets { width: 100%; }
  .rep-presets .btn { flex: 1 1 30%; }
}
