/* ==========================================================================
   Cybersasa CRM — Stylesheet
   Brand: Dark Charcoal Navy #13222D · Bright Orange #F17902 · White #FFFFFF
   No gradients. Solid colours only. Mobile-first.
   ========================================================================== */

:root {
  --navy: #13222D;
  --navy-2: #1c2f3c;       /* lighter navy for surfaces on dark */
  --navy-3: #243a4a;
  --orange: #F17902;
  --orange-2: #d96d06;     /* hover/pressed */
  --orange-soft: #fff3e6;  /* tinted background */
  --white: #FFFFFF;
  --bg: #f6f7f9;           /* page background, off-white */
  --ink: #13222D;          /* primary text */
  --ink-2: #4a5b68;        /* secondary text */
  --ink-3: #8a99a6;        /* muted text */
  --line: #e4e8ec;         /* borders */
  --line-2: #d2d9df;
  --ok: #1f8a4c;
  --ok-soft: #e7f5ee;
  --warn: #b7791f;
  --warn-soft: #fdf3e0;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(19, 34, 45, 0.06);
  --shadow: 0 4px 16px rgba(19, 34, 45, 0.08);
  --shadow-lg: 0 12px 40px rgba(19, 34, 45, 0.12);
  --sidebar-w: 248px;
  --topbar-h: 64px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--orange-2); text-decoration: none; }
a:hover { color: var(--orange); }

h1, h2, h3, h4 { color: var(--navy); margin: 0 0 .4em; font-weight: 700; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 1em; }

/* ---------- Brand logo lockup ---------- */
.logo { display: inline-flex; align-items: center; gap: 0; font-weight: 800; letter-spacing: -0.02em; }
.logo .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--navy); color: var(--white);
  display: inline-flex; align-items: center; justify-content: center;
  margin-right: 9px; font-size: 16px; font-weight: 800;
}
.logo .cy { color: var(--navy); }
.logo .crm { color: var(--orange); }

/* Logo image (used in sidebar, login, etc.) */
.logo-img {
  display: block;
  height: 34px;
  width: auto;
  max-width: 100%;
}
/* On the dark sidebar, sit the logo on a white plate so the brand
   colours read cleanly against the navy background. */
.logo-plate {
  display: inline-flex;
  align-items: center;
  background: var(--white);
  border-radius: 10px;
  padding: 7px 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
.logo-plate .logo-img { height: 26px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-family: inherit; font-size: 14px; font-weight: 600;
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  white-space: nowrap; text-decoration: none; line-height: 1;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--orange); color: var(--white); }
.btn-primary:hover { background: var(--orange-2); color: var(--white); }
.btn-dark { background: var(--navy); color: var(--white); }
.btn-dark:hover { background: var(--navy-3); color: var(--white); }
.btn-ghost { background: transparent; color: var(--navy); border-color: var(--line-2); }
.btn-ghost:hover { background: var(--white); border-color: var(--ink-3); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--line-2); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field label .opt { font-weight: 400; color: var(--ink-3); }
input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--ink);
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); background: var(--white); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-soft);
}
textarea { resize: vertical; min-height: 72px; }
input[type="date"], input[type="time"] { color: var(--ink); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; }

/* ---------- Layout shell ---------- */
.shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--navy); color: var(--white);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
}
.sidebar .brand { padding: 20px 22px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .brand .logo .cy { color: var(--white); }
.sidebar .brand .logo .mark { background: var(--orange); }
.nav { padding: 14px 12px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  border-radius: var(--radius-sm); color: rgba(255,255,255,.72);
  font-weight: 600; font-size: 14.5px; margin-bottom: 3px; transition: background .15s, color .15s;
}
.nav a svg { width: 19px; height: 19px; flex-shrink: 0; }
.nav a:hover { background: rgba(255,255,255,.07); color: var(--white); }
.nav a.active { background: var(--orange); color: var(--white); }
.nav a .badge {
  margin-left: auto; background: rgba(255,255,255,.18); color: var(--white);
  font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 20px;
}
.nav a.active .badge { background: rgba(255,255,255,.25); }
.sidebar-foot { padding: 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.sidebar-foot .who { color: var(--white); font-weight: 600; }
.sidebar-foot .logout { color: rgba(255,255,255,.6); display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; }
.sidebar-foot .logout:hover { color: var(--orange); }

/* Main */
.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

/* Topbar */
.topbar {
  height: var(--topbar-h); background: var(--white); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 0 22px; position: sticky; top: 0; z-index: 30;
}
.topbar .menu-btn { display: none; background: none; border: none; cursor: pointer; padding: 6px; color: var(--navy); }
.search {
  flex: 1; max-width: 460px; position: relative;
}
.search input { padding-left: 38px; background: var(--bg); border-color: var(--line); }
.search .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.topbar .spacer { flex: 1; }
.topbar .new-btn { flex-shrink: 0; }

.content { padding: 24px 22px 60px; max-width: 1180px; width: 100%; }
.content.wide { max-width: 100%; }

/* ---------- Cards ---------- */
.card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); margin-bottom: 18px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.card-head h2 { margin: 0; }
.card-head .sub { font-size: 13px; color: var(--ink-3); font-weight: 500; }
.card-body { padding: 18px; }
.card-body.tight { padding: 14px 18px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--line); }

/* ---------- Stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.stat .label { font-size: 12.5px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat .val { font-size: 1.7rem; font-weight: 800; color: var(--navy); margin-top: 4px; line-height: 1; }
.stat .val.accent { color: var(--orange); }
.stat .val.danger { color: var(--danger); }
.stat .foot { font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.stat.accent-bar { border-left: 4px solid var(--orange); }
.stat.warn-bar { border-left: 4px solid var(--warn); }
.stat.danger-bar { border-left: 4px solid var(--danger); }
.stat.ok-bar { border-left: 4px solid var(--ok); }

/* ---------- Grid helpers ---------- */
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 2fr 1fr; }
.grid-main-side { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; align-items: start; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700;
  padding: 3px 9px; border-radius: 20px; border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.lead { color: #6b5b95; background: #f1edf7; border-color: #e0d6ef; }
.badge.in_progress { color: var(--orange-2); background: var(--orange-soft); border-color: #f8d9b8; }
.badge.completed { color: #2a6f97; background: #e7f1f7; border-color: #cfe4ee; }
.badge.paid { color: var(--ok); background: var(--ok-soft); border-color: #c9e7d4; }
.badge.overdue { color: var(--danger); background: var(--danger-soft); border-color: #f3c9c4; }
.badge.soon { color: var(--warn); background: var(--warn-soft); border-color: #f0e0bd; }
.badge.muted { color: var(--ink-3); background: var(--bg); border-color: var(--line); }
.badge.dot-only::before { display: none; }

/* ---------- List rows ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-row {
  display: flex; align-items: center; gap: 14px; padding: 13px 18px;
  border-bottom: 1px solid var(--line); transition: background .12s;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--bg); }
.list-row .main-info { flex: 1; min-width: 0; }
.list-row .name { font-weight: 600; color: var(--navy); }
.list-row .meta { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.list-row .name a { color: var(--navy); }
.list-row .name a:hover { color: var(--orange); }
.list-row .right { text-align: right; flex-shrink: 0; }
.list-row .amount { font-weight: 700; color: var(--navy); }
.list-row .amount.neg { color: var(--danger); }
.row-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-3); font-weight: 700; padding: 11px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg); }
tr[data-href] { cursor: pointer; }
td .name-cell a { color: var(--navy); font-weight: 600; }
td .name-cell a:hover { color: var(--orange); }
td .sub { font-size: 12px; color: var(--ink-3); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--ink-3); }
.empty svg { width: 40px; height: 40px; color: var(--line-2); margin-bottom: 10px; }
.empty p { margin: 0; }
.empty .ttl { font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }

/* ---------- Timeline (activity log) ---------- */
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--line); }
.timeline .item { position: relative; padding: 0 0 16px 6px; }
.timeline .item::before {
  content: ""; position: absolute; left: -22px; top: 5px; width: 11px; height: 11px;
  border-radius: 50%; background: var(--white); border: 2px solid var(--orange);
}
.timeline .item .date { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.timeline .item .text { color: var(--ink); }

/* AI annotations on activity items */
.ai-note { margin-top: 6px; background: var(--orange-soft); border: 1px solid #f8d9b8; border-radius: var(--radius-sm); padding: 8px 12px; }
.ai-note .ai-sum { font-size: 13px; color: var(--navy); font-weight: 500; }
.ai-note .ai-points { margin: 6px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--ink-2); }
.ai-note .ai-points li { margin-bottom: 2px; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--ink-3); font-size: 14px; margin-top: 3px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Filter bar ---------- */
.filterbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 13px; font-weight: 600; padding: 7px 13px; border-radius: 20px;
  border: 1px solid var(--line-2); background: var(--white); color: var(--ink-2);
  cursor: pointer; transition: all .12s; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { border-color: var(--ink-3); color: var(--navy); }
.chip.active { background: var(--navy); color: var(--white); border-color: var(--navy); }
.chip.active.orange { background: var(--orange); border-color: var(--orange); }
select.sort-select { width: auto; padding: 7px 12px; font-size: 13px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(19,34,45,.5); z-index: 60;
  display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white); border-radius: var(--radius-lg); width: 100%; max-width: 540px;
  box-shadow: var(--shadow-lg); margin-top: 20px; animation: pop .15s ease-out;
}
@keyframes pop { from { transform: translateY(8px); opacity: .96; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--ink-3); padding: 4px; }
.modal-close:hover { color: var(--navy); }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--navy); }
.login-card { background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 400px; padding: 36px 32px; }
.login-card .logo { font-size: 1.5rem; justify-content: center; display: flex; margin-bottom: 6px; }
.login-card .tagline { text-align: center; color: var(--ink-3); font-size: 14px; margin-bottom: 26px; }
.login-card .logo .mark { width: 38px; height: 38px; font-size: 20px; margin-right: 11px; }
.alert-error { background: var(--danger-soft); border: 1px solid #f3c9c4; color: var(--danger); padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 16px; font-weight: 500; }
.login-foot { text-align: center; margin-top: 22px; font-size: 12px; color: var(--ink-3); }

/* ---------- Misc ---------- */
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 700; margin: 0 0 10px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.mt0 { margin-top: 0; }
.mb0 { margin-bottom: 0; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.gap { gap: 10px; }
.wrap { flex-wrap: wrap; }
.center { text-align: center; }
.kpi-row { display: flex; gap: 18px; flex-wrap: wrap; }
.kpi { font-size: 13px; color: var(--ink-3); }
.kpi b { color: var(--navy); font-size: 15px; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.tag { font-size: 11.5px; font-weight: 600; color: var(--orange-2); background: var(--orange-soft); padding: 2px 8px; border-radius: 6px; border: 1px solid #f8d9b8; }
.tag.ok { color: var(--ok); background: var(--ok-soft); border-color: #c9e7d4; }
.tag.bad { color: var(--danger); background: var(--danger-soft); border-color: #f3c9c4; }
.icon-btn { background: none; border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 7px 9px; cursor: pointer; color: var(--ink-2); display: inline-flex; align-items: center; }
.icon-btn:hover { color: var(--navy); border-color: var(--ink-3); background: var(--bg); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.checkbox { width: auto; }

/* Mobile bottom nav hidden on desktop */
.mobile-nav { display: none; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1024px) {
  .grid-main-side { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  :root { --topbar-h: 58px; }
  .sidebar {
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 18px 14px 90px; }
  .search { max-width: none; }

  /* Bottom navigation for thumb reach */
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 35;
    background: var(--white); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(19,34,45,.06);
    justify-content: space-around; padding: 6px 4px max(6px, env(safe-area-inset-bottom));
  }
  .mobile-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 10.5px; font-weight: 600; color: var(--ink-3); padding: 6px 8px; border-radius: 8px; flex: 1;
  }
  .mobile-nav a svg { width: 20px; height: 20px; }
  .mobile-nav a.active { color: var(--orange); }
  .mobile-nav a .plus { background: var(--orange); color: var(--white); width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-top: -18px; box-shadow: var(--shadow); }
  .mobile-nav a .plus svg { width: 22px; height: 22px; }

  .page-head { align-items: flex-start; }
  .table-wrap th, .table-wrap td { padding: 11px 12px; }
  .list-row { flex-wrap: wrap; }
  .list-row .right { width: 100%; text-align: left; }
}

@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .val { font-size: 1.4rem; }
  .form-row { grid-template-columns: 1fr; }
  h1 { font-size: 1.3rem; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar .new-btn span.label { display: none; }
  .topbar .new-btn { padding: 10px 12px; }
  .modal { margin-top: 0; }
}

/* Backdrop for sidebar on mobile */
.backdrop { display: none; position: fixed; inset: 0; background: rgba(19,34,45,.45); z-index: 39; }
.backdrop.open { display: block; }

/* Focus visibility for accessibility */
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
