:root {
  color-scheme: dark;
  --bg: #202528;
  --surface: #2b3135;
  --surface-2: #353d42;
  --surface-3: #252b2f;
  --text: #eef3f2;
  --muted: #aeb9ba;
  --line: #465157;
  --primary: #4aa3ff;
  --primary-2: #91c9ff;
  --danger: #ff8a80;
  --warning: #f1c46b;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(49, 166, 149, 0.16), rgba(241, 196, 107, 0.08)),
    var(--bg);
}

.login-panel {
  width: min(100%, 390px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.brand-mark {
  width: 64px;
  height: 42px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  border-radius: 6px;
  background: var(--primary);
  color: #101719;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 22px;
}

.stack {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--surface-3);
  color: var(--text);
}

input:focus,
select:focus {
  outline: 2px solid rgba(23, 110, 99, 0.25);
  border-color: var(--primary);
}

.primary-button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  padding: 0 18px;
  background: var(--primary);
  color: #101719;
  font-weight: 700;
}

.secondary-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  background: var(--surface-3);
  color: var(--primary-2);
  font-weight: 700;
}

.primary-button:active,
.icon-button:active,
.secondary-button:active,
.nav-item:active {
  transform: translateY(1px);
}

.compact {
  min-height: 42px;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.icon-button.strong {
  color: var(--primary);
  font-weight: 700;
}

.toolbar-button {
  min-width: 78px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: var(--surface-3);
  color: var(--primary-2);
  font-weight: 700;
}

.drawer {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: min(82vw, 310px);
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(-105%);
  transition: transform 160ms ease;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

.drawer nav {
  display: grid;
  padding: 10px;
  gap: 6px;
}

.nav-item {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  text-align: left;
  background: transparent;
  color: var(--text);
}

.nav-item.active {
  background: var(--surface-2);
  color: var(--primary-2);
  font-weight: 700;
}

.nav-item.danger {
  color: var(--danger);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  border: 0;
  background: rgba(4, 7, 9, 0.54);
}

.content {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: 16px;
}

.view {
  display: none;
}

.active-view {
  display: grid;
  gap: 14px;
}

.view-header {
  display: grid;
  grid-template-columns: 78px 1fr 42px;
  align-items: center;
  gap: 12px;
}

.view-header h2 {
  text-align: center;
}

.search-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.status-line {
  min-height: 20px;
  color: var(--muted);
  font-size: 14px;
}

.status-line.error {
  color: var(--danger);
}

.list {
  display: grid;
  gap: 10px;
}

.home-panels {
  display: grid;
  gap: 12px;
}

.home-panel {
  display: grid;
  gap: 8px;
  width: 100%;
  min-height: 126px;
  padding: 18px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
}

.home-panel:active,
.client-item:active {
  background: var(--surface-2);
}

.home-panel span {
  color: var(--primary-2);
  font-size: 14px;
  font-weight: 700;
}

.home-panel strong {
  font-size: 21px;
  overflow-wrap: anywhere;
}

.home-panel small {
  color: var(--muted);
  font-size: 14px;
}

.empty-line {
  padding: 14px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.client-item,
.debt-item,
.selected-client,
.summary-item,
.total-strip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.client-item {
  display: grid;
  gap: 6px;
  width: 100%;
  min-height: 78px;
  padding: 12px;
  text-align: left;
}

.client-item strong,
.debt-item strong,
.summary-item strong {
  overflow-wrap: anywhere;
}

.client-item small,
.selected-client small,
.debt-item small,
.summary-item small {
  color: var(--muted);
}

.summary-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  width: 100%;
  min-height: 82px;
  padding: 12px;
  text-align: left;
}

.summary-item > div {
  display: grid;
  gap: 5px;
}

.summary-action {
  grid-column: 1 / -1;
  justify-self: end;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: var(--surface-3);
  color: var(--primary-2);
  font-weight: 700;
}

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

.summary-amount strong {
  color: var(--primary-2);
  white-space: nowrap;
}

.selected-client {
  display: grid;
  gap: 4px;
  padding: 12px;
}

.selected-client span,
.total-strip span {
  color: var(--muted);
  font-size: 13px;
}

.filters {
  display: grid;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segment {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segment.active {
  background: var(--surface);
  color: var(--primary-2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.total-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
}

.total-strip strong {
  font-size: 22px;
  color: var(--primary-2);
}

.debt-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
}

.debt-item .amount {
  color: var(--primary-2);
  font-weight: 700;
  white-space: nowrap;
}

.debt-item .meta {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

@media (min-width: 760px) {
  .app-shell {
    display: grid;
    grid-template-columns: 250px 1fr;
  }

  .topbar {
    grid-column: 1 / -1;
  }

  #menuButton,
  #closeDrawerButton,
  .drawer-backdrop {
    display: none !important;
  }

  .drawer {
    position: sticky;
    top: 58px;
    z-index: 1;
    width: 250px;
    height: calc(100vh - 58px);
    transform: none;
    box-shadow: none;
  }

  .content {
    width: 100%;
    padding: 22px;
  }
}

@media (max-width: 430px) {
  .search-form,
  .date-row {
    grid-template-columns: 1fr;
  }

  .segmented {
    grid-template-columns: 1fr;
  }

  .debt-item {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .summary-item {
    grid-template-columns: 1fr;
  }

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

  .summary-amount strong {
    display: block;
    margin-bottom: 4px;
  }

  .summary-action {
    width: 100%;
  }
}
