:root {
  color-scheme: light;
  font-family: "Segoe UI", Arial, sans-serif;
  --line: #b8bdc5;
  --ink: #101820;
  --muted: #5e6773;
  --blue: #0078d4;
  --red: #e84b4b;
  --yellow: #fff1bd;
  --green: #daf0dc;
  --violet: #e7ddf7;
  --table-row-height: 36px;
  --table-font-size: 14px;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: #f2f3f5; font-size: 14px; }
button, input, select, textarea { font: inherit; }
button { min-width: 110px; height: 34px; border: 1px solid #c9ced6; border-radius: 4px; background: #fff; cursor: pointer; }
button:hover { border-color: var(--blue); }
input, select, textarea { border: 1px solid #c9ced6; border-radius: 2px; background: #fff; padding: 6px 8px; min-height: 30px; }

.hidden { display: none !important; }
.login { min-height: 100vh; display: grid; place-items: center; background: #151515; }
.login-panel { width: min(420px, calc(100vw - 32px)); background: #fff; padding: 28px; border-radius: 6px; box-shadow: 0 18px 50px #0008; }
.login-logo { width: 100%; max-width: 360px; background: #000; display: block; margin: 0 auto 24px; }
.login form { display: grid; gap: 10px; }
.login button { background: var(--blue); color: #fff; border-color: var(--blue); }
.error { color: #b00020; min-height: 20px; margin: 0; }

.app { min-height: 100vh; padding: 18px 18px 70px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.brand { display: flex; align-items: flex-start; gap: 18px; }
.brand img { width: 380px; max-width: 36vw; background: #000; }
.kpis { display: flex; gap: 18px; flex-wrap: wrap; padding-top: 52px; font-weight: 600; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.actions button.active { background: #eaf4ff; border-color: var(--blue); }
.status-row { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin: 14px 0; }
.filters, .remote, .table-controls { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.filters label { display: flex; align-items: center; gap: 10px; }
.filters input { width: 280px; }
.filters select { width: 190px; }
.table-controls { gap: 12px; }
.table-controls label { display: flex; align-items: center; gap: 8px; }
.table-controls input[type="range"] { width: 110px; padding: 0; min-height: 0; }
.table-controls button { min-width: 96px; }
.remote { font-weight: 600; color: #145da0; }
.light { width: 15px; height: 15px; display: inline-block; border: 1px solid #777; background: #777; }
.light.ok { background: #00b050; }
.light.bad { background: #dc0000; }

.table-wrap { height: calc(100vh - 255px); overflow: auto; border: 1px solid #5f646b; background: #aaa; }
.table-wrap.small { height: calc(100vh - 230px); }
table { width: 100%; border-collapse: collapse; background: #fff; table-layout: auto; font-size: var(--table-font-size); }
th, td {
  border: 1px solid var(--line);
  height: var(--table-row-height);
  min-height: var(--table-row-height);
  padding: 4px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  resize: horizontal;
}
th { position: sticky; top: 0; background: #f8f8f8; z-index: 1; }
tbody tr { cursor: pointer; }
tbody tr.selected { background: #0078d4 !important; color: #fff; }
tbody tr.pending { background: #cfe5fb; }
tbody tr.soon { background: var(--yellow); }
tbody tr.overdue { background: #ffd2d2; }
tbody tr.paid { background: var(--green); }
tbody tr.to-invoice { background: var(--violet); }

.footer-actions, .client-actions { position: fixed; left: 18px; right: 18px; bottom: 18px; display: flex; align-items: center; gap: 14px; }
.footer-actions span { margin-left: 12px; color: var(--muted); }
.footer-actions button:last-child { margin-left: auto; }

.stats-grid { display: grid; grid-template-columns: repeat(5, minmax(140px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat-card { background: #fff; border: 1px solid #d2d6de; border-radius: 6px; padding: 14px; }
.stat-card strong { display: block; font-size: 22px; margin-bottom: 6px; }
.stat-card span { color: var(--muted); }

dialog { border: 0; border-radius: 8px; padding: 0; box-shadow: 0 20px 70px #0006; width: min(920px, calc(100vw - 32px)); }
dialog::backdrop { background: #0006; }
.dialog-grid { display: grid; grid-template-columns: 1fr 120px 1fr; gap: 14px 18px; padding: 22px; background: #f1f1f1; }
.dialog-grid h2, .dialog-grid menu, .dialog-grid .wide, .attachments { grid-column: 1 / -1; }
.dialog-grid label, .settings-form label { display: grid; gap: 6px; }
.dialog-grid input, .dialog-grid select { width: 100%; }
.dialog-grid menu, .settings-form menu { display: flex; justify-content: flex-end; gap: 12px; margin: 8px 0 0; padding: 0; }
.client-dialog { grid-template-columns: 1fr 140px; }
.settings-form { display: grid; gap: 14px; padding: 22px; background: #f1f1f1; }
.settings-form textarea { width: 100%; resize: vertical; }
.attachments { margin: -6px 0 0; padding-left: 18px; color: var(--muted); }

@media (max-width: 900px) {
  .topbar, .status-row, .brand { display: block; }
  .brand img { max-width: 100%; width: 330px; }
  .kpis { padding-top: 12px; }
  .actions, .filters, .remote { margin-top: 12px; justify-content: flex-start; }
  .table-wrap { height: 58vh; }
  .dialog-grid, .client-dialog { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
