:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --text: #111827;
  --muted: #64748b;
  --border: #dbe2ea;
  --border-strong: #c8d2df;
  --primary: #175cd3;
  --primary-hover: #0f4fbf;
  --primary-soft: #eff6ff;
  --success: #15803d;
  --success-soft: #ecfdf3;
  --warning: #c25d0c;
  --warning-soft: #fff7ed;
  --danger: #c81e1e;
  --danger-soft: #fff1f2;
  --shadow: 0 24px 64px rgba(15, 23, 42, .18), 0 4px 16px rgba(15, 23, 42, .1);
  --radius: 10px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; color: var(--text); background: var(--bg); font-size: 14px; line-height: 1.45; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
svg { display: block; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-header {
  height: 72px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(8px);
}
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; font-size: 24px; font-weight: 750; letter-spacing: -.035em; }
.brand svg { width: 30px; height: 30px; stroke-width: 1.7; }
.user-menu { border: 0; background: transparent; display: flex; align-items: center; gap: 8px; color: var(--text); padding: 9px 10px; border-radius: 8px; font-weight: 600; }
.user-menu:hover { background: var(--surface-soft); }
.user-menu:focus-visible { outline: 3px solid rgba(23, 92, 211, .22); }
.user-menu svg { width: 20px; height: 20px; }
.logout-label { color: var(--muted); font-weight: 500; margin-left: 3px; }

.workspace { width: 100%; padding: 38px 24px 28px; }
.toolbar { display: grid; grid-template-columns: minmax(280px, 1.8fr) minmax(170px, .72fr) minmax(190px, .82fr) auto; gap: 16px; align-items: end; }
.search-field { min-height: 46px; border: 1px solid var(--border-strong); border-radius: var(--radius); display: flex; align-items: center; gap: 10px; padding: 0 14px; background: var(--surface); transition: border-color .18s, box-shadow .18s; }
.search-field:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(23, 92, 211, .12); }
.search-field svg { width: 21px; height: 21px; color: var(--muted); flex: 0 0 auto; }
.search-field input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 15px; }
.search-field input::placeholder { color: #8390a3; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field > span:first-child { color: #334155; font-size: 13px; font-weight: 650; }
.field b { color: var(--danger); }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 11px 12px;
  min-height: 44px;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.field textarea { resize: vertical; min-height: 92px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(23, 92, 211, .12); }
.compact-field select { height: 46px; }
.button { min-height: 44px; border: 1px solid transparent; border-radius: 8px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 680; transition: background .18s, border-color .18s, box-shadow .18s, transform .08s; }
.button:active { transform: translateY(1px); }
.button:focus-visible, .close-button:focus-visible, .row-action:focus-visible { outline: 3px solid rgba(23, 92, 211, .2); outline-offset: 1px; }
.button svg { width: 20px; height: 20px; }
.primary { color: #fff; background: var(--primary); box-shadow: 0 1px 2px rgba(15, 23, 42, .08); }
.primary:hover { background: var(--primary-hover); }
.secondary { color: #253249; background: var(--surface); border-color: var(--border-strong); }
.secondary:hover { background: var(--surface-soft); }
.danger { color: #fff; background: var(--danger); }
.danger:hover { background: #a91616; }
.add-button { min-height: 46px; white-space: nowrap; padding-inline: 20px; }

.summary { min-height: 64px; display: flex; flex-wrap: wrap; align-items: center; gap: 14px; color: #536176; font-size: 13px; font-weight: 550; }
.summary strong { color: #283548; font-weight: 750; }
.summary i { width: 3px; height: 3px; border-radius: 50%; background: #8190a5; }

.table-shell { min-height: 310px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; position: relative; background: var(--surface); }
.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; min-width: 1460px; border-collapse: collapse; table-layout: fixed; }
thead { background: #f8fafc; color: #1e293b; }
th, td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); text-align: left; padding: 12px 12px; vertical-align: middle; }
th:last-child, td:last-child { border-right: 0; }
tbody tr:last-child td { border-bottom: 0; }
th { height: 56px; font-size: 12px; font-weight: 750; line-height: 1.25; white-space: normal; }
th button { appearance: none; border: 0; background: transparent; color: inherit; padding: 0; font: inherit; display: inline-flex; align-items: center; gap: 6px; text-align: left; }
th button:hover { color: var(--primary); }
th button span { color: #74839a; font-size: 14px; }
th:nth-child(1) { width: 150px; } th:nth-child(2) { width: 112px; } th:nth-child(3) { width: 108px; }
th:nth-child(4) { width: 92px; } th:nth-child(5), th:nth-child(6), th:nth-child(7) { width: 112px; }
th:nth-child(8) { width: 260px; } th:nth-child(9) { width: 126px; } th:nth-child(10) { width: 125px; } th:nth-child(11) { width: 82px; }
td { min-height: 62px; font-size: 13px; color: #243043; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: #f8fbff; }
.cell-name { font-weight: 720; color: #172033; overflow-wrap: anywhere; }
.cell-comment { max-width: 260px; color: #455468; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-muted { color: #8290a3; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.date-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }
.date-cell.overdue { color: var(--danger); font-weight: 700; }
.date-cell.expiring { color: var(--warning); font-weight: 700; }
.status { display: inline-flex; align-items: center; min-height: 25px; border-radius: 6px; padding: 3px 8px; font-size: 11px; font-weight: 750; line-height: 1.1; white-space: nowrap; }
.status.paid { color: var(--success); background: var(--success-soft); border: 1px solid #bde8c8; }
.status.unpaid { color: var(--warning); background: var(--warning-soft); border: 1px solid #fed7aa; }
.payment-date { display: block; color: #66758a; margin-top: 4px; font-size: 11px; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.row-action, .close-button { appearance: none; border: 1px solid transparent; border-radius: 7px; background: transparent; color: #435168; display: inline-grid; place-items: center; padding: 0; }
.row-action { width: 33px; height: 33px; }
.row-action:hover { background: var(--primary-soft); color: var(--primary); }
.row-action.delete:hover { background: var(--danger-soft); color: var(--danger); }
.row-action svg { width: 17px; height: 17px; }

.loading { min-height: 310px; display: grid; place-items: center; color: var(--muted); }
.empty-state { min-height: 400px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 32px; }
.empty-state > svg { width: 52px; height: 52px; color: #8fa1b8; margin-bottom: 16px; }
.empty-state h2 { margin: 0 0 8px; font-size: 20px; letter-spacing: -.02em; }
.empty-state p { margin: 0 0 20px; color: var(--muted); }


dialog { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 12px; box-shadow: var(--shadow); color: var(--text); overflow: auto; }
dialog::backdrop { background: rgba(15, 23, 42, .54); backdrop-filter: blur(2px); }
#entryForm { padding: 28px 30px 24px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.dialog-header h2 { margin: 0; font-size: 22px; letter-spacing: -.025em; }
.dialog-header p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.close-button { width: 38px; height: 38px; flex: 0 0 auto; }
.close-button:hover { background: var(--surface-soft); color: var(--text); }
.close-button svg { width: 20px; height: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 20px; }
.field.full { grid-column: 1 / -1; }
.input-suffix { position: relative; display: block; }
.input-suffix input { padding-right: 42px; }
.input-suffix em { position: absolute; right: 13px; top: 50%; transform: translateY(-50%); font-style: normal; color: #4b596b; font-weight: 650; }
.form-error { margin: 18px 0 0; padding: 10px 12px; border-radius: 8px; color: var(--danger); background: var(--danger-soft); border: 1px solid #fecdd3; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }
.dialog-actions .button { min-width: 120px; }
.confirm-dialog { width: min(430px, calc(100vw - 32px)); }
.confirm-content { padding: 30px; text-align: center; }
.confirm-content .danger-icon { width: 48px; height: 48px; margin: 0 auto 15px; border-radius: 50%; background: var(--danger-soft); color: var(--danger); display: grid; place-items: center; }
.danger-icon svg { width: 25px; height: 25px; }
.confirm-content h2 { margin: 0 0 8px; font-size: 21px; }
.confirm-content p { margin: 0; color: var(--muted); }
.confirm-content .dialog-actions { justify-content: center; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 80; min-width: 240px; max-width: min(420px, calc(100vw - 44px)); padding: 13px 16px; border-radius: 9px; color: #fff; background: #172033; box-shadow: 0 12px 30px rgba(15, 23, 42, .22); transform: translateY(20px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

.login-page { min-height: 100vh; display: grid; place-items: center; background: #f5f8fc; padding: 24px; }
.login-shell { width: min(860px, 100%); min-height: 500px; display: grid; grid-template-columns: .95fr 1.05fr; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; box-shadow: 0 24px 70px rgba(35, 52, 78, .12); }
.login-brand { padding: 54px; background: #10223d; color: #fff; display: flex; flex-direction: column; justify-content: center; }
.brand-mark { width: 54px; height: 54px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.24); border-radius: 13px; margin-bottom: 28px; }
.brand-mark svg { width: 31px; height: 31px; }
.login-brand h1 { margin: 0 0 10px; font-size: 34px; letter-spacing: -.045em; }
.login-brand p { margin: 0; color: #c6d4e7; font-size: 16px; max-width: 270px; }
.login-form { padding: 54px; display: flex; flex-direction: column; justify-content: center; gap: 20px; }
.login-form h2 { margin: 0; font-size: 27px; letter-spacing: -.035em; }
.login-form > div p { margin: 7px 0 0; color: var(--muted); }
.login-form .form-error { margin: 0; }
.login-button { width: 100%; margin-top: 2px; }

@media (max-width: 980px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .add-button { justify-self: stretch; }
}

@media (max-width: 680px) {
  body { font-size: 13px; }
  .app-header { height: 62px; padding-inline: 16px; }
  .brand { font-size: 20px; gap: 9px; }
  .brand svg { width: 26px; height: 26px; }
  .logout-label { display: none; }
  .workspace { padding: 22px 14px 18px; }
  .toolbar { grid-template-columns: 1fr; gap: 12px; }
  .search-field { grid-column: auto; }
  .compact-field { display: grid; grid-template-columns: 66px 1fr; align-items: center; gap: 10px; }
  .summary { padding-block: 14px; gap: 8px 10px; line-height: 1.2; }
  .summary i { display: none; }
  .summary span { width: calc(50% - 5px); }
  .table-shell { border: 0; overflow: visible; min-height: 250px; }
  .table-scroll { overflow: visible; }
  table { min-width: 0; display: block; }
  thead { display: none; }
  tbody { display: grid; gap: 10px; }
  tbody tr { display: grid; grid-template-columns: 1fr 1fr; position: relative; border: 1px solid var(--border); border-radius: 10px; padding: 14px; background: #fff; }
  tbody tr:hover { background: #fff; }
  td { min-height: auto; padding: 8px 5px; border: 0; display: flex; flex-direction: column; gap: 3px; }
  td::before { content: attr(data-label); color: #77859a; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .035em; }
  td:nth-child(1), td:nth-child(8), td:last-child { grid-column: 1 / -1; }
  td:nth-child(8) { order: 20; }
  td:last-child { order: 30; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 10px; }
  .cell-name { font-size: 15px; }
  .cell-comment { max-width: none; white-space: normal; }
  .number { text-align: left; }
  .row-actions { justify-content: flex-end; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  #entryForm { padding: 22px 18px 18px; }
  .dialog-actions { position: sticky; bottom: -18px; background: #fff; padding: 14px 0 2px; }
  .dialog-actions .button { flex: 1; min-width: 0; }
  .login-shell { grid-template-columns: 1fr; min-height: auto; }
  .login-brand { padding: 32px; }
  .brand-mark { margin-bottom: 18px; }
  .login-brand h1 { font-size: 28px; }
  .login-form { padding: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
