/* ---------------------------------------------------------------- base */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --ink: #1c2333;
  --ink-soft: #5b657a;
  --line: #e3e8f0;
  --accent: #2f6fed;
  --accent-dark: #2456c4;
  --accent-soft: #e8effd;
  --danger: #d64545;
  --danger-soft: #fdeaea;
  --success: #2e9e5b;
  --success-soft: #e6f6ec;
  --warn: #b97f18;
  --warn-soft: #fdf3df;
  --sidebar-bg: #171e2e;
  --sidebar-ink: #aeb7c9;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 60, .08), 0 4px 16px rgba(20, 30, 60, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--ink-soft); font-weight: normal; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pre-line { white-space: pre-line; }

/* ---------------------------------------------------------------- layout */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 220px;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.85rem;
  transition: width .18s ease;
  overflow: hidden;
}

main.with-sidebar { margin-left: 220px; padding: 1.75rem 2.25rem 3rem; transition: margin-left .18s ease; }
main { padding: 1.75rem 2.25rem 3rem; max-width: 1200px; }

.brand { display: flex; align-items: center; gap: .6rem; padding: 0 .5rem 1.25rem; }
.brand img { max-height: 34px; max-width: 120px; }
.brand-name { color: #fff; font-weight: 600; letter-spacing: .02em; }

.brand-mark {
  display: inline-grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #7a4fed);
  color: #fff;
  font-weight: 800;
  letter-spacing: .04em;
  border-radius: 8px;
  padding: .3rem .5rem;
  font-size: .85rem;
}
.brand-mark.large { font-size: 1.3rem; padding: .5rem .8rem; }

.sidebar nav { display: flex; flex-direction: column; gap: .15rem; flex: 1; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: .65rem;
  color: var(--sidebar-ink);
  padding: .55rem .65rem;
  border-radius: 8px;
  font-weight: 500;
}
.sidebar nav a svg {
  width: 18px; height: 18px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--accent); color: #fff; }

.sidebar-footer { border-top: 1px solid rgba(255, 255, 255, .1); padding-top: .9rem; display: grid; gap: .35rem; }
.user-chip { display: flex; align-items: center; gap: .55rem; padding: 0 .3rem .35rem; }
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .85rem;
  flex: none;
}
.user-name { color: #fff; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; }
.user-name small { color: var(--sidebar-ink); }
.footer-link {
  display: flex;
  align-items: center;
  gap: .55rem;
  color: var(--sidebar-ink);
  font-size: .85rem;
  padding: .25rem .3rem;
  border-radius: 6px;
}
.footer-link svg {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.footer-link:hover { color: #fff; text-decoration: none; background: rgba(255,255,255,.06); }
.as-button { background: none; border: none; cursor: pointer; text-align: left; width: 100%; font: inherit; }

/* --------------------------------------------------- language switcher */
.lang-switch { display: flex; gap: .3rem; padding: 0 .3rem .4rem; }
.lang-switch a {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--sidebar-ink);
  padding: .18rem .5rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, .15);
}
.lang-switch a:hover { color: #fff; text-decoration: none; }
.lang-switch a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.login-langs { justify-content: center; padding: 1.1rem 0 0; }
.login-langs a { color: var(--ink-soft); border-color: var(--line); }
.login-langs a:hover { color: var(--ink); }
body.sidebar-collapsed .lang-switch { flex-direction: column; align-items: center; padding: 0 0 .4rem; }

/* --------------------------------------------------- collapsible sidebar */
.brand { position: relative; }
.sidebar-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--sidebar-ink);
  cursor: pointer;
  padding: .3rem;
  border-radius: 6px;
  display: grid;
  place-items: center;
  flex: none;
}
.sidebar-toggle:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.sidebar-toggle svg {
  width: 18px; height: 18px;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
  transition: transform .18s ease;
}

body.sidebar-collapsed .sidebar { width: 64px; padding-left: .6rem; padding-right: .6rem; }
body.sidebar-collapsed main.with-sidebar { margin-left: 64px; }
body.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }
body.sidebar-collapsed .brand { justify-content: center; padding-left: 0; padding-right: 0; }
body.sidebar-collapsed .brand img,
body.sidebar-collapsed .brand-mark,
body.sidebar-collapsed .brand-name { display: none; }
body.sidebar-collapsed .sidebar-toggle { margin: 0 auto; }
body.sidebar-collapsed .sidebar nav a { justify-content: center; padding: .55rem 0; }
body.sidebar-collapsed .sidebar nav a span { display: none; }
body.sidebar-collapsed .user-chip { justify-content: center; padding-left: 0; padding-right: 0; }
body.sidebar-collapsed .user-name { display: none; }
body.sidebar-collapsed .footer-link { justify-content: center; padding: .4rem 0; }
body.sidebar-collapsed .footer-link span { display: none; }

/* ---------------------------------------------------------------- components */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.header-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.inline-form { display: inline; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .5rem .95rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: var(--surface); border-color: #f0c9c9; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent); }
.btn-sm { padding: .28rem .6rem; font-size: .84rem; }
.btn-lg { padding: .65rem 1.4rem; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }

.badge {
  display: inline-block;
  padding: .14rem .55rem;
  border-radius: 99px;
  font-size: .78rem;
  font-weight: 600;
  vertical-align: middle;
}
.badge-draft { background: var(--line); color: var(--ink-soft); }
.badge-sent { background: var(--warn-soft); color: var(--warn); }
.badge-paid { background: var(--success-soft); color: var(--success); }
.badge-admin { background: var(--accent-soft); color: var(--accent); }
.badge-overdue { background: var(--danger); color: #fff; }
.badge-soon { background: var(--warn-soft); color: var(--warn); border: 1px solid #ecd9ad; }

/* row tint by due-date urgency (unpaid invoices only) */
.table-card tbody tr.row-due-overdue { background: var(--danger-soft); }
.table-card tbody tr.row-due-overdue:hover { background: #fbdfdf; }
.table-card tbody tr.row-due-soon { background: var(--warn-soft); }
.table-card tbody tr.row-due-soon:hover { background: #faeccc; }

.flashes { margin-bottom: 1rem; display: grid; gap: .5rem; }
.flash {
  padding: .65rem 1rem;
  border-radius: 8px;
  border: 1px solid;
  font-weight: 500;
}
.flash-success { background: var(--success-soft); border-color: #bfe6cd; color: var(--success); }
.flash-error { background: var(--danger-soft); border-color: #f0c9c9; color: var(--danger); }

/* ---------------------------------------------------------------- tables */
.table-card { overflow-x: auto; }
.table-card table { width: 100%; border-collapse: collapse; }
.table-card th, .table-card td {
  padding: .7rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.table-card th {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-soft);
  background: #fafbfd;
}
.table-card tbody tr:last-child td { border-bottom: none; }
.table-card tbody tr:hover { background: #f8fafd; }
.table-card th.num, .table-card td.num { text-align: right; }
.table-card td { vertical-align: middle; }
.actions { display: flex; gap: .35rem; justify-content: flex-end; align-items: center; }
.actions form { display: inline; }
.actions .btn { white-space: nowrap; }
.actions-col { width: 1%; white-space: nowrap; }
.invoice-number { font-weight: 600; font-variant-numeric: tabular-nums; }
.reset-row td { background: #f8fafd; }
.inline-flex { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------- forms */
label { display: block; font-weight: 600; font-size: .88rem; }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=search], select, textarea {
  display: block;
  width: 100%;
  margin-top: .3rem;
  padding: .5rem .7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input:disabled { background: var(--bg); color: var(--ink-soft); }
textarea { resize: vertical; }

.form-section { padding: 1.4rem 1.6rem; margin-bottom: 1.1rem; }
.form-section.narrow { max-width: 640px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem 1.25rem;
}
.form-grid .span-2 { grid-column: 1 / -1; }
.checkbox-label { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.checkbox-label input { width: auto; margin: 0; }
.hint { display: block; font-weight: normal; color: var(--ink-soft); margin-top: .3rem; font-size: .8rem; }
.form-actions { display: flex; gap: .6rem; align-items: center; margin-top: .35rem; }
.stacked-form { display: grid; gap: .9rem; }

.filter-bar {
  display: flex;
  gap: .6rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.filter-bar input[type=search] { width: 260px; margin: 0; }
.filter-bar select { width: auto; margin: 0; }

/* line items editor */
.items-table { width: 100%; border-collapse: collapse; margin-bottom: .75rem; }
.items-table th {
  text-align: left;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-soft);
  padding: 0 .5rem .4rem 0;
}
.items-table td { padding: .25rem .5rem .25rem 0; vertical-align: middle; }
.items-table input { margin-top: 0; }
.qty-col { width: 90px; }
.price-col { width: 150px; }
.remove-col { width: 40px; }
.row-amount { min-width: 120px; color: var(--ink-soft); font-size: .9rem; }

.totals-box {
  margin-left: auto;
  max-width: 320px;
  display: grid;
  gap: .35rem;
  padding-top: .75rem;
  border-top: 1px solid var(--line);
}
.totals-box > div { display: flex; justify-content: space-between; }
.totals-box .grand { font-weight: 700; font-size: 1.05rem; border-top: 1px solid var(--line); padding-top: .4rem; }

/* ---------------------------------------------------------------- empty state */
.empty-state {
  text-align: center;
  padding: 3.5rem 2rem;
  display: grid;
  gap: .5rem;
  justify-items: center;
}
.empty-state h2 { margin: 0; }
.empty-state p { margin: 0 0 .75rem; color: var(--ink-soft); }

/* ---------------------------------------------------------------- login */
.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
}
.login-page main { padding: 1rem; width: 100%; max-width: 400px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 2.25rem 2rem;
}
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-brand img { max-height: 56px; max-width: 180px; }
.login-brand h1 { margin: .6rem 0 .2rem; }
.login-brand p { margin: 0; color: var(--ink-soft); }

/* ------------------------------------------------- invoice document sheet
   Matches the reference Word-style invoice: blue INVOICE title, Issued By /
   Billed To columns, plain bordered table with gray header. Sans-serif
   throughout (same family as the title) keeps the dollar amounts reading
   as clean, evenly-weighted digits instead of serif old-style figures. */
.doc-sheet {
  max-width: 820px;
  padding: 4.5rem 5rem 5rem;
  font-family: Calibri, "Segoe UI", Arial, sans-serif;
  font-variant-numeric: lining-nums tabular-nums;
  font-size: 15px;
  color: #000;
  line-height: 1.5;
}
.doc-head { display: flex; align-items: flex-start; margin-bottom: 3.5rem; }
.doc-logo { width: 50%; padding-top: .4rem; }
.doc-logo img { width: 260px; max-width: 100%; }
.doc-meta { width: 50%; }
.doc-title {
  color: #2e74b5;
  font-weight: 700;
  font-size: 1.25rem;
  margin-bottom: .45rem;
}
.doc-meta div { margin-bottom: .15rem; }

.doc-parties { display: flex; margin-bottom: 3.5rem; }
.doc-party { width: 50%; }
.doc-party-label { font-weight: 700; margin-bottom: 2.4rem; }
.doc-party-body > div:first-child { margin-bottom: 0; }
.doc-address { font-size: .93em; }

.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
}
.doc-table th, .doc-table td {
  border: 1px solid #000;
  padding: .45rem .7rem;
  text-align: left;
  vertical-align: top;
}
.doc-table th {
  background: #f2f2f2;
  font-weight: 700;
}
.doc-table th:last-child, .doc-table td:last-child { width: 42%; }
.doc-table .doc-total td { font-weight: 700; }
.doc-qty { color: #444; font-size: .9em; }
.doc-notes { margin-top: 2.5rem; font-size: .93em; }
.doc-payref { margin-top: 2.5rem; font-size: .93em; word-break: break-all; }
.txid-box { margin-top: 1.1rem; }
.txid-box input[type=text] { flex: 1; min-width: 260px; margin-top: 0; }

/* sidebar/login logo (SVG has a white background baked in) */
.brand img, .login-brand img { background: #fff; border-radius: 8px; }

/* ---------------------------------------------------------------- print */
@page { size: Letter; margin: 0.75in 0.9in; }

@media print {
  body { background: #fff; }
  .no-print, .sidebar { display: none !important; }
  main.with-sidebar, main { margin: 0; padding: 0; max-width: none; }
  .flashes { display: none !important; }
  .doc-sheet {
    border: none;
    box-shadow: none;
    border-radius: 0;
    max-width: none;
    padding: 0;
  }
  /* keep the document's two-column blocks side by side on paper */
  .doc-head, .doc-parties { display: flex; flex-direction: row; }
  .doc-logo, .doc-meta, .doc-party { width: 50%; }
  .doc-table { page-break-inside: auto; }
  .doc-table tr { page-break-inside: avoid; }
}

/* ---------------------------------------------------------------- responsive
   (screen only — print must keep the two-column document layout) */
@media screen and (max-width: 760px) {
  .sidebar {
    position: static;
    width: auto;
    flex-direction: row;
    align-items: center;
    padding: .6rem .9rem;
    gap: .75rem;
  }
  .sidebar nav { flex-direction: row; }
  .sidebar nav a span { display: none; }
  /* collapse toggle is desktop-only; ignore collapsed state in top-bar mode */
  .sidebar-toggle { display: none; }
  body.sidebar-collapsed .sidebar { width: auto; padding: .6rem .9rem; }
  body.sidebar-collapsed main.with-sidebar { margin-left: 0; }
  body.sidebar-collapsed .brand img, body.sidebar-collapsed .brand-mark { display: block; }
  body.sidebar-collapsed .sidebar nav a { padding: .55rem .65rem; }
  body.sidebar-collapsed .user-chip { justify-content: flex-start; }
  .sidebar-footer { border: none; padding: 0; margin-left: auto; display: flex; align-items: center; }
  .user-chip .user-name, .footer-link:not(.as-button) { display: none; }
  main.with-sidebar { margin-left: 0; padding: 1.1rem; }
  .doc-sheet { padding: 1.75rem 1.25rem; }
  .doc-head { flex-direction: column; gap: 1.5rem; }
  .doc-logo, .doc-meta, .doc-party { width: 100%; }
  .doc-parties { flex-direction: column; gap: 1.5rem; margin-bottom: 2rem; }
  .doc-party-label { margin-bottom: .5rem; }
}
