/* Tax Invoice CRM: shared styles for the pages around the invoice tool.
   Palette matches the existing tool. The tool's own styles live in tool/tool.css. */

:root {
  --accent: #1F5C57;
  --accent-hover: #184A46;
  --accent-soft: #E4F0EE;
  --bg: #ECEFED;
  --surface: #FFF;
  --line: #D3D9D7;
  --text: #1B2422;
  --muted: #5E6B68;
  --danger: #B3261E;
  --danger-soft: #FBEAE9;
  --info-soft: #EEF3F2;
  --radius: 12px;
  --radius-sm: 8px;
  --nav-w: 232px;
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; font-weight: 600; }
h2 { font-size: 17px; font-weight: 600; margin-bottom: 14px; }
p { margin: 0; }
a { color: var(--accent); }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.muted { color: var(--muted); }

/* ---------- Shell & navigation ---------- */
.shell { min-height: 100vh; }

.nav {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--nav-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  z-index: 50;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 22px;
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
}
.nav-logo {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent-soft);
  font-size: 18px;
}
.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.nav-list form { margin: 0; }
.nav-logout { margin-top: auto; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  text-align: start;
  cursor: pointer;
}
.nav-link:hover { background: var(--bg); }
.nav-link.is-active { background: var(--accent); color: #fff; }
.nav-icon { width: 22px; text-align: center; font-size: 17px; }
.nav-user {
  padding: 14px 12px 0;
  margin-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.main {
  margin-left: var(--nav-w);
  padding: 28px 32px 48px;
  max-width: calc(1200px + var(--nav-w));
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

/* ---------- Cards, grids, info ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  align-items: start;
}
.info { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 10px 20px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

.empty { text-align: center; padding: 48px 22px; }
.empty p + p { margin-top: 6px; }
.empty-icon { font-size: 36px; margin-bottom: 8px; }

/* ---------- Forms & buttons ---------- */
.form label { display: block; margin: 14px 0 6px; font-weight: 500; }
.form label:first-of-type { margin-top: 0; }
.form input[type="text"],
.form input[type="password"],
.form input:not([type]) {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.form input:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.form .btn { margin-top: 20px; }
.hint { margin-top: 5px; font-size: 13px; color: var(--muted); }
.check { display: flex !important; align-items: center; gap: 8px; font-weight: 400 !important; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-block { width: 100%; }
.btn:focus-visible, .nav-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Alerts ---------- */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--accent-soft); color: var(--accent); }
.alert-info { background: var(--info-soft); color: var(--text); border: 1px solid var(--line); }

/* ---------- Extra buttons ---------- */
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }
.btn-ghost:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 13px; font-weight: 500; border-radius: 7px; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }

/* ---------- My Invoices ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}
.stat-label { display: block; font-size: 13px; color: var(--muted); }
.stat-value {
  display: block;
  margin-top: 2px;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.stat-value.is-paid { color: var(--accent); }
.stat-value.is-open { color: #9A5B00; }
.stats-note { margin: 6px 2px 18px; font-size: 12.5px; color: var(--muted); }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 16px;
}
.filter { display: flex; flex-direction: column; gap: 5px; min-width: 140px; }
.filter-q { flex: 1 1 260px; }
.filter label { font-size: 13px; color: var(--muted); }
.filter input, .filter select, .status-select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  min-height: 40px;
}
.filter input:focus-visible, .filter select:focus-visible, .status-select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}

.list-card { padding: 0; overflow: hidden; }
.list-msg { padding: 40px 20px; text-align: center; color: var(--muted); }
.list-msg p + p, .list-msg p + a { margin-top: 6px; display: inline-block; }
.list-msg .empty-icon { display: block; margin: 0 0 6px; }
.list-msg.is-error { color: var(--danger); }
.list-msg[hidden], .table-wrap[hidden], .pager[hidden] { display: none; }

.table-wrap { overflow-x: auto; }
.inv-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.inv-table th {
  padding: 11px 10px;
  text-align: start;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: #F6F8F7;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.inv-table td { padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.inv-table tbody tr:last-child td { border-bottom: 0; }
.inv-table tbody tr:hover td { background: #FAFBFB; }
.inv-table .num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.inv-table .nowrap, .inv-no { white-space: nowrap; }
.inv-no a { font-weight: 600; text-decoration: none; }
.inv-no a:hover { text-decoration: underline; }
.inv-cust { min-width: 140px; max-width: 220px; }
.inv-table th:first-child, .inv-table td:first-child { padding-left: 14px; }
.inv-table th:last-child, .inv-table td:last-child { padding-right: 14px; }
.mono { font-variant-numeric: tabular-nums; white-space: nowrap; }

.row-actions { display: flex; gap: 6px; align-items: center; justify-content: flex-end; white-space: nowrap; }
.btn-more { min-width: 34px; padding-inline: 8px; font-size: 16px; line-height: 1; letter-spacing: 1px; }
.actions-col { text-align: end; }

/* Status: a badge that is also the dropdown */
.status-pill {
  appearance: none;
  -webkit-appearance: none;
  padding: 3px 24px 3px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 8px 5px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%23596866'/%3E%3C/svg%3E");
}
.status-pill:hover { border-color: currentColor; }
.status-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.status-pill:disabled { opacity: .6; cursor: progress; }
.status-pill.is-paid { background-color: var(--accent-soft); color: var(--accent); }
.status-pill.is-unpaid { background-color: var(--danger-soft); color: var(--danger); }
.status-pill.is-partial { background-color: #FDF1DC; color: #9A5B00; }
.status-pill option { background: #fff; color: var(--text); }

/* "⋯" actions menu (attached to <body> so the table can't clip it) */
.menu {
  position: fixed;
  z-index: 200;
  min-width: 160px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(27, 36, 34, .14);
}
.menu-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--bg); outline: none; }
.menu-item.is-danger { color: var(--danger); }
.menu-item.is-danger:hover, .menu-item.is-danger:focus-visible { background: var(--danger-soft); }

.list-card { transition: opacity .15s; }
.list-card.is-loading .table-wrap { opacity: .55; pointer-events: none; }

/* Toast (CRM.toast) */
.crm-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 300;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 9px;
  background: var(--text);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.crm-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.crm-toast.is-error { background: var(--danger); }
@media (prefers-reduced-motion: reduce) {
  .crm-toast, .list-card { transition: none; }
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-paid { background: var(--accent-soft); color: var(--accent); }
.badge-unpaid { background: var(--danger-soft); color: var(--danger); }
.badge-partial { background: #FDF1DC; color: #9A5B00; }
.badge-muted { background: var(--bg); color: var(--muted); }
.badge-danger { background: var(--danger); color: #fff; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
}

/* ---------- Save status (above the invoice tool) ---------- */
.crm-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  max-width: 980px;
  margin: 0 auto 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 500;
}
.crm-status[hidden] { display: none; }
.crm-status.is-saving { color: var(--muted); }
.crm-status.is-ok { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.crm-status.is-err { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.crm-status.is-info { background: var(--info-soft); }
.crm-status-action {
  padding: 5px 12px;
  border: 1px solid currentColor;
  border-radius: 7px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.crm-status-action:hover { background: rgba(0, 0, 0, .05); }

/* Bridge modes: hide the tool while a saved invoice loads; view mode hides Edit/New */
.crm-loading #zinv-app { visibility: hidden; }
.crm-view #z-back, .crm-view #z-new { display: none !important; }

/* ---------- Login page ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand h1 { font-size: 20px; color: var(--accent); }
.auth-brand .muted { font-size: 14px; }
.auth-card .check { margin-top: 16px; }

/* ---------- Mobile: bottom tab bar ---------- */
@media (max-width: 760px) {
  .nav {
    inset: auto 0 0 0;
    width: auto;
    height: auto;
    flex-direction: row;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--line);
  }
  .nav-brand, .nav-user { display: none; }
  .nav-list { flex-direction: row; gap: 2px; }
  .nav-list > li { flex: 1; }
  .nav-logout { margin-top: 0; }
  .nav-link {
    flex-direction: column;
    gap: 2px;
    padding: 6px 2px;
    font-size: 11px;
    text-align: center;
  }
  .nav-icon { font-size: 19px; }
  .main { margin-left: 0; padding: 18px 14px calc(88px + env(safe-area-inset-bottom)); }
  h1 { font-size: 21px; }
  .card { padding: 18px; }
  .page-head .btn { padding: 8px 12px; }

  /* My Invoices: 2×2 stats, stacked filters, table rows become cards */
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 18px; }
  .filter { flex: 1 1 calc(50% - 6px); min-width: 0; }
  .filter-q { flex-basis: 100%; }
  .filters .btn { flex: 1 1 100%; }

  .list-card { padding: 0; background: transparent; border: 0; overflow: visible; }
  .table-wrap { overflow: visible; }
  .inv-table thead { display: none; }
  .inv-table, .inv-table tbody { display: block; }
  .inv-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px 12px;
    margin-bottom: 12px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .inv-table tbody tr:hover td { background: none; }
  .inv-table td { display: block; padding: 0; border: 0; min-width: 0; max-width: none; }
  .inv-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 11.5px;
    color: var(--muted);
  }
  .inv-table td.inv-no, .inv-table td.inv-cust, .inv-table td.actions-col { grid-column: 1 / -1; }
  .inv-table td.inv-no::before, .inv-table td.actions-col::before { display: none; }
  .inv-table td.inv-no a { font-size: 16px; }
  .inv-table .num { text-align: start; }
  .row-actions { justify-content: flex-start; padding-top: 10px; margin-top: 4px; border-top: 1px solid var(--line); }
  .row-actions .btn { flex: 1; padding-block: 8px; }
  .row-actions .btn-more { flex: 0 0 44px; }
  .inv-table td.mono { white-space: normal; overflow-wrap: anywhere; }
  .crm-toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .pager { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
}
