:root {
  --paper: #f7f6ef;
  --paper-soft: #fffdf7;
  --ink: #1b120d;
  --muted: #786b5c;
  --espresso: #120906;
  --coffee: #2d1710;
  --copper: #b77c49;
  --gold: #d7bd8e;
  --olive: #667248;
  --teal: #2f6f72;
  --blue: #3a5876;
  --red: #a34c3f;
  --line: rgba(45, 23, 16, 0.13);
  --line-strong: rgba(45, 23, 16, 0.22);
  --shadow: 0 22px 54px rgba(27, 18, 13, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(45, 23, 16, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, #fbfaf4 0%, #efeee6 100%);
  background-size: 88px 88px, auto;
  color: var(--ink);
  font-family: "Manrope", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 74px;
  border-bottom: 1px solid rgba(215, 189, 142, 0.18);
  padding: 12px clamp(16px, 4vw, 44px);
  background: rgba(18, 9, 6, 0.92);
  color: #fffaf0;
  box-shadow: 0 18px 44px rgba(18, 9, 6, 0.24);
  backdrop-filter: blur(18px);
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  font-weight: 900;
}

.brand-link img {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 999px;
  object-fit: contain;
}

.brand-link span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions,
.head-actions,
.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.quiet-link,
.tool-button,
.primary-action,
.secondary-action,
.danger-action,
.edit-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  font-size: 0.84rem;
  font-weight: 900;
  line-height: 1.1;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.quiet-link,
.tool-button {
  border-color: rgba(215, 189, 142, 0.2);
  background: rgba(255, 250, 240, 0.07);
  color: rgba(255, 250, 240, 0.86);
}

.current-user {
  color: rgba(255, 250, 240, 0.68);
  font-size: 0.84rem;
  font-weight: 800;
}

.tool-button span {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: rgba(215, 189, 142, 0.16);
  color: var(--gold);
  font-size: 0.68rem;
  letter-spacing: 0;
}

.primary-action {
  background: linear-gradient(135deg, var(--copper), var(--gold));
  color: var(--espresso);
  box-shadow: 0 14px 30px rgba(183, 124, 73, 0.22);
}

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

.danger-action {
  min-height: 34px;
  border-color: rgba(163, 76, 63, 0.22);
  background: rgba(163, 76, 63, 0.08);
  color: var(--red);
  font-size: 0.76rem;
}

.edit-action {
  min-height: 34px;
  margin-right: 6px;
  border-color: var(--line-strong);
  background: var(--paper-soft);
  color: var(--coffee);
  font-size: 0.76rem;
}

.quiet-link:hover,
.tool-button:hover,
.primary-action:hover,
.secondary-action:hover,
.danger-action:hover,
.edit-action:hover {
  transform: translateY(-1px);
}

.app-layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: calc(100vh - 74px);
}

.sidebar {
  position: sticky;
  top: 74px;
  align-self: start;
  display: grid;
  gap: 8px;
  height: calc(100vh - 74px);
  border-right: 1px solid var(--line);
  padding: 22px 14px;
  background: rgba(255, 253, 247, 0.64);
  backdrop-filter: blur(10px);
}

.nav-tab {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 900;
  text-align: left;
}

.nav-tab:hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.55);
  color: var(--coffee);
}

.nav-tab.is-active {
  border-color: rgba(183, 124, 73, 0.28);
  background: linear-gradient(135deg, rgba(183, 124, 73, 0.18), rgba(102, 114, 72, 0.12));
  color: var(--coffee);
  box-shadow: 0 12px 28px rgba(45, 23, 16, 0.08);
}

.workspace {
  min-width: 0;
  padding: clamp(20px, 4vw, 44px);
}

.view {
  display: none;
}

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

.workspace-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

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

h1,
h2,
h3 {
  letter-spacing: 0;
}

h1 {
  color: var(--coffee);
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(2.65rem, 6vw, 5rem);
  font-weight: 700;
  line-height: 0.95;
}

h2 {
  color: var(--coffee);
  font-size: 1.05rem;
  font-weight: 900;
}

h3 {
  color: var(--coffee);
  font-size: 1rem;
  font-weight: 900;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
}

.finance-summary {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
}

.metric-card {
  display: grid;
  gap: 12px;
  min-height: 136px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.76), rgba(255, 253, 247, 0.56)),
    var(--paper-soft);
  box-shadow: 0 14px 32px rgba(27, 18, 13, 0.07);
}

.metric-card strong {
  color: var(--coffee);
  font-size: clamp(1.42rem, 2.6vw, 2.25rem);
  font-weight: 900;
  line-height: 1;
  word-break: break-word;
}

.metric-card span {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric-card small {
  color: rgba(120, 107, 92, 0.9);
  font-size: 0.78rem;
  font-weight: 800;
}

.metric-card.accent-cash {
  border-color: rgba(47, 111, 114, 0.24);
  background: linear-gradient(135deg, rgba(47, 111, 114, 0.12), rgba(255, 253, 247, 0.72));
}

.metric-card.accent-stock {
  border-color: rgba(102, 114, 72, 0.28);
  background: linear-gradient(135deg, rgba(102, 114, 72, 0.13), rgba(255, 253, 247, 0.72));
}

.metric-card.accent-receive {
  border-color: rgba(58, 88, 118, 0.24);
  background: linear-gradient(135deg, rgba(58, 88, 118, 0.12), rgba(255, 253, 247, 0.72));
}

.metric-card.accent-pay {
  border-color: rgba(163, 76, 63, 0.22);
  background: linear-gradient(135deg, rgba(163, 76, 63, 0.1), rgba(255, 253, 247, 0.72));
}

.metric-card.accent-profit {
  border-color: rgba(183, 124, 73, 0.26);
  background: linear-gradient(135deg, rgba(183, 124, 73, 0.13), rgba(255, 253, 247, 0.72));
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr);
  gap: 16px;
}

.panel {
  display: grid;
  gap: 16px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(16px, 2vw, 22px);
  background: rgba(255, 253, 247, 0.82);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  white-space: nowrap;
}

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

.stack-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.62);
}

.stack-item strong,
.stack-item span {
  display: block;
}

.stack-item strong {
  color: var(--coffee);
  font-size: 0.92rem;
  font-weight: 900;
}

.stack-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.72rem;
  font-weight: 900;
  white-space: nowrap;
}

.status-ok {
  background: rgba(47, 111, 114, 0.13);
  color: var(--teal);
}

.status-warn {
  background: rgba(183, 124, 73, 0.14);
  color: #8a572d;
}

.status-bad {
  background: rgba(163, 76, 63, 0.13);
  color: var(--red);
}

.role-select {
  width: auto;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 28px 0 12px;
  background-color: rgba(47, 111, 114, 0.13);
  color: var(--teal);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
}

.role-select[data-role="admin"] {
  background-color: rgba(183, 124, 73, 0.16);
  color: #8a572d;
}

.role-select:focus {
  border-color: rgba(47, 111, 114, 0.4);
  box-shadow: 0 0 0 4px rgba(47, 111, 114, 0.1);
}

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

label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 900;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fffef9;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 800;
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

input::placeholder {
  color: rgba(120, 107, 92, 0.58);
}

input:focus,
select:focus {
  border-color: rgba(47, 111, 114, 0.52);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(47, 111, 114, 0.1);
}

.wide-field {
  grid-column: span 2;
}

.file-field {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.file-picker-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  width: 100%;
  margin-top: 22px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--paper-soft);
  color: var(--coffee);
  font-size: 0.84rem;
  font-weight: 900;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease;
}

.file-picker-button:hover {
  border-color: rgba(183, 124, 73, 0.4);
  background: rgba(183, 124, 73, 0.08);
}

.form-actions {
  align-self: end;
  justify-content: flex-end;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

th[data-sort-key] {
  cursor: pointer;
  user-select: none;
}

th[data-sort-key]:hover {
  color: var(--coffee);
}

.sort-indicator {
  display: inline-block;
  margin-left: 4px;
  color: var(--copper);
}

td {
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 800;
}

tbody tr:hover {
  background: rgba(102, 114, 72, 0.06);
}

table.row-select-active tbody tr {
  cursor: pointer;
}

tbody tr.is-selected-for-delete,
table.row-select-active tbody tr.is-selected-for-delete:hover {
  background: rgba(163, 76, 63, 0.14);
}

.edit-action.is-active,
.danger-action.is-active {
  outline: 2px solid currentColor;
  outline-offset: -2px;
}

#clientRowModeHint {
  margin: -6px 0 12px;
}

.numeric {
  text-align: right;
  white-space: nowrap;
}

.muted-text {
  color: var(--muted);
}

.empty-row td {
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  max-width: min(380px, calc(100vw - 36px));
  border: 1px solid rgba(47, 111, 114, 0.22);
  border-radius: 8px;
  padding: 14px 16px;
  background: rgba(18, 9, 6, 0.92);
  color: #fffaf0;
  font-size: 0.86rem;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .summary-grid,
  .finance-summary {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }

  .form-grid {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }
}

@media (max-width: 940px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .quiet-link,
  .tool-button {
    flex: 1 1 120px;
  }

  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    z-index: 12;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    height: auto;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 16px;
  }

  .nav-tab {
    min-width: 132px;
  }

  .workspace-head,
  .split-grid {
    grid-template-columns: 1fr;
  }

  .workspace-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 720px) {
  .summary-grid,
  .finance-summary,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .wide-field {
    grid-column: auto;
  }

  .workspace {
    padding: 18px;
  }

  .head-actions,
  .primary-action,
  .secondary-action {
    width: 100%;
  }

  .panel-head,
  .stack-item {
    align-items: flex-start;
    grid-template-columns: 1fr;
  }

  .panel-head {
    flex-direction: column;
  }

  .panel-chip {
    white-space: normal;
  }
}

@media (max-width: 520px) {
  .brand-link span {
    white-space: normal;
  }

  .tool-button span {
    display: none;
  }

  h1 {
    font-size: 2.55rem;
  }

  .metric-card {
    min-height: 118px;
  }
}

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