:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1b1f23; --muted: #5f6b7a; --line: #d6dae0;
  --brand: #1f5f8b; --brand-dark: #174a6d; --accent: #e8f1f8; --ok: #2e7d32; --warn: #b26a00; --err: #b3261e;
  --row: #fafbfc; --row-alt: #f1f4f8; --sel: #fff3c4;
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: "Segoe UI", Calibri, Arial, sans-serif; color: var(--ink); background: var(--bg); line-height: 1.35; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .4rem 0; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem 0; }
h3 { font-size: 1rem; margin: 0 0 .3rem 0; }
.muted { color: var(--muted); }
.sub { color: var(--muted); font-size: .92rem; }

/* top bar and menus */
.topbar { display: flex; align-items: center; gap: 1rem; background: var(--brand); color: #fff; padding: 0 .9rem; height: 44px; position: sticky; top: 0; z-index: 50; }
.topbar .brand { color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: .3px; }
.topbar .brand:hover { text-decoration: none; }
.menu { display: flex; flex: 1; gap: .1rem; flex-wrap: nowrap; }
.dd { position: relative; }
.dd-btn { background: transparent; color: #fff; border: 0; padding: .55rem .6rem; font: inherit; cursor: pointer; border-radius: 4px; }
.dd:hover .dd-btn, .dd:focus-within .dd-btn { background: var(--brand-dark); }
.dd-items { display: none; position: absolute; left: 0; top: 100%; min-width: 16rem; background: #fff; border: 1px solid var(--line); box-shadow: 0 6px 18px rgba(0,0,0,.15); border-radius: 0 0 6px 6px; z-index: 60; padding: .3rem 0; }
.dd:hover .dd-items, .dd:focus-within .dd-items { display: block; }
.dd-items a { display: block; padding: .38rem .9rem; color: var(--ink); white-space: nowrap; }
.dd-items a:hover { background: var(--accent); text-decoration: none; }
.who { font-size: .9rem; white-space: nowrap; }
.who a { color: #dbe9f5; margin-left: .6rem; }
.who .uid { font-weight: 600; }

/* page */
.page { padding: 1rem 1.2rem 3rem; max-width: 1500px; margin: 0 auto; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: .8rem; flex-wrap: wrap; }
.toolbar { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: .9rem 1rem; margin-bottom: 1rem; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .7rem; margin: .5rem 0 1rem; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: .7rem .9rem; color: var(--ink); }
.tile:hover { text-decoration: none; border-color: var(--brand); }
.tile .big { font-size: 1.7rem; font-weight: 700; color: var(--brand); }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem; }
.menu-grid ul { margin: 0; padding-left: 1.1rem; }
.kv th { text-align: left; color: var(--muted); font-weight: 500; padding: .15rem .8rem .15rem 0; }
.kv td { padding: .15rem 0; }

/* flash messages */
.flash { padding: .5rem .8rem; border-radius: 5px; margin: 0 0 .7rem; border: 1px solid; background: #eef4fa; border-color: #b9d1e6; }
.flash.ok { background: #e8f5e9; border-color: #a5d6a7; }
.flash.warn { background: #fff6e5; border-color: #ffd28a; }
.flash.error { background: #fdecea; border-color: #f5b5b0; color: var(--err); }

/* buttons */
.btn, button { display: inline-block; font: inherit; padding: .35rem .8rem; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 4px; cursor: pointer; line-height: 1.3; }
.btn:hover, button:hover { background: var(--accent); text-decoration: none; }
.btn.primary, button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover, button.primary:hover { background: var(--brand-dark); }
.btn.danger, button.danger { color: var(--err); border-color: #e2a7a3; }
.btn.small, button.small { padding: .15rem .5rem; font-size: .85rem; }
.actions { margin-top: .8rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .35rem .9rem; align-items: end; }
.form-grid.narrow { max-width: 480px; grid-template-columns: 1fr; }
.form-grid .actions, .form-grid .wide { grid-column: 1 / -1; }
.fld { display: flex; flex-direction: column; gap: .12rem; font-size: .92rem; }
.fld .lbl { color: var(--muted); }
.fld .help { color: var(--muted); font-size: .8rem; }
input[type=text], input[type=search], input[type=password], input[type=number], select, textarea {
  font: inherit; padding: .3rem .4rem; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--ink); min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc3e3; outline-offset: 0; border-color: var(--brand); }
input.upper { text-transform: uppercase; }
input.num, td.num, th.num { text-align: right; }
input.date { width: 7.5rem; }
input[type=search].filter { width: 18rem; }
fieldset { border: 1px solid var(--line); border-radius: 6px; padding: .6rem .9rem; margin: 0 0 .8rem; }
legend { color: var(--muted); padding: 0 .3rem; }
.inline { display: flex; gap: .6rem; flex-wrap: wrap; align-items: end; }

/* tables */
table.grid { border-collapse: collapse; width: 100%; background: var(--panel); font-size: .9rem; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: .25rem .45rem; text-align: left; vertical-align: top; }
table.grid th { background: #e9edf2; font-weight: 600; position: sticky; top: 44px; z-index: 5; white-space: nowrap; }
table.grid tbody tr:nth-child(even) { background: var(--row-alt); }
table.grid tbody tr:hover { background: var(--sel); }
table.grid td.num { font-variant-numeric: tabular-nums; }
table.grid tr.total td { font-weight: 700; background: #eef4fa; }
table.grid.compact th, table.grid.compact td { padding: .12rem .35rem; }
table.sortable th { cursor: pointer; }
table.sortable th.sorted-asc::after { content: " \25B2"; font-size: .7em; }
table.sortable th.sorted-desc::after { content: " \25BC"; font-size: .7em; }
.editgrid input[type=text], .editgrid select { padding: .15rem .3rem; width: 100%; }
.editgrid td { padding: .12rem .25rem; }
.count { color: var(--muted); font-size: .85rem; margin: .3rem 0; }
.badge { display: inline-block; padding: 0 .4rem; border-radius: 3px; background: #e3e8ee; font-size: .8rem; }
.badge.ok { background: #dcedc8; } .badge.warn { background: #ffe0b2; } .badge.err { background: #ffcdd2; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.scroll-x { overflow-x: auto; }
.scroll-x table.grid th { position: static; }
pre.mono { font-family: Consolas, "Courier New", monospace; font-size: .85rem; white-space: pre; background: #fff; border: 1px solid var(--line); padding: .6rem; overflow-x: auto; }

/* login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 1.5rem 2rem; width: 360px; display: flex; flex-direction: column; gap: .6rem; }
.errorbox { max-width: 600px; margin: 2rem auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 1.5rem; }
.errorbox .msg { font-size: 1.05rem; color: var(--err); }

/* print views */
.print-page { background: #fff; padding: 1rem; }
.print-toolbar { display: flex; gap: .6rem; align-items: center; margin-bottom: 1rem; padding: .5rem; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; }
@media print {
  .no-print, .topbar, .print-toolbar { display: none !important; }
  body { background: #fff; }
  .page { padding: 0; max-width: none; }
  table.grid th { position: static; }
  a { color: inherit; }
}
@media (max-width: 900px) {
  .menu { overflow-x: auto; }
  table.grid th { position: static; }
}
