:root {
  color-scheme: dark;
  --bg: #03050a;
  --surface: rgba(12, 17, 27, 0.86);
  --surface-strong: #0c111b;
  --surface-soft: rgba(18, 26, 40, 0.9);
  --ink: #f4f8ff;
  --muted: #8e9bb0;
  --line: rgba(122, 213, 255, 0.16);
  --line-strong: rgba(87, 211, 255, 0.34);
  --sidebar: #05080f;
  --sidebar-soft: rgba(15, 26, 42, 0.92);
  --accent: #28d9ff;
  --accent-dark: #08a8d6;
  --income: #35efaa;
  --expense: #ff5870;
  --transfer: #b99cff;
  --receivable: #49cfff;
  --gold: #f4d06f;
  --focus: #4be4ff;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  --glow: 0 0 24px rgba(40, 217, 255, 0.18);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(3, 6, 12, 0.72), rgba(3, 5, 10, 0.96)),
    linear-gradient(135deg, rgba(40, 217, 255, 0.08), transparent 32%, rgba(53, 239, 170, 0.05) 70%, transparent),
    var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

svg {
  display: block;
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

[hidden] {
  display: none !important;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(440px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand-row,
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: var(--radius);
  color: var(--accent);
  border: 1px solid rgba(40, 217, 255, 0.32);
  background: rgba(40, 217, 255, 0.09);
  box-shadow:
    inset 0 0 18px rgba(40, 217, 255, 0.08),
    0 0 28px rgba(40, 217, 255, 0.18);
}

.brand-mark.small {
  width: 40px;
  height: 40px;
}

.brand-mark svg {
  width: 32px;
  height: 32px;
}

.brand-mark.small svg {
  width: 24px;
  height: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 7vw, 2.45rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.38rem;
  line-height: 1.2;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.auth-form {
  display: grid;
  gap: 14px;
  margin-top: 28px;
}

label,
.field-label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: rgba(3, 7, 13, 0.58);
  outline: none;
  padding: 10px 11px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

select option {
  color: var(--ink);
  background: var(--surface-strong);
}

textarea {
  min-height: 86px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--focus);
  outline: 3px solid rgba(75, 228, 255, 0.16);
  outline-offset: 1px;
}

.primary-action,
.secondary-action,
.ghost-action,
.danger-action,
.icon-button {
  min-height: 42px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 800;
  letter-spacing: 0;
  transition:
    transform 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease;
}

.primary-action {
  color: #021018;
  background: linear-gradient(180deg, #6cecff, var(--accent));
  box-shadow: 0 0 20px rgba(40, 217, 255, 0.22);
}

.primary-action:hover {
  background: linear-gradient(180deg, #8af2ff, var(--accent-dark));
  box-shadow: 0 0 28px rgba(40, 217, 255, 0.3);
}

.secondary-action {
  color: var(--ink);
  border-color: var(--line);
  background: rgba(12, 17, 27, 0.78);
  padding: 0 14px;
}

.secondary-action:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.ghost-action {
  color: var(--ink);
  border-color: transparent;
  background: transparent;
  padding: 0 12px;
}

.ghost-action:hover {
  background: rgba(40, 217, 255, 0.08);
}

.danger-action {
  color: #fff;
  background: var(--expense);
  padding: 0 14px;
}

.danger-action:hover {
  background: #df4058;
}

.icon-button {
  display: grid;
  width: 42px;
  min-width: 42px;
  place-items: center;
  color: var(--ink);
  border-color: var(--line);
  background: rgba(12, 17, 27, 0.78);
  padding: 0;
}

.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.auth-note,
.form-error {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.form-error {
  margin-top: 16px;
  color: var(--expense);
  font-weight: 750;
}

.inline-error {
  margin: 0;
  color: var(--expense);
  font-size: 0.84rem;
  font-weight: 800;
}

.app-shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  min-height: 560px;
  flex-direction: column;
  gap: 22px;
  padding: 22px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(5, 8, 15, 0.98), rgba(5, 8, 15, 0.92)),
    var(--sidebar);
  border-right: 1px solid var(--line);
}

.sidebar .eyebrow {
  color: var(--muted);
}

.sidebar-brand strong {
  display: block;
  font-size: 1.05rem;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: #d7e3f5;
  background: transparent;
  padding: 0 10px;
  text-align: left;
  transition:
    color 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease;
}

.nav-item:hover,
.nav-item.is-active {
  background: var(--sidebar-soft);
}

.nav-item.is-active {
  color: var(--ink);
  border-color: var(--line-strong);
  box-shadow: inset 0 0 22px rgba(40, 217, 255, 0.05), var(--glow);
}

.nav-icon {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 7px;
  color: var(--accent);
  background: rgba(40, 217, 255, 0.1);
  box-shadow: inset 0 0 14px rgba(40, 217, 255, 0.05);
}

.nav-icon svg {
  width: 18px;
  height: 18px;
}

.sidebar-lock {
  margin-top: auto;
  color: var(--ink);
  border-color: var(--line);
}

.sidebar-lock:hover {
  background: rgba(40, 217, 255, 0.08);
}

.workspace {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(3, 6, 12, 0.86);
  padding: 18px 28px;
  backdrop-filter: blur(14px);
}

.period-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

#month-select {
  width: 150px;
}

#year-input {
  width: 104px;
}

.view {
  display: grid;
  gap: 20px;
  padding: 24px 28px 44px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.section-heading p {
  margin: 6px 0 0;
  color: var(--muted);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.stat-card,
.panel,
.entry-form,
.summary-strip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    var(--shadow);
  backdrop-filter: blur(18px);
}

.stat-card {
  min-height: 118px;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  position: absolute;
  inset: auto 14px 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, currentColor, transparent);
  content: "";
  opacity: 0.32;
}

.stat-card p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.stat-card strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(1.25rem, 2.8vw, 1.8rem);
  line-height: 1.08;
}

.stat-card span {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.stat-card.income {
  border-top: 4px solid var(--income);
}

.stat-card.expense {
  border-top: 4px solid var(--expense);
}

.stat-card.balance {
  border-top: 4px solid var(--accent);
}

.stat-card.transfer {
  border-top: 4px solid var(--transfer);
}

.stat-card.receivable {
  border-top: 4px solid var(--receivable);
}

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 16px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.chart-wrap {
  width: 100%;
  min-height: 240px;
}

.chart-wrap svg {
  width: 100%;
  height: 240px;
  overflow: visible;
}

.chart-grid {
  stroke: rgba(142, 155, 176, 0.18);
  stroke-width: 1;
}

.chart-income {
  stroke: var(--income);
  fill: rgba(53, 239, 170, 0.18);
}

.chart-expense {
  stroke: var(--expense);
  fill: rgba(255, 88, 112, 0.18);
}

.axis-label {
  fill: var(--muted);
  font-size: 10px;
  stroke: none;
}

.empty-state {
  display: grid;
  min-height: 150px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--surface-soft);
  padding: 20px;
  text-align: center;
}

.compact-empty {
  min-height: 72px;
  padding: 12px;
}

.category-list,
.recent-list,
.tag-list {
  display: grid;
  gap: 10px;
}

.category-row {
  display: grid;
  gap: 8px;
}

.category-meta,
.recent-item,
.table-actions,
.tag-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.category-meta span,
.recent-item span,
.muted {
  color: var(--muted);
}

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(142, 155, 176, 0.14);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--expense), #ff9aa9);
}

.recent-item {
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.recent-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.kind-pill {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 0.74rem;
  font-weight: 850;
}

.kind-income {
  color: #041711;
  background: rgba(53, 239, 170, 0.82);
}

.kind-expense {
  color: #1e0509;
  background: rgba(255, 88, 112, 0.84);
}

.kind-transfer {
  color: #120a22;
  background: rgba(185, 156, 255, 0.84);
}

.amount-income {
  color: var(--income);
}

.amount-expense {
  color: var(--expense);
}

.amount-transfer {
  color: var(--transfer);
}

.amount-receivable {
  color: var(--receivable);
}

.two-column {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.entry-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
  text-transform: uppercase;
}

td {
  font-size: 0.92rem;
}

tr:last-child td {
  border-bottom: 0;
}

.row-title {
  display: grid;
  gap: 4px;
}

.row-title small {
  color: var(--muted);
}

.mini-action {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: rgba(12, 17, 27, 0.72);
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 800;
}

.mini-action:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 1px;
  overflow: hidden;
}

.summary-strip div {
  padding: 14px;
  background: rgba(12, 17, 27, 0.72);
}

.summary-strip p {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.summary-strip strong {
  overflow-wrap: anywhere;
}

.settings-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.cards-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.85fr) minmax(320px, 1.15fr);
  gap: 16px;
  align-items: start;
}

.compact-form {
  margin-bottom: 16px;
}

.card-list,
.invoice-list {
  display: grid;
  gap: 10px;
}

.credit-card,
.invoice-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 12px;
}

.credit-card span,
.invoice-row span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.invoice-amount {
  text-align: right;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 0.72rem;
  font-weight: 850;
}

.credit-card .status-pill,
.invoice-row .status-pill {
  display: inline-flex;
  margin-top: 6px;
}

.status-pill.is-open {
  color: #04131a;
  background: rgba(73, 207, 255, 0.86);
}

.status-pill.is-paid {
  color: #041711;
  background: rgba(53, 239, 170, 0.86);
}

.status-pill.is-received {
  color: #041711;
  background: rgba(53, 239, 170, 0.86);
}

.status-pill.is-overdue {
  color: #25060c;
  background: rgba(255, 88, 112, 0.9);
}

.invoice-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.invoice-summary-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 14px;
}

.receivable-groups {
  display: grid;
  gap: 12px;
}

.receivable-person-block {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(73, 207, 255, 0.06), transparent),
    var(--surface-soft);
  padding: 14px;
}

.receivable-person-head,
.receivable-item {
  display: grid;
  gap: 12px;
}

.receivable-person-head {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.receivable-person-head span,
.receivable-main span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.receivable-list {
  display: grid;
  gap: 8px;
}

.receivable-item {
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.receivable-main strong {
  overflow-wrap: anywhere;
}

.invoice-summary-head,
.invoice-grand-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.invoice-summary-head span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.invoice-expense-list {
  display: grid;
  gap: 8px;
}

.invoice-expense-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.invoice-expense-row span,
.invoice-expense-row em {
  color: var(--muted);
  font-size: 0.82rem;
  font-style: normal;
}

.invoice-expense-row strong {
  overflow-wrap: anywhere;
}

.invoice-grand-total {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.invoice-grand-total span {
  color: var(--muted);
  font-weight: 850;
}

.tag-item {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 7px 8px 7px 12px;
}

.sync-status {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 12px;
}

.sync-status span {
  color: var(--muted);
  font-size: 0.86rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.64);
  padding: 18px;
  backdrop-filter: blur(10px);
}

.modal {
  width: min(720px, 100%);
  max-height: min(92vh, 760px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 17, 27, 0.94);
  padding: 16px 18px;
}

.modal .entry-form {
  border: 0;
  border-radius: 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  max-width: min(360px, calc(100vw - 36px));
  border-radius: var(--radius);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  background: rgba(12, 17, 27, 0.96);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-weight: 750;
}

.year-bars {
  display: grid;
  gap: 10px;
}

.year-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.dual-bar {
  display: grid;
  gap: 3px;
}

.dual-bar span {
  display: block;
  height: 8px;
  min-width: 2px;
  border-radius: 999px;
}

.dual-bar .income-bar {
  background: linear-gradient(90deg, var(--income), rgba(53, 239, 170, 0.36));
}

.dual-bar .expense-bar {
  background: linear-gradient(90deg, var(--expense), rgba(255, 88, 112, 0.36));
}

@media (max-width: 1120px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .dashboard-layout,
  .two-column,
  .cards-layout,
  .settings-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    z-index: 10;
    height: auto;
    min-height: 0;
    gap: 12px;
    padding: 14px;
  }

  .sidebar-brand {
    justify-content: space-between;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-item {
    min-width: max-content;
  }

  .sidebar-lock {
    display: none;
  }

  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

  .period-controls {
    flex-wrap: wrap;
  }

  #month-select {
    flex: 1 1 150px;
  }

  #year-input {
    flex: 0 0 96px;
  }

  .view {
    padding: 18px 16px 34px;
  }

  .section-heading {
    align-items: start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .auth-panel {
    padding: 20px;
  }

  .brand-row {
    align-items: start;
  }

  .stat-grid,
  .summary-strip,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .period-controls .secondary-action {
    flex: 1 1 100%;
  }

  .panel,
  .entry-form {
    padding: 14px;
  }

  .credit-card,
  .invoice-row,
  .receivable-person-head,
  .receivable-item {
    grid-template-columns: 1fr;
  }

  .invoice-expense-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .invoice-amount {
    text-align: left;
  }
}
