/* ============================================================
   Dseal CRM — application stylesheet (self-hosted, no CDN)
   ============================================================ */
:root {
  --brand-red: #d3202a;
  --brand-blue: #1f4e9c;
  --brand-blue-2: #2b6fd6;
  --sidebar-bg: #12203b;
  --ink: #1c2430;
  --ink-soft: #55627a;
  --line: #e4e8f0;
  --bg: #f4f6fb;
  --card: #ffffff;
  --ok: #17914e;
  --ok-bg: #e6f6ec;
  --warn: #b9770c;
  --warn-bg: #fdf3e0;
  --danger: #c0272d;
  --danger-bg: #fbeaea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
  --shadow-lg: 0 8px 24px rgba(16,24,40,.10);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 14px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-blue-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; color: var(--ink); }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
small { color: var(--ink-soft); }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* ---- Layout shell ---- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px; background: var(--sidebar-bg); color: #cfd8ea;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  padding: 18px 20px; font-weight: 800; font-size: 20px; letter-spacing: .3px;
  border-bottom: 1px solid rgba(255,255,255,.08); color: #fff;
}
.sidebar .brand .d { color: #ff5b62; }
.sidebar .brand .seal { color: #8fb6ff; }
.sidebar nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; margin: 2px 0;
  border-radius: 8px; color: #cfd8ea; font-weight: 500;
}
.sidebar nav a .ico { width: 18px; text-align: center; opacity: .9; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--brand-blue); color: #fff; }
.sidebar nav .group-label {
  padding: 14px 12px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: #6f7f9e;
}
.sidebar .badge-count {
  margin-left: auto; background: var(--brand-red); color: #fff; border-radius: 999px;
  font-size: 11px; padding: 1px 7px; font-weight: 700;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 12px 24px;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.topbar .spacer { flex: 1; }
.topbar .user { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); }
.topbar .avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--brand-blue);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.content { padding: 22px 24px 60px; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font-weight: 600;
  cursor: pointer; font-size: 13.5px; line-height: 1; transition: .12s;
}
.btn:hover { border-color: #c7cfdd; text-decoration: none; box-shadow: var(--shadow); }
.btn-primary { background: var(--brand-blue); border-color: var(--brand-blue); color: #fff; }
.btn-primary:hover { background: #1a4489; color: #fff; }
.btn-danger { background: #fff; border-color: #edc9cb; color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---- Cards ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card .card-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card .card-head h2, .card .card-head h3 { margin: 0; }
.card .card-body { padding: 18px; }
.card .card-body.tight { padding: 0; }

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

/* ---- KPI tiles ---- */
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .label { color: var(--ink-soft); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 28px; font-weight: 800; margin-top: 4px; color: var(--ink); }
.kpi .sub { color: var(--ink-soft); font-size: 12.5px; margin-top: 2px; }
.kpi.accent-red { border-top: 3px solid var(--brand-red); }
.kpi.accent-blue { border-top: 3px solid var(--brand-blue); }
.kpi.accent-green { border-top: 3px solid var(--ok); }
.kpi.accent-amber { border-top: 3px solid var(--warn); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); background: #fafbfe; font-weight: 700; white-space: nowrap; }
table.data tbody tr:hover { background: #f8faff; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .muted { color: var(--ink-soft); }
.empty { padding: 40px 20px; text-align: center; color: var(--ink-soft); }
.empty .big { font-size: 34px; opacity: .4; margin-bottom: 6px; }

/* ---- Badges / pills ---- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: #eef1f7; color: var(--ink-soft); white-space: nowrap; }
.badge.b-lead { background: #eaf1ff; color: #2657b8; }
.badge.b-prospect { background: #fff2e0; color: #a9660a; }
.badge.b-customer { background: var(--ok-bg); color: var(--ok); }
.badge.b-inactive, .badge.b-declined, .badge.b-expired { background: #eef1f5; color: #6a7488; }
.badge.b-active { background: var(--ok-bg); color: var(--ok); }
.badge.b-draft { background: #eef1f7; color: #55627a; }
.badge.b-sent { background: #eaf1ff; color: #2657b8; }
.badge.b-accepted { background: var(--ok-bg); color: var(--ok); }
.badge.b-high { background: var(--danger-bg); color: var(--danger); }
.badge.b-normal { background: #eef1f7; color: #55627a; }
.badge.b-low { background: #eef4f0; color: #4a6a58; }
.badge.b-overdue { background: var(--danger-bg); color: var(--danger); }
/* invoice statuses (status_badge() slugs "Partly Paid" -> b-partlypaid) */
.badge.b-paid { background: var(--ok-bg); color: var(--ok); }
.badge.b-partlypaid { background: #fff2e0; color: #a9660a; }
.badge.b-cancelled { background: #eef1f5; color: #6a7488; }
.tag-pill { display: inline-block; padding: 2px 9px; margin: 2px 3px 2px 0; border-radius: 6px; font-size: 12px; background: #eef1fb; color: #3a4a6b; border: 1px solid #e0e6f5; }

/* ---- Forms ---- */
.form-row { margin-bottom: 15px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 700px) { .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; } }
label.field-label { display: block; font-weight: 600; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], input[type=url], input[type=tel],
select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; color: var(--ink); background: #fff; transition: .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-blue-2); box-shadow: 0 0 0 3px rgba(43,111,214,.14); }
textarea { resize: vertical; min-height: 74px; }
.help { color: var(--ink-soft); font-size: 12px; margin-top: 4px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.inline-form { display: inline; }

/* ---- Alerts / flash ---- */
.alert { padding: 11px 15px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; border: 1px solid transparent; }
.alert-success { background: var(--ok-bg); color: var(--ok); border-color: #bfe6cd; }
.alert-error, .alert-danger { background: var(--danger-bg); color: var(--danger); border-color: #eecacc; }
.alert-info { background: #eaf1ff; color: #2657b8; border-color: #cddffb; }
.field-error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }
input.has-error, select.has-error, textarea.has-error { border-color: var(--danger); }

/* ---- Filters bar ---- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.filters .f { display: flex; flex-direction: column; }
.filters .f label { font-size: 11.5px; color: var(--ink-soft); font-weight: 600; margin-bottom: 3px; }
.filters input, .filters select { padding: 7px 10px; min-width: 130px; }

/* ---- Pagination ---- */
.pager { display: flex; gap: 6px; align-items: center; margin-top: 16px; justify-content: flex-end; color: var(--ink-soft); }
.pager a, .pager span { padding: 6px 11px; border: 1px solid var(--line); border-radius: 7px; background: #fff; font-weight: 600; }
.pager .cur { background: var(--brand-blue); color: #fff; border-color: var(--brand-blue); }

/* ---- Detail layout ---- */
.detail-grid { display: grid; grid-template-columns: 340px 1fr; gap: 18px; }
@media (max-width: 950px) { .detail-grid { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--ink-soft); font-weight: 600; }
.kv dd { margin: 0; word-break: break-word; }

/* ---- Activity timeline ---- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 26px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline .dot { position: absolute; left: -8px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--brand-blue); border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.timeline .dot.t-note { background: #7b8aa8; }
.timeline .dot.t-call { background: var(--ok); }
.timeline .dot.t-email { background: var(--brand-blue-2); }
.timeline .dot.t-whatsapp { background: #25a565; }
.timeline .dot.t-status { background: var(--warn); }
.timeline .dot.t-system { background: #b3bccd; }
.timeline .ttl { font-weight: 600; }
.timeline .meta { color: var(--ink-soft); font-size: 12px; margin-top: 1px; }
.timeline .body { margin-top: 3px; white-space: pre-wrap; }

/* ---- Misc ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; font-weight: 600; color: var(--ink-soft); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--brand-blue); border-bottom-color: var(--brand-blue); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.stack > * + * { margin-top: 14px; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
.copybox { display: flex; gap: 8px; align-items: center; background: #0f1b30; color: #cfe0ff; padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.copybox code { white-space: nowrap; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--sidebar-bg), var(--brand-blue)); padding: 20px; }
.login-card .brand-logo { display:block; max-height: 54px; margin: 0 auto 10px; }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); padding: 30px 28px; }
.login-card .brand { font-size: 26px; font-weight: 800; text-align: center; margin-bottom: 4px; }
.login-card .brand .d { color: var(--brand-red); }
.login-card .brand .seal { color: var(--brand-blue); }
.login-card .sub { text-align: center; color: var(--ink-soft); margin-bottom: 22px; font-size: 13px; }

/* ---- Lock screens (screen lock + site lock) ---- */
.lock-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--sidebar-bg), var(--brand-blue)); padding: 20px; }
.lock-card { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg); padding: 30px 28px; text-align: center; }
.lock-card .padlock { font-size: 42px; line-height: 1; margin-bottom: 8px; }
.lock-card .who { display:flex; flex-direction: column; align-items:center; gap:8px; margin-bottom: 16px; }
.lock-card .avatar-lg { width: 60px; height: 60px; border-radius: 50%; background: var(--brand-blue); color:#fff; display:grid; place-items:center; font-weight:800; font-size:22px; }
.lock-card h2 { margin: 0; }
.lock-card .brand-logo { max-height: 48px; margin: 0 auto 12px; display:block; }
.topbar .lock-btn { border:1px solid var(--line); background:#fff; }

/* ---- Public landing ---- */
.pub { min-height: 100vh; display:flex; flex-direction: column; color: #eaf0fb; background: linear-gradient(140deg, var(--sidebar-bg) 0%, var(--brand-blue) 100%); }
.pub .pub-nav { display:flex; align-items:center; padding: 20px 32px; }
.pub .pub-nav .brand { font-weight: 800; font-size: 22px; color:#fff; }
.pub .pub-nav .brand .d { color: var(--brand-red); }
.pub .pub-nav .spacer { flex:1; }
.pub .hero { flex:1; display:grid; place-items:center; text-align:center; padding: 40px 24px; }
.pub .hero-inner { max-width: 680px; }
.pub .hero h1 { font-size: 44px; color:#fff; line-height:1.12; margin-bottom: 16px; }
.pub .hero p { font-size: 18px; color: #c8d6f0; margin-bottom: 28px; }
.pub .hero .brand-logo { max-height: 80px; margin: 0 auto 22px; display:block; }
.pub .btn-white { background:#fff; color: var(--brand-blue); border:none; padding: 13px 26px; font-size: 15px; border-radius: 10px; font-weight:700; }
.pub .btn-white:hover { background:#eef2fb; text-decoration:none; }
.pub .pub-foot { text-align:center; padding: 18px; color: #9fb2d6; font-size: 12.5px; }
.pub .feat { display:flex; gap:22px; justify-content:center; flex-wrap:wrap; margin-top: 34px; }
.pub .feat .f { background: rgba(255,255,255,.08); border:1px solid rgba(255,255,255,.14); border-radius: 12px; padding: 16px 18px; width: 190px; }
.pub .feat .f .ic { font-size: 22px; } .pub .feat .f h3 { color:#fff; margin: 8px 0 4px; font-size: 15px; } .pub .feat .f p { font-size: 13px; color:#c0d0ec; margin:0; }
.color-swatch { display:inline-block; width:22px; height:22px; border-radius:5px; border:1px solid var(--line); vertical-align:middle; }
