:root {
  --navy: #151a3a;
  --navy-2: #1e2550;
  --blue: #2f6fed;
  --blue-soft: #e8effc;
  --green: #1f9d5c;
  --green-soft: #e5f7ed;
  --amber: #c67a12;
  --amber-soft: #fbf1dc;
  --red: #d64545;
  --red-soft: #fdeaea;
  --purple: #6b57d6;
  --purple-soft: #eee9fb;
  --bg: #f3f5fa;
  --panel: #ffffff;
  --line: #e3e8f2;
  --text: #152038;
  --muted: #66758c;
  --sidebar: #0d1228;
  --sidebar-text: #e8eef8;
  --sidebar-muted: #93a0bb;
  --shadow: 0 8px 24px rgba(21, 32, 56, .06);
  --radius: 14px;
  --focus: 0 0 0 3px rgba(47, 111, 237, .28);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #eef1f6;
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.45;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.skip-link { position: absolute; left: -999px; top: 8px; }
.skip-link:focus { left: 8px; background: #fff; padding: .4rem .7rem; z-index: 40; border-radius: 8px; }
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 1.1rem .85rem 1.2rem;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.brand { display: block; padding: .2rem .45rem .85rem; }
.brand img { width: 148px; height: auto; display: block; }
.nav { display: flex; flex-direction: column; gap: .12rem; }
.nav a {
  color: var(--sidebar-text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .58rem .7rem;
  border-radius: 10px;
  font-weight: 650;
}
.nav a svg { width: 18px; height: 18px; flex: 0 0 auto; }
.nav a:hover, .nav a.active { background: var(--navy-2); text-decoration: none; }
.nav a.active { box-shadow: inset 3px 0 0 var(--blue); }
.safety-chip {
  margin-top: auto;
  background: #161d3a;
  border: 1px solid #2a335c;
  color: var(--sidebar-muted);
  border-radius: 12px;
  padding: .7rem .8rem;
  font-size: .78rem;
}
.safety-chip strong { display: block; color: #fff; margin-bottom: .15rem; }
.content { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .85rem 1.25rem;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 6;
}
.menu-btn, .icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  min-width: 40px;
  height: 40px;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn { display: inline-flex; position: relative; text-decoration: none; color: var(--text); }
.icon-btn .count {
  position: absolute; top: -4px; right: -4px;
  background: var(--red); color: #fff; border-radius: 99px;
  font-size: .68rem; min-width: 16px; text-align: center; padding: 0 .25rem;
}
.search {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: .45rem;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: .1rem .7rem;
  height: 42px;
}
.search svg, .icon-btn svg, .menu-btn svg { width: 18px; height: 18px; flex: 0 0 auto; }
.search input { border: 0; background: transparent; padding: .55rem .15rem; width: 100%; min-width: 0; }
.search input:focus { box-shadow: none; }
.profile details { position: relative; }
.profile summary { list-style: none; display: flex; align-items: center; gap: .45rem; cursor: pointer; font-weight: 700; }
.profile summary::-webkit-details-marker { display: none; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--blue-soft); color: var(--blue);
  display: grid; place-items: center; font-weight: 800;
}
.profile .menu {
  position: absolute; right: 0; top: 120%; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; min-width: 180px; box-shadow: var(--shadow); padding: .35rem;
}
.profile .menu a, .profile .menu button {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: .5rem .6rem; border-radius: 8px; color: var(--text); cursor: pointer; text-decoration: none;
}
.profile .menu a:hover, .profile .menu button:hover { background: var(--bg); }
.page { padding: 1.35rem 1.5rem 2rem; }
.page-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-end; margin-bottom: 1rem; flex-wrap: wrap; }
.kicker { margin: 0 0 .2rem; color: var(--blue); font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.page-head h1 { margin: 0 0 .25rem; font-size: 1.7rem; letter-spacing: -.02em; }
.page-head p { margin: 0; }
.muted { color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(6, 1fr); gap: .8rem; margin-bottom: 1rem; }
.card, .panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card { padding: .95rem 1rem; }
.card span { display: block; color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; }
.card strong { display: block; margin-top: .3rem; font-size: 1.35rem; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.stat { position: relative; overflow: hidden; padding-left: 1.15rem; }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--blue); }
.panel { padding: 1rem; margin-bottom: 1rem; }
.panel h2 { margin: 0 0 .75rem; font-size: 1.05rem; }
.split { display: grid; grid-template-columns: 1.3fr .7fr; gap: .8rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { text-align: left; padding: .72rem .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .72rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); background: #f7f9fc; font-weight: 800; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f5f8fd; }
tr.row-link { cursor: pointer; }
tr.row-link:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
a.entry { color: var(--navy); font-weight: 750; text-decoration: none; }
a.entry:hover { color: var(--blue); text-decoration: none; }
.row-hint { margin: .7rem .15rem 0; font-size: .82rem; }
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .8rem; }
.report-card { display: flex; flex-direction: column; gap: .35rem; min-height: 148px; text-decoration: none; color: inherit; transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease; }
.report-card span { color: var(--blue); }
.report-card strong { font-size: 1.12rem; color: var(--text); }
.report-card p { margin: 0; color: var(--muted); font-size: .9rem; line-height: 1.4; }
.report-card:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(21, 32, 56, .1); border-color: #c5d4f6; text-decoration: none; }
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 42px; height: 42px; padding: 0 .9rem; border-radius: 10px; border: 1px solid transparent;
  background: var(--blue); color: #fff; font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--line); }
.btn.danger { background: var(--red); }
.btn.small { min-height: 34px; height: 34px; padding: 0 .6rem; font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: .45rem; }
input:not([type]), input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: .55rem .7rem; min-height: 42px; height: 42px;
}
textarea { height: auto; min-height: 90px; resize: vertical; }
.search input { border: 0; background: transparent; height: auto; min-height: 0; padding: .55rem .15rem; width: 100%; border-radius: 0; }
.filters { display: flex; flex-wrap: wrap; gap: .7rem; margin-bottom: .9rem; align-items: flex-end; }
.filters > div { min-width: 200px; flex: 1 1 220px; max-width: 320px; display: flex; flex-direction: column; }
.filters > .filter-actions { flex: 0 0 auto; min-width: 0; max-width: none; }
.filters .filter-spacer {
  display: block;
  visibility: hidden;
  font-weight: 700;
  font-size: .82rem;
  line-height: 1.2;
  margin-bottom: .3rem;
}
.filter-bar .filter-spacer {
  font-size: .72rem;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.filters input,
.filters select,
.filters .btn {
  box-sizing: border-box;
  width: 100%;
  height: 40px !important;
  min-height: 40px !important;
  max-height: 40px !important;
  padding: 0 .75rem !important;
  line-height: 38px;
  border-radius: 10px;
  font-size: .95rem;
}
.filters .btn {
  width: auto;
  flex: 0 0 auto;
  padding: 0 1.1rem !important;
  white-space: nowrap;
}
.filter-bar { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem .95rem; box-shadow: var(--shadow); }
.filter-bar label { font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
label { display: block; font-weight: 700; font-size: .82rem; margin-bottom: .3rem; }
.field { margin-bottom: .85rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .8rem; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: .12rem .5rem; font-size: .75rem; font-weight: 800; background: var(--blue-soft); color: var(--blue); }
.badge-paid, .badge-approved, .badge-active, .badge-issued.ok { background: var(--green-soft); color: var(--green); }
.badge-issued, .badge-sent, .badge-converted, .badge-viewed { background: var(--blue-soft); color: var(--blue); }
.badge-part_paid, .badge-expired { background: var(--amber-soft); color: var(--amber); }
.badge-overdue, .badge-rejected, .badge-inactive, .badge-failed { background: var(--red-soft); color: var(--red); }
.badge-draft, .badge-cancelled, .badge-void, .badge-blocked { background: #eef1f6; color: var(--muted); }
.badge-credit, .badge-product { background: var(--purple-soft); color: var(--purple); }
.flash { border-radius: 12px; padding: .7rem .85rem; margin-bottom: .8rem; }
.flash.ok { background: var(--green-soft); color: #146b3a; }
.flash.err { background: var(--red-soft); color: #8d2424; }
.error { color: var(--red); font-size: .82rem; margin-top: .25rem; }
.empty { padding: 1.4rem .4rem; color: var(--muted); }
.totals { margin-left: auto; width: min(320px, 100%); }
.totals div { display: flex; justify-content: space-between; gap: 1rem; padding: .28rem 0; }
.totals .grand { font-size: 1.15rem; font-weight: 800; border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .45rem; }
.quick-item { display: flex; flex-wrap: wrap; gap: .7rem; align-items: end; margin: 0 0 .9rem; padding: .8rem; border: 1px dashed var(--line); border-radius: 12px; background: #f8fafc; }
.quick-item > div { min-width: 160px; flex: 1; }
.quick-item .filter-actions { flex: 0 0 auto; min-width: 0; }
.quick-item .btn { flex: 0 0 auto; height: 40px; min-height: 40px; max-height: 40px; padding: 0 1rem; }
.quick-item .error { flex-basis: 100%; }
.quick-item-title { flex-basis: 100%; margin: 0; font-weight: 700; color: var(--text); }
.currency-list { display: grid; gap: .45rem; margin: .8rem 0 1rem; }
.currency-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }
.currency-row form { margin-left: auto; }
.currency-add { margin-top: .4rem; }
.item-row { display: grid; grid-template-columns: 1.4fr 1.6fr .6fr .7fr .6fr .6fr auto; gap: .4rem; margin-bottom: .45rem; align-items: center; }
.item-row.invoice, .item-head { grid-template-columns: 1.15fr .95fr .8fr 1.2fr .55fr .65fr .55fr .5fr auto auto; }
.item-head { display: grid; gap: .4rem; margin-bottom: .2rem; color: var(--muted); font-size: .75rem; font-weight: 700; }
td.detail { min-width: 12rem; }
.overlay { display: none; }
.pager { display: flex; gap: .7rem; align-items: center; margin-top: .8rem; }
.pager .disabled { color: var(--muted); }
.login-shell { min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr; }
.login-side { background: var(--sidebar); color: #fff; display: flex; flex-direction: column; justify-content: center; padding: 3rem; }
.login-side img { width: 220px; }
.login-main { display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: min(420px, 100%); }
.choice-set { border: 1px solid var(--line); border-radius: 12px; padding: .7rem .9rem .85rem; margin: 0 0 .9rem; }
.choice-set legend { font-weight: 800; padding: 0 .3rem; }
.choice-set .check { display: inline-flex; margin-right: 1.2rem; }
.check { display: flex; gap: .45rem; align-items: center; font-weight: 600; }
.check input { width: auto; min-height: 0; }
.sensitive { color: var(--red); font-size: .75rem; font-weight: 700; }
@media (max-width: 1366px) {
  .cards { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; transform: translateX(-110%); width: 260px; transition: transform .18s ease; }
  .app.nav-open .sidebar { transform: none; }
  .overlay { position: fixed; inset: 0; background: rgba(8, 12, 28, .45); z-index: 20; }
  .app.nav-open .overlay { display: block; }
  .menu-btn { display: inline-flex; }
  .split, .login-shell { grid-template-columns: 1fr; }
  .login-side { display: none; }
  .cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .page { padding: .85rem; }
  .grid-2, .grid-3, .item-row, .item-row.invoice { grid-template-columns: 1fr; }
  .item-head { display: none; }
  .profile summary span.name { display: none; }
  .cards { grid-template-columns: 1fr; }
  .topbar { padding: .7rem; }
}
@media (max-width: 390px) {
  .btn { width: 100%; }
  .actions .btn { width: auto; }
  .page-head .btn { width: auto; }
}
