/* ===== Dreekk CRM — dreekk.com theme (red + navy + white) ===== */
*, *::before, *::after { box-sizing: border-box; }
:root {
  /* dreekk.com palette */
  --navy: #192038;         /* site footer / dark surfaces */
  --navy-deep: #0e2f56;    /* site "intro" / CTA panels */
  --navy-2: #232c48;       /* raised navy */

  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --surface-3: #e7eaef;
  --border: #e2e6ec;
  --border-soft: #edeff3;
  --text: #192038;         /* navy text, like the site headings */
  --text-dim: #444c60;
  --muted: #737b8c;
  --brand: #e4062b;        /* dreekk.com red */
  --brand-hi: #c00524;
  --brand-dim: rgba(228, 6, 43, 0.10);
  --ok: #12a150;
  --ok-dim: rgba(18, 161, 80, 0.12);
  --warn: #c07d10;
  --warn-dim: rgba(214, 158, 46, 0.16);
  --bad: #d61f30;
  --bad-dim: rgba(214, 31, 48, 0.12);
  --info: #2563eb;
  --info-dim: rgba(37, 99, 235, 0.12);
  --radius: 12px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px -14px rgba(25, 32, 56, 0.28);
  --shadow-sm: 0 1px 2px rgba(25, 32, 56, 0.06), 0 1px 3px rgba(25, 32, 56, 0.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
[hidden] { display: none !important; }

/* ---- brand ---- */
.brand-logo { display: block; height: 26px; width: auto; border-radius: 5px; }
.badge-mark {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--brand); color: #fff; font-weight: 800; font-size: 15px; flex: none;
}

/* ================= Auth ================= */
.auth {
  position: relative; overflow: hidden;
  min-height: 100%;
  display: grid; place-items: center; padding: 24px;
  background: var(--navy);
}
.auth__fx { position: absolute; inset: 0; z-index: 0; display: block; width: 100%; height: 100%; pointer-events: none; }
.auth__inner {
  position: relative; z-index: 1;
  width: 100%; max-width: 384px;
  display: flex; flex-direction: column; align-items: center; gap: 22px;
}
.auth__logo-top { width: 100%; height: auto; display: block; }
.auth__card {
  width: 100%;
  background: var(--surface);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 16px; padding: 26px 26px 22px;
  box-shadow: 0 26px 64px -22px rgba(10, 14, 30, 0.6), 0 6px 18px -8px rgba(10, 14, 30, 0.4);
}
.auth__form { display: grid; gap: 13px; }
.auth__error {
  margin: 0; color: var(--bad); font-size: 13px;
  background: var(--bad-dim); border: 1px solid rgba(214, 59, 48, 0.28);
  padding: 8px 10px; border-radius: 8px;
}
.auth__note { margin: 14px 0 0; color: var(--muted); font-size: 12.5px; text-align: center; }

/* ================= App shell ================= */
.app { display: flex; min-height: 100%; }
/* navy sidebar (like the dreekk.com footer), red brand strip on top (like the site header) */
.sidebar {
  width: 236px; flex: none;
  background: var(--navy);
  color: #fff;
  border-right: 1px solid var(--navy);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; z-index: 40;
}
.sidebar__brand {
  display: flex; align-items: center; gap: 11px;
  padding: 20px 20px;
  background: var(--brand);
}
.sidebar__logo { height: 24px; width: auto; }
.sidebar__tag {
  font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: rgba(255, 255, 255, 0.82); border-left: 1px solid rgba(255, 255, 255, 0.34); padding-left: 10px;
}
.nav { display: flex; flex-direction: column; padding: 12px 12px; gap: 2px; overflow-y: auto; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 10px;
  color: rgba(255, 255, 255, 0.74); font-weight: 550;
  transition: background .12s, color .12s;
}
.nav a:hover { background: rgba(255, 255, 255, 0.09); color: #fff; }
.nav a.is-active { background: var(--brand); color: #fff; font-weight: 650; }
.nav a.is-active i { color: #fff; }
.nav i { width: 18px; height: 18px; display: inline-grid; place-items: center; color: rgba(255, 255, 255, 0.6); }
.nav i svg { width: 18px; height: 18px; }
.sidebar__foot {
  padding: 14px 20px; border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 12px; color: rgba(255, 255, 255, 0.62);
  display: flex; flex-direction: column; gap: 6px;
}
.linkbtn { background: none; border: 0; color: #ff8a80; cursor: pointer; font: inherit; padding: 0; text-align: left; }
.linkbtn:hover { text-decoration: underline; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.view { padding: 22px; max-width: 1160px; width: 100%; }

/* red top bar — only on narrow screens where the sidebar collapses to a drawer */
.mobilebar { display: none; }
.mobilebar__btn {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  background: rgba(255, 255, 255, 0.16); border: 1px solid rgba(255, 255, 255, 0.34);
  color: #fff; cursor: pointer;
  display: grid; place-items: center;
}
.mobilebar__btn svg { width: 19px; height: 19px; }
.mobilebar__logo { height: 22px; width: auto; }
.scrim {
  position: fixed; inset: 0; background: rgba(20, 24, 40, 0.35);
  opacity: 0; pointer-events: none; transition: opacity .16s; z-index: 39;
}
body.nav-open .scrim { opacity: 1; pointer-events: auto; }

/* ================= Buttons ================= */
.btn {
  --btn-bg: var(--surface);
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 13px; border-radius: 9px;
  background: var(--btn-bg); color: var(--text);
  border: 1px solid var(--border);
  font: inherit; font-weight: 570; cursor: pointer;
  white-space: nowrap; box-shadow: var(--shadow-sm);
  transition: background .12s, border-color .12s, box-shadow .12s, transform .04s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 6px 16px -8px rgba(228, 6, 43, 0.55); }
.btn--primary:hover { background: var(--brand-hi); }
.btn--ghost { background: transparent; box-shadow: none; }
.btn--ghost:hover { background: var(--surface-2); }
.btn--danger { background: transparent; border-color: rgba(214, 59, 48, 0.35); color: var(--bad); box-shadow: none; }
.btn--danger:hover { background: var(--bad-dim); }
.btn--sm { padding: 5px 9px; font-size: 12.5px; border-radius: 7px; }
.btn--block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn i, .btn svg { width: 15px; height: 15px; }

/* ================= Cards / layout ================= */
.grid { display: grid; gap: 14px; }
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.card--pad0 { padding: 0; overflow: hidden; }
.card__h {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border-soft);
}
.card__h h3 { font-size: 13.5px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin: 26px 0 12px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 260px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.split { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }

/* KPI */
.kpi { display: flex; flex-direction: column; gap: 6px; position: relative; }
.kpi__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi__label { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.kpi__value { font-size: 23px; font-weight: 730; letter-spacing: -0.02em; }
.kpi__sub { font-size: 12px; color: var(--text-dim); }
.kpi__icon {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  display: grid; place-items: center;
  background: var(--brand-dim); color: var(--brand);
}
.kpi__icon svg { width: 16px; height: 16px; }
.kpi--accent { background: var(--brand-dim); border-color: rgba(228, 6, 43, 0.24); }
.kpi--ok .kpi__value { color: var(--ok); }
.kpi--ok .kpi__icon { background: var(--ok-dim); color: var(--ok); }
.kpi--bad .kpi__value { color: var(--bad); }
.kpi--bad .kpi__icon { background: var(--bad-dim); color: var(--bad); }
.ministat { display: flex; gap: 10px; align-items: center; }
.ministat__body { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.ministat b { font-size: 16px; font-weight: 720; white-space: nowrap; }
.ministat span { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ministat__ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); flex: none; }
.ministat__ic svg { width: 15px; height: 15px; }

/* donut */
.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut { width: 148px; height: 148px; flex: none; }
.donut__hole-label { fill: var(--text); font-weight: 750; }
.donut__hole-sub { fill: var(--muted); }
.donut-legend { display: grid; gap: 7px; font-size: 12.5px; min-width: 150px; flex: 1; }
.donut-legend__row { display: grid; grid-template-columns: 12px 1fr auto; gap: 8px; align-items: center; }
.donut-legend__dot { width: 10px; height: 10px; border-radius: 3px; }
.donut-legend__val { color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ================= Tables ================= */
.tablewrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.tbl th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 700; background: var(--surface-2);
  position: sticky; top: 0;
}
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.is-clickable { cursor: pointer; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .rowactions { display: flex; gap: 6px; justify-content: flex-end; }
.tbl .muted { color: var(--muted); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.empty h3 { color: var(--text-dim); margin-bottom: 4px; }

/* ================= Badges / pills ================= */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 650; letter-spacing: .02em;
  background: var(--surface-3); color: var(--text-dim);
  text-transform: capitalize;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--paid, .badge--won, .badge--active, .badge--completed, .badge--complete, .badge--reimbursed { color: var(--ok); background: var(--ok-dim); }
.badge--overdue, .badge--lost, .badge--cancelled, .badge--owed { color: var(--bad); background: var(--bad-dim); }
.badge--sent, .badge--partial, .badge--proposal, .badge--negotiation, .badge--planning, .badge--running { color: var(--warn); background: var(--warn-dim); }
.badge--draft, .badge--new, .badge--contacted, .badge--on-hold, .badge--upcoming { color: var(--info); background: var(--info-dim); }
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-dim);
  font-size: 11.5px; margin: 2px 4px 2px 0;
}
.prio-high { color: var(--bad); }
.prio-medium { color: var(--warn); }
.prio-low { color: var(--muted); }

/* ================= Forms ================= */
.field { display: grid; gap: 5px; }
.field > label { font-size: 12.5px; color: var(--text-dim); font-weight: 600; }
.input, .select, .textarea {
  width: 100%; padding: 9px 11px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  font: inherit; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-dim);
}
.textarea { resize: vertical; min-height: 68px; }

/* password field with show/hide toggle */
.pw-wrap { position: relative; display: block; }
.pw-wrap .input { padding-right: 40px; }
.pw-toggle {
  position: absolute; top: 0; right: 0; height: 100%; width: 38px;
  display: grid; place-items: center;
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--muted); border-radius: 0 9px 9px 0;
  transition: color .12s;
}
.pw-toggle:hover { color: var(--text); }
.pw-toggle.is-on { color: var(--brand); }
.pw-toggle i, .pw-toggle svg { width: 18px; height: 18px; display: block; }
.form-grid { display: grid; gap: 13px; grid-template-columns: 1fr 1fr; }
.form-grid .field--full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form .input { flex: 1; min-width: 180px; }
.hint { font-size: 12px; color: var(--muted); }
.hint code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.searchbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.searchbar .input, .searchbar .select { max-width: 280px; }

/* line items editor */
.items { display: grid; gap: 8px; }
.items__row { display: grid; grid-template-columns: 1fr 78px 110px 34px; gap: 8px; align-items: center; }
.items__row .input { padding: 7px 9px; }
.items__head { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.iremove { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; }
.iremove:hover { color: var(--bad); }
.itotals { margin-top: 12px; margin-left: auto; width: 240px; display: grid; gap: 6px; font-size: 13px; }
.itotals div { display: flex; justify-content: space-between; }
.itotals .grand { font-weight: 700; font-size: 15px; border-top: 1px solid var(--border); padding-top: 6px; }

/* ================= Modal ================= */
.modal-back {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(20, 24, 40, 0.35);
  backdrop-filter: blur(2px);
  display: grid; place-items: start center;
  padding: 40px 16px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 620px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  animation: pop .14s ease-out;
}
.modal--wide { max-width: 780px; }
@keyframes pop { from { transform: translateY(6px) scale(.99); opacity: 0; } }
.modal__h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px; border-bottom: 1px solid var(--border-soft);
}
.modal__h h3 { font-size: 15px; }
.modal__x { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; }
.modal__x:hover { color: var(--text); }
.modal__body { padding: 18px; }
.modal__foot {
  display: flex; justify-content: flex-end; gap: 9px;
  padding: 14px 18px; border-top: 1px solid var(--border-soft);
}
.modal__err {
  margin: 0 0 12px; color: var(--bad); font-size: 13px;
  background: var(--bad-dim); border: 1px solid rgba(214, 59, 48, 0.28);
  padding: 8px 10px; border-radius: 8px;
}

/* ================= Toast ================= */
.toast-root {
  position: fixed; right: 16px; bottom: 16px; z-index: 80;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  padding: 10px 14px; border-radius: 9px; font-size: 13px;
  box-shadow: var(--shadow); animation: pop .14s ease-out;
  max-width: 320px; color: var(--text);
}
.toast--ok { border-left-color: var(--ok); }
.toast--bad { border-left-color: var(--bad); }

/* ================= Charts ================= */
.chart { width: 100%; height: 210px; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .bar-a { fill: var(--brand); }
.chart .bar-b { fill: #9aa3bb; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 4; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.barlist { display: grid; gap: 10px; }
.barlist__row { display: grid; grid-template-columns: 130px 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.barlist__track { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.barlist__fill { height: 100%; background: var(--brand); border-radius: 999px; }
.barlist__val { font-variant-numeric: tabular-nums; color: var(--text-dim); }

/* stage strip */
.stages { display: grid; grid-auto-flow: column; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.stage {
  min-width: 132px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 13px; box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
}
.stage::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--brand); opacity: .5; }
.stage__name { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stage__count { font-size: 21px; font-weight: 730; margin-top: 3px; }
.stage__val { font-size: 12px; color: var(--text-dim); }

/* activity feed */
.feed { display: grid; gap: 2px; }
.feed__item { display: grid; grid-template-columns: 84px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
.feed__item:last-child { border-bottom: 0; }
.feed__when { color: var(--muted); font-size: 12px; }
.feed__who { color: var(--brand-hi); font-weight: 600; }

/* detail header */
.detail-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 6px; }
.detail-head h1 { font-size: 22px; }
.detail-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.page-head h1 { font-size: 19px; }

/* ---- partner (non-admin) session: hide admin-only controls ---- */
body[data-role="partner"] .rowactions,
body[data-role="partner"] .detail-head .actions { display: none !important; }
body[data-role="partner"] input[data-reimb] { pointer-events: none; opacity: .4; }
.role-note {
  display: flex; align-items: center; gap: 8px;
  background: var(--warn-dim); color: var(--warn);
  border: 1px solid rgba(214, 158, 46, 0.3);
  border-radius: 10px; padding: 9px 12px; font-size: 12.5px; font-weight: 600;
  margin-bottom: 16px;
}
.backlink { color: var(--muted); font-size: 12.5px; display: inline-flex; gap: 5px; align-items: center; margin-bottom: 12px; }
.backlink:hover { color: var(--text); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* invoice print view */
.invoice-doc { background: #fff; color: #14141a; border: 1px solid var(--border); border-radius: 12px; padding: 34px; box-shadow: var(--shadow-sm); }
.invoice-doc h2 { color: #14141a; }
.idoc-logo { height: 34px; width: auto; display: block; margin-bottom: 10px; }
.invoice-doc .idoc-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 16px; margin-bottom: 22px; }
.invoice-doc table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.invoice-doc th, .invoice-doc td { padding: 9px 10px; border-bottom: 1px solid #e2e2e6; font-size: 13px; text-align: left; }
.invoice-doc td.num, .invoice-doc th.num { text-align: right; }
.invoice-doc .idoc-tot { margin-left: auto; width: 260px; }
.invoice-doc .idoc-tot .grand { font-weight: 800; font-size: 16px; }
.invoice-doc .muted { color: #6a6a75; }

@media print {
  .sidebar, .mobilebar, .no-print { display: none !important; }
  body, .view, .invoice-doc { background: #fff !important; }
  .view { padding: 0; max-width: none; }
  .invoice-doc { border: 0; padding: 0; box-shadow: none; }
}

/* ================= Responsive ================= */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: var(--shadow); z-index: 44;
  }
  body.nav-open .sidebar { transform: none; }
  .mobilebar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 38;
    background: var(--brand);
    padding: 11px 16px;
    box-shadow: 0 6px 18px -12px rgba(228, 6, 43, 0.65);
  }
  .view { padding: 16px; }
}
@media (max-width: 560px) {
  body { font-size: 14px; }
  .view { padding: 14px; }
  .cards { gap: 12px; }
  .card { padding: 14px; }
  .page-head h1, .detail-head h1 { font-size: 17px; }
  .section-title { font-size: 11px; margin: 20px 0 10px; }
  .kpi__value { font-size: 19px; }
  .kpi__label { font-size: 11.5px; }
  .stage__count { font-size: 18px; }
  .tbl th, .tbl td { padding: 10px 11px; }
  .tbl { font-size: 13px; }
  .items__row { grid-template-columns: 1fr 60px 90px 28px; }
  .feed__item { grid-template-columns: 66px 1fr; font-size: 12.5px; }
  .donut-wrap { gap: 12px; justify-content: center; }
  .modal-back { padding: 16px 10px; }
  .modal__body { padding: 15px; }
  .form-grid { gap: 11px; }
}
