:root {
  color-scheme: light;
  --ink: #14212b;
  --muted: #66727c;
  --paper: #f5f7fb;
  --surface: #ffffff;
  --line: #dce3eb;
  --brand: #071224;
  --brand-2: #0a2647;
  --accent: #0f8b8d;
  --danger: #bf3a4a;
  --gold: #b98020;
  --ok: #177245;
  --shadow: 0 18px 40px rgba(12, 24, 38, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 13px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 850;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(15, 139, 141, 0.28);
  outline-offset: 2px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}

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

[hidden] {
  display: none !important;
}

.app-booting .app-frame {
  visibility: hidden;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--brand);
}

.auth-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.auth-brand strong,
.auth-brand small {
  display: block;
}

.auth-brand small {
  margin-top: 2px;
  color: var(--muted);
}

.remember-row {
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
}

.remember-row input {
  width: 18px;
  min-height: 18px;
  margin: 0;
}

.auth-error {
  margin: 0;
  border-left: 3px solid var(--danger);
  padding: 9px 10px;
  background: #fff3f4;
  color: #8f2432;
  font-size: 13px;
  font-weight: 800;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  background: var(--brand);
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: linear-gradient(135deg, #0f8b8d, #2447d8 55%, #bf3a4a);
  font-weight: 950;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.64);
  font-size: 12px;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.side-nav button {
  justify-content: start;
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.84);
  text-align: left;
}

.side-nav button.active {
  border-color: rgba(15, 139, 141, 0.7);
  background: rgba(15, 139, 141, 0.2);
  color: #fff;
}

.license-card {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.06);
}

.license-card span,
.license-card small {
  display: block;
  color: rgba(255, 255, 255, 0.66);
}

.license-card strong {
  display: block;
  margin: 6px 0;
}

.license-card small + small {
  margin-top: 7px;
}

.workspace {
  min-width: 0;
  max-width: 100vw;
  padding: 22px;
  overflow-x: hidden;
}

.topbar,
.panel-head,
.receipt-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  min-height: 72px;
  margin-bottom: 16px;
}

.topbar h1,
.panel h2,
.help-panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(28px, 4vw, 42px);
}

.topbar-actions,
.receipt-toolbar,
.action-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric {
  min-height: 140px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 18px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.metric strong {
  font-size: clamp(24px, 3vw, 34px);
  color: var(--brand-2);
}

.metric small {
  color: var(--muted);
  line-height: 1.4;
}

.panel {
  padding: 18px;
}

.panel + .panel {
  margin-top: 14px;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.secondary {
  border-color: rgba(10, 38, 71, 0.28);
  background: var(--brand-2);
  color: #fff;
}

.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

.ghost {
  background: transparent;
}

.action-grid button {
  flex: 1 1 180px;
  min-height: 64px;
}

.search-box {
  width: min(360px, 100%);
}

.entity-create-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: end;
  gap: 10px;
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.entity-create-form button {
  min-height: 44px;
  white-space: nowrap;
}

.product-create-form {
  grid-template-columns: minmax(220px, 1.4fr) minmax(130px, 0.6fr) minmax(180px, 0.8fr) auto;
}

.entity-list,
.report-list,
.security-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.security-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.cloud-password-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.cloud-password-form > div:first-child,
.cloud-password-form .remember-row,
.cloud-password-actions,
.cloud-password-form .auth-error {
  grid-column: 1 / -1;
}

.cloud-password-form h3 {
  margin: 3px 0 0;
  font-size: 20px;
}

.cloud-password-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#cloudResetMessage:not(.error),
.cloud-password-form .auth-error:not(.error) {
  border-left-color: var(--accent);
  background: #effafa;
  color: var(--accent);
}

.entity-card,
.report-card,
.security-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdff;
}

.entity-card header,
.entity-meta,
.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.entity-card strong {
  font-size: 18px;
}

.entity-meta,
.entity-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.entity-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.entity-actions button {
  min-height: 38px;
}

.account-dialog {
  width: min(980px, calc(100% - 28px));
  max-height: min(820px, calc(100vh - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(4, 14, 28, 0.32);
}

.account-dialog::backdrop {
  background: rgba(7, 18, 36, 0.72);
}

.dialog-shell {
  min-width: 0;
  padding: 20px;
  background: var(--surface);
}

.dialog-head,
.movement-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.dialog-head h2,
.dialog-content h3,
.movement-head h3 {
  margin: 0;
  letter-spacing: 0;
}

.dialog-contact {
  margin: 6px 0 0;
  color: var(--muted);
}

.icon-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  font-size: 28px;
  line-height: 1;
}

.account-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0;
  border-block: 1px solid var(--line);
  padding: 14px 0;
}

.account-summary span {
  color: var(--muted);
  font-weight: 850;
}

.account-summary strong {
  color: var(--brand-2);
  font-size: 28px;
}

.dialog-content {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(250px, 0.72fr) minmax(0, 1.28fr);
  gap: 18px;
  align-items: start;
}

.transaction-form {
  display: grid;
  gap: 12px;
  border-right: 1px solid var(--line);
  padding-right: 18px;
}

.movement-panel {
  min-width: 0;
}

.movement-list {
  max-height: 390px;
  display: grid;
  gap: 8px;
  margin-top: 12px;
  overflow-y: auto;
}

.movement-row {
  min-width: 0;
  display: grid;
  grid-template-columns: 90px minmax(120px, 0.8fr) minmax(110px, auto) minmax(0, 1.2fr);
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 2px;
}

.movement-row span,
.movement-row small {
  min-width: 0;
}

.movement-row small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.movement-row .positive {
  color: var(--danger);
}

.movement-row .negative {
  color: var(--ok);
}

.balance.debt {
  color: var(--danger);
}

.balance.credit,
.ok-text {
  color: var(--ok);
}

.receipt-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 14px;
  align-items: start;
}

.report-filters {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.receipt-form {
  min-width: 0;
  overflow: hidden;
}

.compact-head {
  align-items: start;
}

.status-pill {
  border: 1px solid rgba(15, 139, 141, 0.35);
  border-radius: 999px;
  padding: 7px 10px;
  background: #effafa;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(160px, 0.6fr) minmax(0, 1fr);
  gap: 10px;
  margin: 16px 0;
}

.receipt-toolbar {
  margin-bottom: 12px;
}

.line-table {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.line-row {
  min-width: 860px;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 110px 130px 150px 140px;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding: 8px;
}

.line-row:first-child {
  border-top: 0;
}

.line-head {
  background: #eef3f9;
  color: var(--muted);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.line-row.selected {
  background: #f1fbfb;
}

.line-total {
  font-weight: 950;
  color: var(--brand-2);
}

.receipt-footer {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.receipt-footer span,
.receipt-footer strong {
  display: block;
}

.receipt-footer span {
  color: var(--muted);
  font-weight: 800;
}

.receipt-footer strong {
  font-size: 30px;
}

.help-panel {
  position: sticky;
  top: 18px;
}

.help-panel ul {
  margin: 14px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.7;
}

.product-memory {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.product-memory p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 20;
  max-width: min(520px, calc(100% - 24px));
  transform: translateX(-50%);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.toast.show {
  opacity: 1;
}

.admin-pro-body {
  min-height: 100vh;
  background: #eef3f8;
}

.admin-pro-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.admin-pro-login {
  min-height: calc(100vh - 72px);
}

.admin-pro-header,
.admin-pro-metrics,
.admin-pro-create-form,
.admin-pro-user-list > div,
.admin-pro-license {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-pro-header {
  margin-bottom: 18px;
}

.admin-pro-header h1 {
  margin: 4px 0 0;
}

.admin-pro-metrics {
  align-items: stretch;
  margin-bottom: 14px;
}

.admin-pro-metrics .metric {
  flex: 1 1 0;
}

.admin-pro-create-form {
  align-items: end;
  flex-wrap: wrap;
  margin-top: 16px;
}

.admin-pro-create-form label {
  flex: 1 1 220px;
}

.admin-pro-create-form button {
  min-height: 44px;
}

.admin-pro-list-panel {
  margin-top: 14px;
}

.admin-pro-user-list {
  display: grid;
  gap: 8px;
}

.admin-pro-user-list > div,
.admin-pro-license {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.admin-pro-user-list span,
.admin-pro-license span {
  color: var(--muted);
}

@media (max-width: 720px) {
  .admin-pro-shell { width: min(100% - 24px, 1180px); padding-top: 12px; }
  .admin-pro-header, .admin-pro-metrics, .admin-pro-user-list > div, .admin-pro-license { align-items: stretch; flex-direction: column; }
  .admin-pro-metrics { display: grid; grid-template-columns: 1fr; }
  .admin-pro-create-form { display: grid; grid-template-columns: 1fr; }
  .admin-pro-create-form label { width: 100%; }
}

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

  .sidebar {
    position: relative;
    height: auto;
  }

  .side-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric-grid,
  .receipt-shell,
  .form-grid,
  .report-filters,
  .entity-create-form,
  .cloud-password-form {
    grid-template-columns: 1fr;
  }

  .help-panel {
    position: static;
  }

  .dialog-content {
    grid-template-columns: 1fr;
  }

  .transaction-form {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0 18px;
  }
}

@media (max-width: 560px) {
  .workspace {
    padding: 14px;
  }

  .topbar,
  .panel-head,
  .receipt-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .receipt-toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .side-nav {
    grid-template-columns: 1fr 1fr;
  }

  .panel {
    padding: 14px;
  }

  .entity-card header,
  .entity-meta,
  .status-line,
  .account-summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .account-dialog {
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
  }

  .dialog-shell {
    min-height: 100vh;
    padding: 14px;
  }

  .movement-row {
    grid-template-columns: 82px minmax(0, 1fr) auto;
  }

  .movement-row small {
    grid-column: 1 / -1;
  }
}
