:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --panel: #fbfcfc;
  --ink: #172326;
  --muted: #6a767a;
  --faint: #97a3a7;
  --border: #dce4e6;
  --border-strong: #c7d2d6;
  --accent: #1b7f79;
  --accent-strong: #126760;
  --accent-soft: #dff3ef;
  --amber: #c77b16;
  --amber-soft: #fff3dd;
  --green: #2f8a4f;
  --green-soft: #e6f5ea;
  --red: #b94646;
  --red-soft: #fdeaea;
  --shadow: 0 18px 48px rgba(25, 46, 51, 0.12);
  --shadow-soft: 0 8px 24px rgba(25, 46, 51, 0.08);
  --radius: 8px;
  --radius-sm: 6px;
  --rail: 64px;
  --list: 286px;
  --inspector: 280px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(223, 243, 239, 0.45), transparent 280px),
    var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--rail) var(--list) minmax(520px, 1fr) var(--inspector);
  grid-template-rows: 64px minmax(0, 1fr) 88px;
  min-height: 100vh;
  position: relative;
}

.icon-rail {
  grid-row: 1 / 4;
  background: #102426;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 10px;
  gap: 18px;
  color: #d8f1ee;
}

.icon-rail nav,
.rail-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rail-footer {
  margin-top: auto;
}

.rail-menu,
.rail-button,
.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  position: relative;
}

.rail-menu span {
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.rail-button {
  color: #b3cbc8;
}

.rail-button:hover,
.rail-button.active {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.rail-button::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 48px;
  top: 50%;
  transform: translateY(-50%);
  background: #102426;
  color: #fff;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 140ms ease;
  box-shadow: var(--shadow-soft);
  z-index: 20;
}

.rail-button:hover::after {
  opacity: 1;
}

.topbar {
  grid-column: 2 / 5;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 0 18px 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand,
.toolbar,
.account,
.search-row,
.tabs,
.line-actions,
.list-pagination,
.preview-chip {
  display: flex;
  align-items: center;
}

.brand {
  gap: 8px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
}

.brand strong {
  font-size: 16px;
  font-weight: 760;
}

.brand span {
  color: var(--muted);
  font-size: 14px;
}

.toolbar {
  gap: 8px;
  justify-content: center;
}

.account {
  gap: 8px;
  justify-content: flex-end;
}

.button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  background: transparent;
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
}

.button.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 6px 14px rgba(27, 127, 121, 0.22);
}

.button.primary:hover {
  background: var(--accent-strong);
}

.button.secondary {
  border-color: var(--border-strong);
  background: #fff;
}

.button.ghost:hover,
.button.secondary:hover,
.icon-button:hover {
  background: #eef4f4;
}

.button.small {
  min-height: 34px;
  font-size: 13px;
  padding: 0 11px;
}

.icon-button {
  color: var(--muted);
}

.icon-button.bordered {
  border: 1px solid var(--border);
  background: #fff;
}

.profile {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 0 10px 0 6px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 640;
}

.profile span {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.profile svg {
  width: 14px;
}

.invoice-list,
.inspector {
  background: var(--panel);
  border-right: 1px solid var(--border);
  min-height: 0;
  overflow: auto;
}

.invoice-list {
  grid-column: 2;
  grid-row: 2 / 4;
  padding: 16px 14px;
}

.search-row {
  gap: 8px;
  margin-bottom: 14px;
}

.search {
  flex: 1;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 0 10px;
  color: var(--muted);
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 14px;
}

.tabs {
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 2px;
  margin-bottom: 12px;
}

.tab {
  min-height: 30px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding: 0 9px;
}

.tab.active,
.tab:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

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

.invoice-card {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
  display: grid;
  gap: 8px;
  color: var(--ink);
}

.invoice-card:hover,
.invoice-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(27, 127, 121, 0.08);
}

.card-top,
.card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.invoice-card strong {
  font-size: 14px;
}

.invoice-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.status {
  min-width: 58px;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
}

.status.draft {
  background: var(--amber-soft);
  color: var(--amber);
}

.status.sent {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status.paid {
  background: var(--green-soft);
  color: var(--green);
}

.status.overdue {
  background: var(--red-soft);
  color: var(--red);
}

.amount {
  font-weight: 800;
  color: var(--ink);
}

.list-pagination {
  justify-content: space-between;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.list-pagination button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm);
  color: var(--muted);
}

.workspace {
  grid-column: 3;
  grid-row: 2;
  min-height: 0;
  overflow: auto;
  padding: 22px;
}

.invoice-document {
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.document-head {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

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

h1 {
  margin-bottom: 0;
  font-size: 44px;
  line-height: 1;
  letter-spacing: 0;
  font-weight: 780;
}

h2 {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.document-fields {
  display: grid;
  grid-template-columns: 156px 154px;
  gap: 12px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  min-height: 38px;
  padding: 9px 10px;
  outline: 0;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(27, 127, 121, 0.14);
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.party-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 36px;
  padding: 28px 0;
}

.party-grid strong {
  display: block;
  margin-bottom: 8px;
  font-size: 16px;
}

.party-grid p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 12px;
}

.inline-icon {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  margin-left: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--muted);
  vertical-align: middle;
}

.line-items {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 18px 0;
}

.line-header,
.line-row {
  display: grid;
  grid-template-columns: 28px minmax(150px, 1fr) 64px 92px 74px 66px 88px 30px;
  gap: 8px;
  align-items: center;
}

.line-header {
  min-height: 32px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.line-row {
  padding: 8px 0;
}

.line-row span:first-child {
  color: var(--faint);
  font-size: 13px;
  font-weight: 800;
}

.line-row input {
  min-height: 36px;
  padding: 8px;
  font-size: 14px;
}

.line-total {
  text-align: right;
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
}

.remove-line {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
}

.remove-line:hover {
  background: var(--red-soft);
  color: var(--red);
}

.line-actions {
  justify-content: space-between;
  padding-top: 12px;
}

.document-bottom {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) 170px 268px;
  gap: 18px;
  padding-top: 24px;
}

.textarea-label {
  position: relative;
}

.textarea-label span {
  position: absolute;
  right: 10px;
  bottom: 10px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 700;
}

.terms {
  display: grid;
  align-content: start;
  gap: 12px;
}

.terms small,
.inspector small,
.audit {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.terms label span {
  color: var(--faint);
  font-weight: 650;
}

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

.totals div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.totals strong {
  color: var(--ink);
  font-size: 14px;
  text-align: right;
}

.discount-control {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
}

.discount-control input {
  width: 54px;
  min-height: 30px;
  text-align: right;
}

.total-row {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.total-row span,
.total-row strong {
  font-size: 17px;
  color: var(--ink);
  font-weight: 850;
}

.balance {
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 4px;
}

.balance span,
.balance strong {
  color: var(--accent-strong);
  font-size: 17px;
  font-weight: 850;
}

.balance small {
  display: block;
  font-size: 11px;
  font-weight: 750;
}

.inspector {
  grid-column: 4;
  grid-row: 2 / 4;
  border-right: 0;
  border-left: 1px solid var(--border);
  padding: 18px;
  display: grid;
  align-content: start;
  gap: 14px;
}

.payment-methods {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
  display: grid;
  gap: 11px;
  margin: 2px 0 0;
}

.payment-methods legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  padding: 0 4px;
}

.payment-methods label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
}

.payment-methods input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.link-button {
  width: fit-content;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  padding: 0;
  font-size: 13px;
  font-weight: 800;
}

.attachments {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.attachments h2 {
  margin-bottom: 10px;
}

.audit {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 4px;
}

.audit p {
  margin-bottom: 10px;
}

.audit span {
  color: var(--green);
  font-weight: 900;
}

.export-tray {
  grid-column: 3;
  grid-row: 3;
  align-self: center;
  justify-self: center;
  width: min(780px, calc(100% - 56px));
  min-height: 70px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  transition: transform 180ms ease, opacity 180ms ease;
}

.export-tray.hidden {
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
}

.preview-chip {
  gap: 10px;
  margin-right: auto;
}

.preview-chip div {
  display: grid;
  gap: 1px;
}

.preview-chip strong {
  font-size: 14px;
}

.preview-chip span,
.preview-chip small {
  color: var(--muted);
  font-size: 12px;
}

.tray-close {
  margin-left: 2px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100vw - 40px));
  background: #102426;
  color: #ffffff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 650;
  opacity: 0;
  transform: translateY(14px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

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

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 10%, rgba(27, 127, 121, 0.14), transparent 28%),
    rgba(245, 247, 248, 0.94);
  backdrop-filter: blur(10px);
}

.auth-card {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-card h1 {
  font-size: 30px;
}

.auth-card p,
.auth-card small {
  color: var(--muted);
  line-height: 1.5;
}

.auth-error {
  border: 1px solid var(--red);
  background: var(--red-soft);
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.4;
}

.auth-brand {
  margin-bottom: 4px;
}

.admin-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 80;
  width: min(460px, 100vw);
  height: 100vh;
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 18px;
  overflow: auto;
  transform: translateX(104%);
  transition: transform 180ms ease;
}

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

.drawer-head,
.admin-tabs,
.user-row {
  display: flex;
  align-items: center;
}

.drawer-head {
  justify-content: space-between;
  margin-bottom: 14px;
}

.drawer-head h2 {
  margin: 0;
  color: var(--ink);
  font-size: 20px;
  text-transform: none;
}

.admin-tabs {
  gap: 6px;
  margin-bottom: 14px;
}

.admin-section,
.mini-form {
  display: grid;
  gap: 12px;
}

.admin-section.hidden {
  display: none;
}

.admin-section p {
  color: var(--muted);
  line-height: 1.5;
}

.admin-section code {
  display: block;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent-strong);
  font-size: 13px;
  margin-bottom: 8px;
}

.user-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.user-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 3px;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.user-row span {
  color: var(--muted);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: var(--rail) 280px minmax(420px, 1fr);
  }

  .topbar {
    grid-column: 2 / 4;
    grid-template-columns: 190px 1fr;
  }

  .account {
    display: none;
  }

  .inspector {
    grid-column: 3;
    grid-row: 3;
    display: none;
  }

  .export-tray {
    grid-column: 3;
  }

  .document-bottom {
    grid-template-columns: 1fr 260px;
  }

  .terms {
    grid-column: 1;
  }

  .totals {
    grid-column: 2;
    grid-row: 1 / span 2;
  }
}

@media (max-width: 880px) {
  .app-shell {
    display: block;
    min-height: 100vh;
  }

  .icon-rail {
    display: none;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    min-height: 64px;
    padding: 10px 14px;
  }

  .toolbar {
    order: 3;
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .invoice-list,
  .workspace {
    border: 0;
  }

  .invoice-list {
    max-height: 300px;
    padding: 14px;
  }

  .workspace {
    padding: 16px;
  }

  .invoice-document {
    padding: 20px;
  }

  .document-head,
  .party-grid,
  .document-bottom {
    grid-template-columns: 1fr;
    display: grid;
  }

  .terms,
  .totals {
    grid-column: auto;
    grid-row: auto;
  }

  .document-fields {
    grid-template-columns: 1fr;
  }

  .line-header {
    display: none;
  }

  .line-row {
    grid-template-columns: 24px minmax(0, 1fr) minmax(0, 1fr) 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    margin-bottom: 10px;
  }

  .line-row > * {
    min-width: 0;
  }

  .line-row input:nth-of-type(1) {
    grid-column: 2 / 5;
  }

  .line-row input:nth-of-type(2),
  .line-row input:nth-of-type(4) {
    grid-column: 2;
  }

  .line-row input:nth-of-type(3),
  .line-row input:nth-of-type(5) {
    grid-column: 3 / 5;
  }

  .line-total {
    grid-column: 2 / 4;
    text-align: left;
  }

  .remove-line {
    grid-column: 4;
  }

  .inspector {
    display: grid;
    border-left: 0;
    padding: 16px;
  }

  .export-tray {
    position: static;
    width: calc(100% - 24px);
    margin: 12px auto;
    flex-wrap: wrap;
  }
}

@media print {
  .icon-rail,
  .topbar,
  .invoice-list,
  .inspector,
  .export-tray,
  .toast {
    display: none;
  }

  .app-shell {
    display: block;
  }

  .workspace {
    padding: 0;
    overflow: visible;
  }

  .invoice-document {
    max-width: none;
    border: 0;
    box-shadow: none;
    border-radius: 0;
  }
}
