:root {
  --navy: #0a3a63;
  --brand: #0d5aa7;
  --brand-soft: #e8f1fa;
  --ink: #16202b;
  --ink-2: #5a6b7c;
  --line: #dbe3ec;
  --bg: #f4f7fb;
  --danger: #b3261e;
  --ok: #1c7a4a;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
}

a { color: var(--brand); }

/* ------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 24px;
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: #fff;
  text-decoration: none;
  padding: 14px 0;
}
.brand-mark { font-weight: 700; letter-spacing: .06em; font-size: 20px; }
.brand-text { color: #b9d3ea; font-size: 14px; }

.topbar nav { display: flex; gap: 4px; margin-right: auto; }
.topbar nav a {
  color: #cfe1f2;
  text-decoration: none;
  padding: 16px 14px;
  border-bottom: 3px solid transparent;
  font-size: 14px;
}
.topbar nav a:hover { color: #fff; }
.topbar nav a.on { color: #fff; border-bottom-color: #5aa9e6; }

.who { display: flex; align-items: center; gap: 14px; font-size: 13px; color: #b9d3ea; }
.who a { color: #fff; }

/* -------------------------------------------------------------- page */

.wrap { max-width: 1080px; margin: 0 auto; padding: 24px 20px 64px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin: 8px 0 20px;
}
.page-head.sticky {
  position: sticky;
  top: 52px;
  z-index: 10;
  background: var(--bg);
  padding: 12px 0;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

h1 { font-size: 24px; margin: 0; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; color: var(--navy); }
.sub, .hint { color: var(--ink-2); font-size: 13px; margin: 4px 0 0; }
.hint { margin-bottom: 12px; }
.muted { color: var(--ink-2); font-size: 13px; }

/* ------------------------------------------------------------- cards */

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h2 { margin-bottom: 0; }
.card-head-actions { display: flex; gap: 8px; }

.row-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 12px;
  background: #fbfcfe;
}
.row-head {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--line);
}
.handle { font-size: 13px; font-weight: 600; color: var(--ink-2); }

/* ------------------------------------------------------------- forms */

label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 12px; }
label.check, label.check.tight { display: flex; align-items: center; gap: 8px; color: var(--ink); }
label.check.tight { margin-bottom: 0; }

input[type=text], input:not([type]), input[type=email], input[type=password],
input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
textarea { line-height: 1.55; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}
input[type=color] { padding: 3px; height: 38px; }
.type-select { width: auto; margin-top: 0; padding: 5px 8px; font-size: 13px; }

.grid { display: grid; gap: 0 16px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: 1fr 1fr 1fr; }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }

.filters { display: flex; gap: 8px; margin-bottom: 16px; }
.filters input, .filters select { margin-top: 0; width: auto; }
.filters input[type=search] { flex: 1; }

.form-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ----------------------------------------------------------- buttons */

.btn {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  border: 1px solid var(--brand);
  border-radius: 6px;
  padding: 9px 16px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: #0b4c8f; }
.btn.ghost { background: #fff; color: var(--brand); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.small { padding: 6px 11px; font-size: 13px; }

.link-danger {
  background: none;
  border: 0;
  color: var(--danger);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  margin-left: auto;
  padding: 0;
}

/* ------------------------------------------------------------- table */

.table-scroll { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th {
  text-align: left;
  font-size: 12px;
  letter-spacing: .02em;
  color: var(--ink-2);
  font-weight: 600;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #f7fafd;
}
table.list td { padding: 12px 14px; border-bottom: 1px solid #eef2f7; vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list .num { text-align: right; white-space: nowrap; }
table.list .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
table.list .strong { font-weight: 600; text-decoration: none; display: block; }
table.list .muted { display: block; }
table.list .actions { white-space: nowrap; text-align: right; }
table.list .actions a { margin-left: 12px; font-size: 13px; text-decoration: none; }
table.list .actions a.danger { color: var(--danger); }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef2f7;
  color: var(--ink-2);
}
.pill.sent, .pill.partial { background: #e5eefc; color: #1a4f9c; }
.pill.accepted, .pill.paid { background: #e3f4ec; color: var(--ok); }
.pill.declined, .pill.cancelled { background: #fbe9e7; color: var(--danger); }
.pill.unpaid { background: #fdf0dd; color: #8a5b12; }

td.overdue { color: var(--danger); font-weight: 600; }

/* -------------------------------------------------- invoice editor */

table.line-items { width: 100%; border-collapse: collapse; font-size: 14px; }
table.line-items th {
  text-align: left;
  font-size: 12px;
  color: var(--ink-2);
  font-weight: 600;
  padding: 8px 8px;
  border-bottom: 1px solid var(--line);
}
table.line-items td { padding: 8px; border-bottom: 1px solid #eef2f7; vertical-align: top; }
table.line-items input, table.line-items textarea { margin-top: 0; }
table.line-items .w-code { width: 15%; }
table.line-items .w-qty { width: 10%; }
table.line-items .w-rate { width: 14%; }
table.line-items .w-amt { width: 14%; text-align: right; }
table.line-items td.amount { text-align: right; font-variant-numeric: tabular-nums; padding-top: 17px; }
table.line-items .qty, table.line-items .rate { text-align: right; }
table.line-items .link-danger { margin-left: 0; }

.totals-row { display: flex; gap: 24px; margin-top: 18px; flex-wrap: wrap; }
.totals-inputs { flex: 1 1 340px; display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.totals-preview {
  flex: 0 1 320px;
  background: #f7fafd;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 14px;
}
.totals-preview div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals-preview strong { font-variant-numeric: tabular-nums; }
.totals-preview .grand {
  border-top: 1px solid var(--line);
  margin-top: 6px;
  padding-top: 8px;
  font-size: 16px;
}
.totals-preview .words {
  margin: 10px 0 0;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  font-size: 12px;
  color: var(--ink-2);
  font-style: italic;
}

/* ------------------------------------------------------------ notices */

.flash, .error, .callout {
  border-radius: 6px;
  padding: 11px 14px;
  margin: 16px 0;
  font-size: 14px;
}
.flash { background: #e3f4ec; color: #14603a; border: 1px solid #bfe3d1; }
.error { background: #fbe9e7; color: #8c1d18; border: 1px solid #f2c4bf; }
.callout { background: var(--brand-soft); border: 1px solid #c5ddf3; }

.empty {
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 48px;
  text-align: center;
  color: var(--ink-2);
}

/* -------------------------------------------------------- auth pages */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(160deg, #0a3a63, #0d5aa7 70%);
  padding: 24px;
}
.auth-card {
  background: #fff;
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(6, 30, 55, .28);
}
.auth-mark { font-weight: 700; font-size: 22px; letter-spacing: .06em; color: var(--brand); }
.auth-card h1 { font-size: 20px; margin: 6px 0 2px; }
.auth-sub { color: var(--ink-2); font-size: 13px; margin: 0 0 20px; }
.auth-card .btn { width: 100%; margin-top: 6px; }
.install-log { font-size: 13px; color: var(--ink-2); padding-left: 18px; }
.danger-note { background: #fbe9e7; color: #8c1d18; padding: 10px 12px; border-radius: 6px; font-size: 13px; }

/* ---------------------------------------------------------- settings */

.upload {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  background: #fbfcfe;
}
.upload-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.upload .preview { max-width: 100%; max-height: 60px; display: block; margin-bottom: 8px; }
.upload input[type=file] { font-size: 12px; margin-top: 8px; }

.preview-box {
  align-self: start;
  background: var(--brand-soft);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 13px;
  color: var(--ink-2);
  margin-top: 22px;
}
.preview-box strong { color: var(--navy); font-size: 16px; }

code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; font-size: 13px; }

@media (max-width: 760px) {
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: span 1; }
  .topbar { flex-wrap: wrap; gap: 12px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head.sticky { position: static; }
}
