:root {
  --bg: #d9dee6;
  --panel: #ffffff;
  --ink: #1c2533;
  --muted: #5f6b7d;
  --line: #d5dae2;
  --accent: #1f6fb2;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fa;
  --green: #1d7a3a;
  --green-soft: #dcf3e2;
  --red: #b42318;
  --red-soft: #fde4e1;
  --amber: #a15c07;
  --amber-soft: #fdf0d2;
  --chrome: #eef1f5;
  --chrome-2: #e1e6ed;
  --side: #26354d;
  --side-ink: #d6dceb;
  --radius: 4px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 13px/1.45 "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
kbd { font: 11px ui-monospace, Menlo, monospace; color: var(--muted); margin-left: auto; padding-left: 18px; }

/* Desktop chrome */
.app { display: flex; flex-direction: column; height: 100vh; }
.app.locked { display: none; }
.titlebar { display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 10px; background: linear-gradient(#2d3d58, #1f2c42); color: #e7ecf5; font-size: 12px; flex-shrink: 0; }
.tb-logo { width: 18px; height: 18px; border-radius: 4px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 11px; }
.tb-app { font-weight: 600; }
.tb-sep { opacity: .5; }
.tb-company { font-weight: 600; color: #fff; }
.tb-right { margin-left: auto; opacity: .85; }
.menubar { display: flex; background: var(--chrome); border-bottom: 1px solid #c4cbd6; height: 28px; padding: 0 4px; flex-shrink: 0; position: relative; z-index: 30; }
.menu { position: relative; }
.menu > button { border: none; background: none; font: inherit; padding: 0 11px; height: 27px; cursor: default; color: var(--ink); }
.menu > button:hover, .menu.open > button { background: #cfe0f3; }
.dropdown { display: none; position: absolute; top: 27px; left: 0; min-width: 240px; background: #fff; border: 1px solid #aab4c3; box-shadow: 2px 4px 14px rgba(0,0,0,.18); padding: 3px 0; }
.menu.open .dropdown { display: block; }
.dropdown a { display: flex; padding: 5px 22px; color: var(--ink); white-space: nowrap; }
.dropdown a:hover { background: var(--accent); color: #fff; text-decoration: none; }
.dropdown a:hover kbd { color: #dce8f6; }
.dropdown hr { border: none; border-top: 1px solid var(--line); margin: 3px 0; }
.body { display: flex; flex: 1; min-height: 0; }
.iconbar { width: 196px; flex-shrink: 0; background: var(--side); color: var(--side-ink); overflow-y: auto; padding-bottom: 12px; }
.ib-search { padding: 10px 10px 4px; position: relative; }
.ib-search input { background: #1b273a; border-color: #3b4c69; color: #fff; font-size: 12px; padding: 6px 8px; }
.ib-search input::placeholder { color: #8e9ab3; }
.search-results { position: absolute; left: 10px; right: -260px; top: 42px; background: #fff; border: 1px solid #aab4c3; box-shadow: 2px 4px 14px rgba(0,0,0,.25); z-index: 40; max-height: 380px; overflow-y: auto; }
.search-results a { display: block; padding: 6px 10px; color: var(--ink); border-bottom: 1px solid #f0f2f5; }
.search-results a:hover, .search-results a.sel { background: var(--accent-soft); text-decoration: none; }
.search-results small { color: var(--muted); margin-left: 6px; }
.ib-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #8e9ab3; margin: 14px 12px 4px; }
.iconbar a { display: flex; align-items: center; gap: 10px; color: var(--side-ink); padding: 7px 12px; border-left: 3px solid transparent; }
.iconbar a i { font-style: normal; width: 22px; height: 22px; display: grid; place-items: center; background: rgba(255,255,255,.08); border-radius: 4px; font-size: 13px; }
.iconbar a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.iconbar a.active { background: rgba(255,255,255,.12); color: #fff; border-left-color: #5aa9ef; font-weight: 600; }
.workspace { flex: 1; min-width: 0; overflow: auto; padding: 12px; }
.window { background: #fff; border: 1px solid #a9b3c2; box-shadow: 0 2px 8px rgba(30,40,60,.15); min-height: calc(100% - 2px); display: flex; flex-direction: column; }
.window-title { display: flex; justify-content: space-between; align-items: center; height: 28px; padding: 0 10px; background: linear-gradient(#f4f6f9, #dfe4eb); border-bottom: 1px solid #b9c2cf; font-weight: 600; font-size: 12px; position: sticky; top: -12px; z-index: 5; }
.window-ctrls a { color: var(--muted); padding: 0 4px; }
.window-ctrls a:hover { color: var(--red); text-decoration: none; }
.view { padding: 18px 22px 40px; flex: 1; }
.statusbar { display: flex; justify-content: space-between; height: 22px; padding: 0 10px; align-items: center; background: var(--chrome); border-top: 1px solid #c4cbd6; font-size: 11.5px; color: var(--muted); flex-shrink: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 19px; font-weight: 600; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* Home workflow */
.home { display: grid; grid-template-columns: 1fr 280px; gap: 16px; }
@media (max-width: 1100px) { .home { grid-template-columns: 1fr; } }
.flow-panel { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 14px; overflow: hidden; }
.flow-panel > h4 { margin: 0; padding: 6px 12px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: #fff; background: linear-gradient(#3a5a86, #2c4770); }
.flow { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; padding: 16px 14px; background: linear-gradient(#fbfcfe, #f2f5f9); }
.flow .arrow { color: #8796ad; font-size: 20px; padding: 0 2px; }
.tile { width: 104px; text-align: center; color: var(--ink); padding: 8px 4px; border-radius: 6px; border: 1px solid transparent; cursor: pointer; background: none; font: inherit; }
.tile:hover { background: #fff; border-color: #b8cbe3; box-shadow: 0 2px 6px rgba(31,111,178,.15); text-decoration: none; }
.tile .ico { width: 46px; height: 46px; margin: 0 auto 6px; border-radius: 10px; display: grid; place-items: center; font-size: 22px; color: #fff; box-shadow: inset 0 -3px 0 rgba(0,0,0,.15); }
.tile span { display: block; font-size: 12px; line-height: 1.25; }
.tile .count { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.ico.blue { background: linear-gradient(#4b93d6, #2b6fae); }
.ico.teal { background: linear-gradient(#36a89b, #1f7f74); }
.ico.orange { background: linear-gradient(#f0a246, #cf7a16); }
.ico.purple { background: linear-gradient(#8f72d6, #6a4cb5); }
.ico.slate { background: linear-gradient(#7d8ba1, #56637a); }
.ico.green { background: linear-gradient(#58b368, #2f8a42); }
.side-box { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 14px; overflow: hidden; }
.side-box h4 { margin: 0; padding: 6px 12px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; background: var(--chrome-2); border-bottom: 1px solid var(--line); }
.side-box .rows a, .side-box .rows div { display: flex; justify-content: space-between; padding: 7px 12px; border-bottom: 1px solid #f0f2f5; color: var(--ink); }
.side-box .rows a:hover { background: var(--accent-soft); text-decoration: none; }
.side-box .tiles { display: flex; flex-wrap: wrap; padding: 8px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #26354d, #1f6fb2); }
.login { background: #fff; width: 360px; border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,.35); overflow: hidden; }
.login-head { background: linear-gradient(#2d3d58, #1f2c42); color: #fff; padding: 18px 22px; display: flex; gap: 10px; align-items: center; font-size: 16px; font-weight: 600; }
.login form { padding: 20px 22px; }
.login .err { color: var(--red); min-height: 18px; margin-bottom: 6px; }

/* Cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: 1.6fr 1fr; }
@media (max-width: 1000px) { .grid.two { grid-template-columns: 1fr; } }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }

/* Buttons & inputs */
.btn { border: 1px solid #b3bccb; background: linear-gradient(#fff, #eef1f5); color: var(--ink); padding: 6px 13px; border-radius: 4px; cursor: pointer; font: inherit; font-weight: 500; }
.btn:hover { border-color: #c5cad8; }
.btn.primary { background: linear-gradient(#2f82c8, #1f6fb2); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.link { border: none; background: none; color: var(--accent); padding: 4px 6px; }
input, select, textarea {
  font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; }
.search { max-width: 260px; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: #fafbfd; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8f9ff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }

.lines td { padding: 5px 6px; }
.lines input, .lines select { padding: 6px 7px; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.paid { background: var(--green-soft); color: var(--green); }
.badge.overdue { background: var(--red-soft); color: var(--red); }
.badge.open, .badge.partial { background: var(--amber-soft); color: var(--amber); }
.badge.draft { background: #eceef3; color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.hidden { display: none !important; }
.right { text-align: right; }

/* Totals box */
.totals { margin-left: auto; width: 300px; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; }
.totals .grand { font-size: 18px; font-weight: 700; border-top: 2px solid var(--line); margin-top: 6px; padding-top: 10px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }

/* Reports */
.report { max-width: 820px; margin: 0 auto; }
.report-title { text-align: center; margin-bottom: 18px; }
.report-title h2 { margin: 0; }
.report-title div { color: var(--muted); }
.report table td { border-bottom: 1px dashed var(--line); }
.report .section td { font-weight: 700; background: #fafbfd; border-bottom: 1px solid var(--line); }
.report .subtotal td { font-weight: 600; border-top: 1px solid var(--ink); }
.report .total td { font-weight: 800; border-top: 2px solid var(--ink); border-bottom: 3px double var(--ink); }
.report .indent { padding-left: 28px; }
.report-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.report-list a.card { color: var(--ink); display: block; }
.report-list a.card:hover { border-color: var(--accent); text-decoration: none; }
.report-list p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

/* Chart */
.chart svg { width: 100%; height: 240px; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.bar-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.bar-row .bar-label { width: 130px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar { flex: 1; height: 10px; background: #eef0f5; border-radius: 6px; overflow: hidden; }
.bar-row .bar span { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.bar-row .bar-val { width: 110px; text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 24, 40, .45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.close-x { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.25); }

/* Invoice document */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 40px; max-width: 860px; }
.doc-head { display: flex; justify-content: space-between; margin-bottom: 30px; }
.doc-head h2 { margin: 0; font-size: 28px; letter-spacing: .05em; color: var(--accent); }
.doc-meta { display: grid; grid-template-columns: auto auto; gap: 2px 14px; text-align: right; }
.doc-meta span:nth-child(odd) { color: var(--muted); }
.doc-to { margin-bottom: 24px; }

@media print {
  .titlebar, .menubar, .iconbar, .statusbar, .window-title, .page-head .actions, .no-print { display: none !important; }
  .app { height: auto; } .workspace { overflow: visible; padding: 0; } .window { border: none; box-shadow: none; }
  body { background: #fff; }
  .view { padding: 0; }
  .doc, .card, .table-wrap { border: none; }
}
