/* KiraBooks */
:root {
  --brand: #1f6feb;
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #1b2433;
  --ink-2: #4a5568;
  --muted: #7b8798;
  --line: #e3e8ef;
  --side: #0f1b2d;
  --side-ink: #b8c3d6;
  --green: #12805c; --green-bg: #e3f6ee;
  --red: #c4291c; --red-bg: #fde8e6;
  --amber: #a15c00; --amber-bg: #fff3dc;
  --blue: #1f5fbf; --blue-bg: #e5efff;
  --purple: #6b3fc4; --purple-bg: #efe8ff;
  --gray: #5b6575; --gray-bg: #eef1f5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; }
h2 { font-size: 18px; } h3 { font-size: 15px; margin-top: 1.2em; }
code { background: var(--gray-bg); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .center { text-align: center; }
.right, td.num, th.num { text-align: right; }
.nowrap { white-space: nowrap; }
.ico { width: 18px; height: 18px; fill: currentColor; flex: none; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 236px; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 30; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 650; font-size: 15px; }
.brand img { max-height: 32px; max-width: 64px; border-radius: 4px; background: #fff; padding: 2px; }
.sidebar nav { flex: 1; padding: 4px 10px; }
.sidebar nav a, .side-foot a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--side-ink); margin: 1px 0; }
.sidebar nav a:hover, .side-foot a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.nav-sec { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6f7f99; padding: 14px 10px 4px; }
.nav-sep { height: 1px; background: rgba(255,255,255,.08); margin: 10px 8px; }
.side-foot { padding: 10px; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot .who { font-size: 12px; padding: 4px 10px; color: #8a99b2; }
.main { flex: 1; margin-left: 236px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 18px 28px 6px; }
.topbar h1 { font-size: 22px; margin: 0; }
.menu-btn { display: none; background: none; border: 0; padding: 6px; cursor: pointer; color: var(--ink); }
.menu-btn .ico { width: 24px; height: 24px; }
.content { padding: 12px 28px 48px; max-width: 1280px; }
.nav-backdrop { display: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 14px 16px 4px; }
  .content { padding: 10px 16px 40px; }
}

/* Cards & grid */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-h h2, .card-h h3 { margin: 0; }
.grid { display: grid; gap: 18px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px 18px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; }
.span2 { grid-column: span 2; }
@media (max-width: 900px) { .grid4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .grid3 { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .grid2, .grid4 { grid-template-columns: 1fr; } .span2 { grid-column: auto; } }
.cols-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
@media (max-width: 1000px) { .cols-2-1 { grid-template-columns: 1fr; } }

.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.accent { border-top: 3px solid var(--brand); }
.kpi.warn { border-top: 3px solid var(--red); }
.kpi.good { border-top: 3px solid var(--green); }

/* Page actions */
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.page-actions .left, .page-actions .right { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none !important; line-height: 1.3; white-space: nowrap; }
.btn:hover { background: #f7f9fc; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { filter: brightness(.94); background: var(--brand); }
.btn-danger { color: var(--red); border-color: #f2c4bf; }
.btn-danger:hover { background: var(--red-bg); }
.btn-light { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }
.btn-link { background: none; border: 0; color: var(--brand); padding: 0; cursor: pointer; font: inherit; }
.inline { display: inline; }

/* Forms */
label { display: block; font-size: 13px; color: var(--ink-2); font-weight: 550; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid #cfd7e3; border-radius: 8px; font: inherit; color: var(--ink); background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
input[type=checkbox], input[type=radio] { display: inline-block; width: auto; margin: 0 6px 0 0; }
input[type=color] { padding: 2px; height: 38px; }
textarea { min-height: 70px; resize: vertical; }
.form-row { margin-bottom: 12px; }
.check-label { display: flex; align-items: center; font-weight: 500; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 3px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters label { min-width: 150px; }
.filters .btn { margin-bottom: 1px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafbfd; }
.table td.num, .table th.num { font-variant-numeric: tabular-nums; }
.table tfoot td { font-weight: 650; border-top: 2px solid var(--line); }
.row-link { cursor: pointer; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-green { color: var(--green); background: var(--green-bg); }
.badge-red { color: var(--red); background: var(--red-bg); }
.badge-amber { color: var(--amber); background: var(--amber-bg); }
.badge-blue { color: var(--blue); background: var(--blue-bg); }
.badge-purple { color: var(--purple); background: var(--purple-bg); }
.badge-gray { color: var(--gray); background: var(--gray-bg); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.active { color: var(--brand); border-color: var(--brand); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs .count { background: var(--gray-bg); color: var(--gray); border-radius: 999px; padding: 0 7px; font-size: 11.5px; margin-left: 4px; }

/* Alerts */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.alert-success { background: var(--green-bg); color: var(--green); border-color: #bfe8d6; }
.alert-error { background: var(--red-bg); color: var(--red); border-color: #f6c6c0; }
.alert-info { background: var(--blue-bg); color: var(--blue); border-color: #c7dafc; }
.alert-warning { background: var(--amber-bg); color: var(--amber); border-color: #f5ddb0; }

.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.empty p { margin: 0 0 12px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; padding-top: 12px; color: var(--muted); }

/* Document editor */
.lines th { font-size: 12px; color: var(--muted); text-transform: uppercase; text-align: left; padding: 6px 4px; font-weight: 600; }
.lines td { padding: 4px; vertical-align: top; }
.lines input, .lines select, .lines textarea { margin-top: 0; padding: 7px 8px; }
.lines textarea { min-height: 38px; height: 38px; }
.lines .c-item { width: 20%; } .lines .c-desc { width: 26%; } .lines .c-qty { width: 8%; } .lines .c-price { width: 12%; }
.lines .c-disc { width: 7%; } .lines .c-tax { width: 13%; } .lines .c-amt { width: 11%; text-align: right; } .lines .c-x { width: 34px; }
.lines .amt { padding-top: 9px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.line-acc { margin-top: 4px !important; font-size: 12px; color: var(--ink-2); }
.rm-line { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; padding: 4px 6px; line-height: 1; }
.rm-line:hover { color: var(--red); }
.totals { margin-left: auto; width: 320px; max-width: 100%; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 2px solid var(--ink); font-weight: 700; font-size: 16px; margin-top: 6px; padding-top: 9px; }
@media (max-width: 860px) {
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .lines td { padding: 0; width: auto !important; }
  .lines td.c-item, .lines td.c-desc { grid-column: span 2; }
}

/* Document preview */
.doc-paper { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 40px; max-width: 900px; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 28px; flex-wrap: wrap; }
.doc-head img { max-height: 80px; max-width: 220px; }
.doc-title { font-size: 26px; font-weight: 300; letter-spacing: .04em; text-transform: uppercase; color: var(--brand); }
.doc-meta td { padding: 2px 0 2px 16px; }
.doc-meta td:first-child { color: var(--muted); padding-left: 0; }
.doc-items th { background: var(--brand); color: #fff; padding: 9px 10px; font-size: 12px; text-transform: uppercase; text-align: left; }
.doc-items td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.doc-items .num { text-align: right; }
.doc-balance { background: var(--gray-bg); padding: 8px 10px !important; border-radius: 6px; font-weight: 700; }
.pre { white-space: pre-line; }

/* Reports */
.report { max-width: 900px; }
.report table td { padding: 7px 10px; border-bottom: 1px solid #f0f2f6; }
.report .sec td { font-weight: 700; background: #f7f9fc; padding-top: 12px; }
.report .sub td { font-weight: 650; border-top: 1px solid var(--line); }
.report .grand td { font-weight: 750; font-size: 15px; border-top: 2px solid var(--ink); border-bottom: 3px double var(--ink); }
.report .ind td:first-child { padding-left: 28px; }
.report-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.report-list a { display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; color: var(--ink); box-shadow: var(--shadow); }
.report-list a:hover { border-color: var(--brand); text-decoration: none; }
.report-list b { display: block; margin-bottom: 4px; }
.chart-box { position: relative; height: 280px; }
.aging-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--gray-bg); margin: 8px 0 12px; }
.aging-bar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12.5px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* Auth */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; background: linear-gradient(160deg, #0f1b2d 0%, #1d3557 100%); }
.auth-card { background: #fff; padding: 32px; border-radius: 14px; width: 380px; max-width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.auth-card.wide { width: 720px; }
.auth-card label { margin-bottom: 12px; }
.auth-title { font-size: 22px; margin-bottom: 4px; }
.auth-logo { max-height: 60px; max-width: 180px; margin-bottom: 10px; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 13px; margin: 10px 0 16px; }
.check.ok { color: var(--green); } .check.bad { color: var(--red); }

.logo-preview { max-height: 80px; max-width: 240px; border: 1px solid var(--line); border-radius: 6px; padding: 6px; background: #fff; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.stack > * + * { margin-top: 10px; }

@media print {
  .sidebar, .topbar, .page-actions, .no-print, .alert { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; }
  body { background: #fff; }
  .doc-paper, .card { border: 0; box-shadow: none; padding: 0; }
}
