:root {
  --navy: #08233c;
  --ink: #132536;
  --blue: #0077c8;
  --sky: #1aa6e0;
  --mist: #eef4f9;
  --line: #d5e1ec;
  --muted: #5d7286;
  --card: #ffffff;
  --ok: #0b7a4a;
  --ok-bg: #e7f7ef;
  --warn: #9a5b00;
  --warn-bg: #fff4e0;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --sent: #155e9a;
  --sent-bg: #e5f2fb;
  --shadow: 0 10px 30px rgba(8, 35, 60, 0.08);
  --radius: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 400px at 10% -10%, rgba(26, 166, 224, 0.16), transparent 60%),
    var(--mist);
  min-height: 100vh;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand img { height: 36px; width: auto; background: #fff; border-radius: 8px; padding: 4px 8px; }
.brand span {
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;
}
.nav { display: flex; flex-wrap: wrap; gap: 4px 10px; flex: 1; }
.nav a {
  color: #d7e7f5;
  text-decoration: none;
  font-size: 14px;
  padding: 6px 8px;
  border-radius: 8px;
}
.nav a:hover, .nav a.active { background: rgba(255,255,255,0.1); color: #fff; text-decoration: none; }
.userbox { display: flex; align-items: center; gap: 12px; font-size: 13px; color: #c5d8e8; }
.userbox a { color: #fff; }
.nav-toggle {
  display: none;
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 8px;
  padding: 6px 10px;
}
.wrap { width: min(1100px, calc(100% - 32px)); margin: 28px auto 40px; }
.foot { text-align: center; color: var(--muted); padding: 10px 0 30px; font-size: 13px; }
h1 { font-size: 28px; margin: 0 0 8px; letter-spacing: -0.02em; }
.lede { color: var(--muted); margin: 0 0 22px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}
.tile {
  background: var(--card);
  border-radius: var(--radius);
  min-height: 150px;
  padding: 22px 18px 18px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  border: 1px solid #e8eef4;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform .15s ease, box-shadow .15s ease;
}
.tile:hover { transform: translateY(-3px); box-shadow: 0 16px 34px rgba(8,35,60,.12); text-decoration: none; }
.tile .ico {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(180deg, #e8f6fc, #d5eefb);
  color: var(--blue);
}
.tile strong { font-size: 16px; display: block; margin-top: 16px; }
.tile span { color: var(--muted); font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 0 0 22px; }
.stat { background: var(--card); border-radius: 14px; padding: 14px 16px; border: 1px solid var(--line); }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 13px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  border: 1px solid #e8eef4;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
td.num, th.num { text-align: right; white-space: nowrap; }
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--blue); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 16px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.05); text-decoration: none; color: #fff; }
.btn.secondary { background: #e7eef5; color: var(--navy); }
.btn.ghost { background: transparent; color: var(--blue); border: 1px solid var(--line); }
.btn.danger { background: var(--bad); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
label { display: block; font-weight: 600; margin: 0 0 6px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid #c9d6e2; background: #fff; font: inherit; color: inherit;
}
textarea { min-height: 84px; resize: vertical; }
.row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.field { margin-bottom: 14px; }
.lines { width: 100%; }
.lines td { vertical-align: middle; }
.flash { border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--bad-bg); color: var(--bad); }
.badge { display: inline-block; border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 700; }
.badge-draft { background: #eef1f4; color: #445566; }
.badge-sent { background: var(--sent-bg); color: var(--sent); }
.badge-converted { background: var(--ok-bg); color: var(--ok); }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.login-body {
  min-height: 100vh;
  display: grid; place-items: center;
  background:
    radial-gradient(900px 420px at 50% -10%, rgba(0,119,200,.25), transparent 55%),
    var(--navy);
}
.login-card {
  width: min(420px, calc(100% - 32px));
  background: #fff;
  border-radius: 24px;
  padding: 32px 28px 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,.22);
  text-align: center;
}
.login-card img { width: 170px; height: auto; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; margin: 6px 0 4px; }
.login-card .lede { margin-bottom: 18px; }
.login-card .field { text-align: left; }
.login-card .btn { width: 100%; margin-top: 6px; }
.doc-hero { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.doc-hero h1 { margin: 0; }
.meta { color: var(--muted); }
.low { color: var(--bad); font-weight: 700; }
@media (max-width: 800px) {
  .row { grid-template-columns: 1fr; }
  .nav-toggle { display: inline-block; margin-left: auto; }
  .nav, .userbox { display: none; }
  .topbar.is-open .nav, .topbar.is-open .userbox {
    display: flex; flex-direction: column; align-items: flex-start;
    width: 100%;
  }
  .topbar { flex-wrap: wrap; }
  .wrap { width: calc(100% - 24px); margin-top: 18px; }
}
@media print {
  .topbar, .foot, .actions, .flash, .nav-toggle, .no-print { display: none !important; }
  body { background: #fff; }
  .wrap { width: auto; margin: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
}

.doc-grand { text-align: right; font-size: 18px; margin: 16px 0 0; }
.filter-card { margin-bottom: 16px; }

.badge-unpaid { background: var(--bad-bg); color: var(--bad); }
.badge-partial { background: var(--warn-bg); color: var(--warn); }
.badge-paid { background: var(--ok-bg); color: var(--ok); }
.hint { display: block; color: var(--muted); font-size: 13px; margin-top: 6px; font-weight: 400; }
.share-card { margin-top: 18px; }
.share-grid { display: grid; gap: 18px; }
@media (min-width: 860px) {
  .share-grid { grid-template-columns: 1.3fr .9fr; align-items: start; }
}
.share-body { background: var(--mist); }
.share-wrap { padding-bottom: 40px; }
.share-brand { display: flex; align-items: center; gap: 14px; margin: 8px 0 20px; }
.share-brand img { width: 64px; height: auto; }
.share-brand strong { display: block; font-size: 20px; }
.share-brand span { color: var(--muted); }
.share-toolbar { display: flex; gap: 8px; margin-bottom: 16px; }
