:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --text: #202124;
  --muted: #5f6368;
  --border: #dadce0;
  --primary: #1a73e8;
  --primary-hover: #1765cc;
  --primary-soft: #e8f0fe;
  --on-primary: #ffffff;
  --ok: #188038;
  --err: #d93025;
  --warn: #b06000;
  --shadow: 0 1px 2px rgba(60, 64, 67, .3), 0 2px 6px 2px rgba(60, 64, 67, .15);
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #202124;
    --surface: #292a2d;
    --surface-2: #303134;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --border: #5f6368;
    --primary: #8ab4f8;
    --primary-hover: #aecbfa;
    --primary-soft: #394457;
    --on-primary: #202124;
    --ok: #81c995;
    --err: #f28b82;
    --warn: #fdd663;
    --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 4px 8px 3px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/20px "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; line-height: 16px; }
.strong { font-weight: 600; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.brand { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 500; letter-spacing: -.2px; }
.brand.small { font-size: 18px; gap: 8px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--surface-2); }
.login-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 40px 36px 32px; }
.login-card h1 { font-size: 24px; line-height: 32px; font-weight: 400; margin: 24px 0 4px; }
.login-card .sub { margin: 0 0 28px; color: var(--muted); font-size: 15px; }
.login-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 24px; }

.field { position: relative; margin-bottom: 16px; }
.field input, .field select { width: 100%; height: 52px; padding: 18px 14px 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; outline: none; transition: border-color .15s; appearance: none; }
.field select { padding-right: 34px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 24px, calc(100% - 13px) 24px; background-size: 5px 5px; background-repeat: no-repeat; text-overflow: ellipsis; }
.field input:hover, .field select:hover { border-color: var(--text); }
.field input:focus, .field select:focus { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.field label { position: absolute; left: 14px; top: 16px; color: var(--muted); pointer-events: none; transition: all .15s; font-size: 15px; background: transparent; }
.field input:focus + label, .field input:not(:placeholder-shown) + label, .field select + label, .field input[type=date] + label { top: 6px; font-size: 11px; line-height: 12px; }
.field input:focus + label, .field select:focus + label { color: var(--primary); }
.field input[type=number]::-webkit-inner-spin-button { opacity: .4; }
.field-icon { position: absolute; right: 8px; top: 10px; border: none; background: none; color: var(--muted); padding: 6px; border-radius: 50%; cursor: pointer; }
.field-icon:hover { background: var(--surface-2); }
.field-group { margin-bottom: 16px; }
.combo input { padding-right: 36px; cursor: pointer; }
.combo::after { content: ""; position: absolute; right: 16px; top: 22px; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); pointer-events: none; }
.combo-list { position: fixed; z-index: 30; min-width: 220px; max-height: 320px; overflow-y: auto; background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); padding: 6px 0; }
.combo-item { display: flex; justify-content: space-between; gap: 12px; padding: 9px 16px; cursor: pointer; }
.combo-item.active { background: var(--surface-2); }
.combo-item[aria-selected=true] { color: var(--primary); font-weight: 500; }
.combo-empty { padding: 12px 16px; color: var(--muted); }
.field.invalid input { border-color: var(--err); box-shadow: inset 0 0 0 1px var(--err); }
.field.invalid label { color: var(--err); }
.group-label { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.error-text { color: var(--err); font-size: 13px; min-height: 18px; }

.btn { height: 40px; padding: 0 24px; border-radius: 20px; border: 1px solid transparent; background: none; cursor: pointer; font-weight: 500; letter-spacing: .1px; transition: background .15s, box-shadow .15s; white-space: nowrap; }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); box-shadow: 0 1px 3px rgba(60, 64, 67, .3); }
.btn.outline { border-color: var(--border); color: var(--primary); }
.btn.outline:hover { background: var(--primary-soft); }
.btn.text { color: var(--primary); padding: 0 12px; }
.btn.text:hover { background: var(--primary-soft); }
.btn:disabled { opacity: .45; cursor: default; box-shadow: none; }
.btn.wide { width: 100%; }
.link { color: var(--primary); cursor: pointer; font-weight: 500; }
.link:hover { text-decoration: underline; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; height: 64px; padding: 0 16px 0 20px; background: var(--bg); border-bottom: 1px solid var(--border); }
.spacer { flex: 1; }
.avatar { width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--primary); color: var(--on-primary); font-weight: 600; cursor: pointer; display: grid; place-items: center; flex: none; }
.avatar.big { width: 44px; height: 44px; font-size: 18px; cursor: default; }
.menu { position: absolute; right: 12px; top: 60px; width: 300px; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 20px; }
.menu-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; overflow: hidden; }
.menu-head > div:last-child { min-width: 0; }
.menu-head .muted { overflow: hidden; text-overflow: ellipsis; }
.menu-line { margin-bottom: 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { height: 32px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500; font-size: 13px; color: var(--text); display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { background: var(--surface-2); }
.chip[aria-checked=true] { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.chip[aria-checked=true]::before { content: ""; width: 10px; height: 6px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg) translate(1px, -2px); }

.container { max-width: 1120px; margin: 0 auto; padding: 24px 16px 64px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; margin-bottom: 20px; }
.panel-title { font-size: 16px; font-weight: 500; margin-bottom: 16px; }
.panel .row .panel-title { margin-bottom: 0; }
.grid { display: grid; gap: 0 16px; }
.g2 { grid-template-columns: 2fr 1fr; }
.g3 { grid-template-columns: 2fr 1fr 1.2fr; }
.g4 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.search { flex: 1; min-width: 200px; height: 40px; padding: 0 16px 0 40px; border: 1px solid transparent; border-radius: 20px; background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='18' height='18'%3E%3Cpath fill='%235f6368' d='M15.5 14h-.8l-.3-.3A6.5 6.5 0 1 0 9.5 16a6.5 6.5 0 0 0 4.2-1.6l.3.3v.8l5 5 1.5-1.5-5-5zm-6 0A4.5 4.5 0 1 1 14 9.5 4.5 4.5 0 0 1 9.5 14z'/%3E%3C/svg%3E") no-repeat 14px center; outline: none; }
.search:focus { background-color: var(--surface); border-color: var(--border); box-shadow: 0 1px 3px rgba(60, 64, 67, .2); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tabs button { height: 48px; padding: 0 20px; border: none; background: none; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 3px solid transparent; margin-bottom: -1px; border-radius: 4px 4px 0 0; }
.tabs button:hover { background: var(--surface-2); color: var(--text); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

.list { margin-top: 12px; border: 1px solid var(--border); border-radius: var(--radius); max-height: 280px; overflow-y: auto; outline: none; }
.list:empty { display: none; }
.item { display: flex; align-items: flex-start; gap: 12px; padding: 10px 16px; cursor: pointer; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: none; }
.item:hover { background: var(--surface-2); }
.item[aria-selected=true] { background: var(--primary-soft); }
.item .radio { width: 18px; height: 18px; border: 2px solid var(--muted); border-radius: 50%; flex: none; margin-top: 1px; }
.item[aria-selected=true] .radio { border-color: var(--primary); box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 9px var(--primary); }
.item .t { font-weight: 500; }
.item .id { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; }
.hint { margin-top: 8px; min-height: 16px; }

.actions { display: flex; justify-content: flex-end; align-items: center; gap: 16px; margin-top: 16px; }

.drop { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 36px 16px; border: 2px dashed var(--border); border-radius: 12px; color: var(--muted); transition: all .15s; margin-bottom: 12px; }
.drop > div:first-of-type { color: var(--text); font-size: 15px; }
.drop.over { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

.scroll { overflow-x: auto; margin: 0 -24px; padding: 0 24px; }
table { border-collapse: collapse; width: 100%; min-width: 860px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 500; color: var(--muted); font-size: 12px; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover td { background: var(--surface-2); }
td select { max-width: 300px; height: 32px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); padding: 0 8px; }
td .empty { padding: 32px 0; text-align: center; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.ok { color: var(--ok); }
.err { color: var(--err); }
.warn { color: var(--warn); }
.icon-btn { border: none; background: none; color: var(--muted); width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 16px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.scrim { position: fixed; inset: 0; background: rgba(32, 33, 36, .6); display: grid; place-items: center; padding: 16px; z-index: 20; }
.dialog { background: var(--surface); border-radius: 12px; padding: 24px; width: 100%; max-width: 440px; box-shadow: var(--shadow); }
.dialog h2 { font-size: 20px; font-weight: 400; margin: 0 0 16px; }
.dialog dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.dialog dt { color: var(--muted); }
.dialog dd { margin: 0; }

.snackbar { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #323232; color: #fff; padding: 14px 20px; border-radius: 6px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); z-index: 30; }

@media (max-width: 760px) {
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; row-gap: 10px; }
  .topbar #companies { order: 3; width: 100%; }
  .panel { padding: 16px; }
  .scroll { margin: 0 -16px; padding: 0 16px; }
  .login-card { padding: 32px 20px 24px; }
}

.toolbar { margin-bottom: 4px; }
#listPanel { position: relative; }
.grid-table { min-width: 1040px; }
.grid-table td { padding: 6px 4px; vertical-align: middle; }
.grid-table th { padding: 8px 4px; }
.grid-table th.c-num { text-align: right; }
.c-inv { width: 15%; } .c-city { width: 16%; } .c-tr { width: 10%; } .c-places { width: 6%; } .c-w { width: 10%; } .c-pt { width: 12%; }
.grid-table th { white-space: nowrap; }
.cell, .grid-table td select { width: 100%; height: 36px; padding: 0 10px; border: 1px solid transparent; border-radius: 4px; background: transparent; font: inherit; color: inherit; outline: none; max-width: none; }
.cell:hover, .grid-table td select:hover { border-color: var(--border); }
.cell:focus, .grid-table td select:focus { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); background: var(--surface); }
.cell::placeholder { color: var(--muted); opacity: .7; }
input.cell[type=number] { text-align: right; }
.grid-table td select { appearance: none; cursor: pointer; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 14px) 16px, calc(100% - 9px) 16px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 24px; }
.cell-combo { position: relative; }
.cell-combo .cell { padding-right: 24px; }
.cell.bad, .grid-table td select.bad { border-color: var(--err); background-color: color-mix(in srgb, var(--err) 6%, transparent); }
.grid-table tr.done td { color: var(--muted); }
.grid-table td.ro { padding: 6px 14px; }
.add-row { display: block; width: 100%; margin-top: 8px; padding: 10px; border: 1px dashed var(--border); border-radius: 8px; background: none; color: var(--primary); font: inherit; font-weight: 500; cursor: pointer; }
.add-row:hover { background: var(--primary-soft); border-color: var(--primary); }
.drop-hint { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--primary-soft) 90%, transparent); border: 2px dashed var(--primary); border-radius: var(--radius); color: var(--primary); font-weight: 500; font-size: 16px; z-index: 5; pointer-events: none; }
label.btn { display: inline-flex; align-items: center; }
