:root {
  --bg: #eef3f7; --panel: #ffffff; --ink: #1d2a35; --muted: #66788a; --line: #d9e2ea;
  --brand: #1f5f7a; --brand-ink: #ffffff; --brand-soft: #e3f0f6; --accent: #d64545;
  --row-alt: #f4f9fc; --sel: #fff6d6; --ok: #2f8f5b; --radius: 8px;
  font-family: Roboto, "Segoe UI", Arial, sans-serif; font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
.boot { padding: 40px; color: var(--muted); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #1f5f7a, #0f3445); }
.login form { background: var(--panel); padding: 28px; border-radius: 12px; width: min(360px, 100%); display: grid; gap: 12px; box-shadow: 0 10px 40px #0004; }
.login h1 { margin: 0 0 4px; color: var(--accent); font-size: 26px; }
.login p { margin: 0 0 8px; color: var(--muted); }

/* shell */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side .logo { padding: 14px 16px; font-weight: 700; color: var(--accent); font-size: 20px; border-bottom: 1px solid var(--line); }
.side .logo small { display: block; color: var(--muted); font-size: 11px; font-weight: 400; }
.side .who { padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.side .who b { display: block; }
.side .who span { color: var(--muted); font-size: 12px; }
.side .find { padding: 10px; background: var(--brand-soft); margin: 10px; border-radius: var(--radius); }
.side .find input { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; }
.side .find ul { list-style: none; margin: 6px 0 0; padding: 0; max-height: 260px; overflow: auto; }
.side .find li a { display: block; padding: 4px 6px; text-decoration: none; color: var(--ink); border-radius: 4px; }
.side .find li a:hover { background: #fff; }
.side nav { overflow: auto; flex: 1; padding: 4px 0 12px; }
.side nav a { display: block; padding: 9px 18px; color: var(--ink); text-decoration: none; border-left: 3px solid transparent; }
.side nav a.on, .side nav a:hover { background: var(--brand-soft); border-left-color: var(--brand); }
.side .foot { padding: 8px 16px; color: var(--muted); font-size: 11px; border-top: 1px solid var(--line); }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 18px 0; position: sticky; top: 0; z-index: 5; }
.top .row { display: flex; align-items: center; gap: 10px; }
.top h2 { margin: 0; font-size: 24px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn { border: 0; background: none; font-size: 18px; padding: 4px 8px; border-radius: 6px; color: var(--brand); }
.iconbtn:hover { background: var(--brand-soft); }
.menubar { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 6px; }
.dd { position: relative; }
.dd > button { border: 0; background: none; padding: 8px 10px; border-radius: 6px 6px 0 0; }
.dd > button:hover, .dd.open > button { background: var(--brand-soft); }
.dd > button::after { content: " ▾"; color: var(--muted); }
.dd .menu { display: none; position: absolute; left: 0; top: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 0 6px 6px 6px; min-width: 240px; box-shadow: 0 8px 24px #0002; z-index: 20; max-height: 70vh; overflow: auto; }
.dd.open .menu { display: block; }
.dd .menu a, .dd .menu button { display: block; width: 100%; text-align: left; padding: 8px 14px; color: var(--ink); text-decoration: none; border: 0; background: none; }
.dd .menu a:hover, .dd .menu button:hover { background: var(--brand-soft); }
.dd .menu button:disabled { color: var(--muted); cursor: default; background: none; }
.dd .menu .grp { padding: 6px 14px 2px; font-size: 11px; text-transform: uppercase; color: var(--muted); }

.content { padding: 16px 18px 40px; min-width: 0; }

/* dashboard */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile-btn { background: var(--brand); color: var(--brand-ink); border: 0; border-radius: var(--radius); padding: 14px 10px; text-transform: uppercase; font-weight: 600; letter-spacing: .3px; }
.tile-btn:hover { filter: brightness(1.1); }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.card { background: var(--panel); border-radius: var(--radius); padding: 12px; box-shadow: 0 1px 3px #0001; min-width: 0; }
.card h3 { margin: 0 0 8px; font-size: 14px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.card.wide { grid-column: span 2; }
.card .big { font-size: 34px; font-weight: 700; text-align: center; padding: 18px 0; color: var(--brand); }
.card .empty { text-align: center; color: var(--muted); padding: 30px 0; }
.card .canvas { position: relative; height: 220px; }
.card table { width: 100%; border-collapse: collapse; font-size: 12px; }
.card td, .card th { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; }
.card .tbl { max-height: 260px; overflow: auto; }

/* list screen */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.toolbar .grow { flex: 1; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 18px; padding: 6px 14px; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--accent); }
.search { display: flex; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: #fff; }
.search select { border: 0; border-right: 1px solid var(--line); padding: 6px; max-width: 160px; background: var(--brand-soft); }
.search input { border: 0; padding: 6px 10px; width: 220px; outline: 0; }
.count { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { background: var(--brand-soft); border-radius: 14px; padding: 3px 10px; font-size: 12px; }
.chip button { border: 0; background: none; margin-left: 4px; color: var(--muted); }
.gridwrap { background: var(--panel); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 250px); box-shadow: 0 1px 3px #0001; }
table.grid { border-collapse: collapse; width: 100%; font-size: 12px; }
.grid th { position: sticky; top: 0; background: #f7fafc; text-transform: uppercase; font-size: 11px; color: #33495c; padding: 8px 6px; border-bottom: 2px solid var(--line); white-space: nowrap; cursor: pointer; text-align: left; }
.grid td { padding: 6px; border-bottom: 1px solid var(--line); max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid tbody tr:nth-child(even) { background: var(--row-alt); }
.grid tbody tr:hover { background: var(--brand-soft); }
.grid tbody tr.sel { background: var(--sel); }
.grid td.num { text-align: right; }
.grid tfoot td { font-weight: 700; background: #f7fafc; }
.pager { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px; flex-wrap: wrap; }
.pager select { padding: 3px; }

/* form */
.overlay { position: fixed; inset: 0; background: #0005; display: flex; justify-content: flex-end; z-index: 50; }
.drawer { background: var(--panel); width: min(760px, 100%); height: 100%; display: flex; flex-direction: column; }
.drawer header { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.drawer header h3 { margin: 0; flex: 1; }
.drawer .body { padding: 16px 18px; overflow: auto; flex: 1; }
.drawer footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.drawer.wide { width: min(1280px, 100%); }
.drawer footer .dd .menu { top: auto; bottom: 100%; border-radius: 6px 6px 6px 0; }
.drawer footer .dd > button { border: 1px solid var(--line); border-radius: 18px; padding: 6px 14px; }
.items-title { margin: 20px 0 8px; font-size: 15px; border-top: 1px solid var(--line); padding-top: 14px; }
.items-grid { max-height: 50vh; }
.items-grid td { overflow: visible; max-width: none; }
.items-grid input, .items-grid select { border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px; width: 110px; background: #fff; }
.items-grid .ac input { width: 190px; }
.items-grid input[type=number] { width: 90px; text-align: right; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.field { display: grid; gap: 4px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--muted); }
.field label .req { color: var(--accent); }
.field input, .field select, .field textarea { border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff; width: 100%; }
.field textarea { min-height: 70px; resize: vertical; }
.field .ro { padding: 7px 9px; background: #f4f7fa; border-radius: 6px; min-height: 34px; }
.field .multi { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.ac { position: relative; }
.ac ul { position: absolute; z-index: 60; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); list-style: none; margin: 0; padding: 0; max-height: 220px; overflow: auto; box-shadow: 0 6px 18px #0002; }
.ac li { padding: 6px 9px; cursor: pointer; }
.ac li:hover { background: var(--brand-soft); }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1d2a35; color: #fff; padding: 10px 18px; border-radius: 20px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 99; }
#toast.show { opacity: 1; }
#toast.err { background: var(--accent); }

.menu-toggle { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px #0003; }
  .shell.nav-open .side { transform: none; }
  .menu-toggle { display: inline-block; }
  .card.wide { grid-column: auto; }
  .search input { width: 140px; }
  .content { padding: 12px 16px 40px; }
}
