/* Billing window. Uses only tokens from theme.css. Escrowed; theme.css is the customer surface.
   No backdrop-filter anywhere: it renders as a black box in some FiveM NUI builds. */

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: clamp(11px, 1.3vh, 18px); }

body {
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.4;
  color: var(--text-primary);
  background: transparent;
  height: 100vh;
  overflow: hidden;
  user-select: none;
}

.hidden { display: none !important; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--text-muted); font-size: 0.85rem; }

.ico {
  width: 1.15rem; height: 1.15rem;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}

button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { opacity: 0.4; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Window ── */
.scrim {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--bg-overlay);
  animation: fade var(--dur-med) var(--ease);
}
.panel {
  position: relative;
  width: min(60rem, 94vw);
  height: min(40rem, 90vh);
  display: flex; flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  overflow: hidden;
  animation: rise var(--dur-slow) var(--ease);
}
/* background orbs */
.panel::before, .panel::after {
  content: ""; position: absolute; border-radius: 50%; pointer-events: none; filter: blur(100px); opacity: 0.07;
}
.panel::before { width: 28rem; height: 28rem; top: -10rem; right: -8rem; background: var(--accent); }
.panel::after { width: 24rem; height: 24rem; bottom: -10rem; left: -8rem; background: var(--accent-2); }
.panel > * { position: relative; z-index: 1; }

.head {
  display: flex; align-items: center; gap: 1.5rem;
  padding: 1rem 1rem 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.head::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(168, 85, 247, 0.5), transparent);
}
.brand { display: flex; align-items: center; gap: 0.75rem; }
.tile {
  width: 2.4rem; height: 2.4rem; display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--bg-raised); border: 1px solid var(--accent-line);
  color: var(--accent); box-shadow: var(--glow);
}
h1 { font-size: 1.4rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }

.tabs { flex: 1; display: flex; gap: 0.25rem; }
.tab {
  display: flex; align-items: center; gap: 0.45rem;
  height: 2.4rem; padding: 0 0.9rem;
  border-radius: var(--r-md);
  color: var(--text-secondary); font-weight: 600; font-size: 0.95rem;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.tab:hover { background: var(--bg-raised); color: var(--text-primary); }
.tab.active { background: var(--accent-soft); color: var(--accent-hover); }
.badge {
  min-width: 1.3rem; height: 1.3rem; padding: 0 0.35rem;
  display: inline-grid; place-items: center;
  border-radius: 999px; background: var(--accent-strong); color: var(--on-accent);
  font-size: 0.72rem; font-weight: 700;
}
.icon-btn {
  width: 2.4rem; height: 2.4rem; display: grid; place-items: center;
  border-radius: var(--r-md); color: var(--text-secondary);
}
.icon-btn:hover { background: var(--bg-raised); color: var(--text-primary); }

.view { flex: 1; min-height: 0; }
.split { display: grid; grid-template-columns: 22rem 1fr; min-height: 0; height: 100%; }
#view-sent { display: flex; flex-direction: column; }
#view-sent .split { flex: 1; height: auto; }

/* ── Lists ── */
.list { overflow-y: auto; padding: 0.75rem; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.4rem; }
.list::-webkit-scrollbar, .detail::-webkit-scrollbar, .lines::-webkit-scrollbar, .col::-webkit-scrollbar { width: 6px; }
.list::-webkit-scrollbar-thumb, .detail::-webkit-scrollbar-thumb, .lines::-webkit-scrollbar-thumb, .col::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.row {
  display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 0.75rem;
  padding: 0.7rem 0.8rem;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  border-left: 2px solid transparent;
  text-align: left;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.row:hover { background: var(--bg-hover); }
.row.selected { background: var(--accent-soft); border-left-color: var(--accent); }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-amount { font-family: var(--font-mono); font-weight: 600; text-align: right; }
.row-meta { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text-muted); }
.row-meta .mono { font-size: 0.78rem; }

.empty { color: var(--text-muted); padding: 2rem 1rem; text-align: center; font-size: 0.95rem; }

/* ── Pills ── */
.pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  height: 1.45rem; padding: 0 0.6rem;
  border-radius: 999px;
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft); border: 1px solid var(--accent-line);
  white-space: nowrap;
}
.pill.unpaid { color: var(--warning); background: var(--warning-soft); border-color: rgba(251, 191, 36, 0.25); }
.pill.overdue { color: var(--danger); background: var(--danger-soft); border-color: rgba(248, 113, 113, 0.25); }
.pill.paid { color: var(--success); background: var(--success-soft); border-color: rgba(34, 197, 94, 0.25); }
.pill.declined, .pill.cancelled { color: var(--text-muted); background: var(--bg-raised); border-color: var(--border); }
.pill.fine { color: var(--info); background: var(--info-soft); border-color: rgba(129, 140, 248, 0.25); }
.pill::before { content: ""; width: 0.38rem; height: 0.38rem; border-radius: 50%; background: currentColor; }
.pill.overdue::before { animation: pulse 1.5s ease-in-out infinite; }

/* ── Detail ── */
.detail { overflow-y: auto; padding: 1.5rem; }
.doc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.doc-title { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
.doc-sub { color: var(--text-secondary); font-size: 0.9rem; margin-top: 0.25rem; }
.doc-pills { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }

.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; margin-bottom: 1.25rem; }
.fact { background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--r-md); padding: 0.6rem 0.8rem; }
.fact span { display: block; font-size: 0.75rem; color: var(--text-muted); }
.fact b { display: block; font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

table.items { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.items th { text-align: left; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); padding: 0 0 0.5rem; border-bottom: 1px solid var(--border); }
table.items td { padding: 0.55rem 0; border-bottom: 1px solid var(--border); }
table.items .num { text-align: right; font-family: var(--font-mono); }
table.items th.num { font-family: var(--font-ui); }
.totals { margin: 0.75rem 0 0 auto; width: 16rem; display: flex; flex-direction: column; gap: 0.3rem; }
.totals div { display: flex; justify-content: space-between; color: var(--text-secondary); font-size: 0.92rem; }
.totals .mono { color: var(--text-primary); }
.totals .fee .mono { color: var(--danger); }
.totals .grand { margin-top: 0.3rem; padding-top: 0.5rem; border-top: 1px solid var(--border-strong); font-size: 1.1rem; color: var(--text-primary); font-weight: 700; }
.note { margin-top: 1.25rem; padding: 0.75rem 0.9rem; border-left: 3px solid var(--accent-line); background: var(--bg-raised); border-radius: var(--r-sm); color: var(--text-secondary); font-size: 0.92rem; white-space: pre-wrap; word-break: break-word; user-select: text; }
.actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.5rem; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  height: 2.4rem; padding: 0 1.1rem;
  border-radius: var(--r-md);
  font-weight: 600; font-size: 0.92rem;
  transition: background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.btn-sm { height: 2rem; padding: 0 0.75rem; font-size: 0.85rem; }
.btn-primary { background: linear-gradient(135deg, var(--accent-strong), var(--accent-dark)); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { box-shadow: 0 0 20px var(--accent-soft); }
.btn-secondary { background: var(--bg-raised); border: 1px solid var(--border); color: var(--text-primary); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); border-color: rgba(168, 85, 247, 0.4); }
.btn-ghost { color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-raised); color: var(--text-primary); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger.confirm { background: var(--danger); color: #1a0505; }
.btn:active:not(:disabled) { transform: translateY(1px); }

/* ── Form ── */
.send { display: grid; grid-template-columns: 1fr 1.35fr; gap: 0; }
.col { padding: 1.25rem; display: flex; flex-direction: column; gap: 1.1rem; overflow-y: auto; min-height: 0; }
.col + .col { border-left: 1px solid var(--border); }
.field { display: flex; flex-direction: column; gap: 0.45rem; }
.field-head { display: flex; align-items: center; justify-content: space-between; }
.field-label { font-size: 0.85rem; color: var(--text-secondary); }

select, input[type="text"], input[type="number"], textarea {
  width: 100%; height: 2.4rem; padding: 0 0.75rem;
  background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--r-sm);
  color: var(--text-primary); font-size: 0.92rem; outline: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
select option { background: #14121c; }
textarea { height: auto; padding: 0.6rem 0.75rem; resize: none; line-height: 1.4; }
select:focus, input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="number"] { font-family: var(--font-mono); text-align: right; -moz-appearance: textfield; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
::placeholder { color: var(--text-muted); }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; min-height: 2.4rem; }
.chip {
  display: inline-flex; align-items: center; gap: 0.5rem;
  height: 2.2rem; padding: 0 0.8rem;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-raised); font-size: 0.88rem; font-weight: 600;
}
.chip small { font-family: var(--font-mono); font-weight: 400; color: var(--text-muted); font-size: 0.78rem; }
.chip:hover { border-color: var(--border-strong); }
.chip.selected { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-hover); }
.chips .empty { padding: 0.4rem 0; text-align: left; font-size: 0.85rem; }

.presets { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.preset {
  display: inline-flex; align-items: center; gap: 0.5rem;
  height: 2rem; padding: 0 0.7rem;
  border-radius: var(--r-sm); border: 1px dashed var(--border-strong);
  font-size: 0.85rem; color: var(--text-secondary);
}
.preset b { font-family: var(--font-mono); font-weight: 500; color: var(--text-primary); }
.preset:hover { border-style: solid; border-color: var(--accent); color: var(--text-primary); background: var(--bg-hover); }

.lines-head, .line { display: grid; grid-template-columns: 1fr 4rem 6.5rem 2.2rem; gap: 0.4rem; align-items: center; }
.lines-head { font-size: 0.75rem; color: var(--text-muted); padding: 0 0.1rem; }
.lines-head span:nth-child(2), .lines-head span:nth-child(3) { text-align: right; }
.lines { display: flex; flex-direction: column; gap: 0.4rem; max-height: 14rem; overflow-y: auto; }
.line .icon-btn { width: 2.2rem; height: 2.2rem; }
.line .icon-btn:hover { color: var(--danger); background: var(--danger-soft); }
#add-line { align-self: flex-start; }

.send-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.sum { display: flex; flex-direction: column; }
.sum span { font-size: 0.8rem; color: var(--text-muted); }
.sum b { font-size: 1.5rem; font-weight: 700; }
.sum b.over { color: var(--danger); }
#send-none { grid-column: 1 / -1; }

/* ── Stats ── */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; padding: 1rem 1.25rem 0.25rem; }
.stat { background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--r-md); padding: 0.75rem 1rem; }
.stat span { display: block; font-size: 0.78rem; color: var(--text-muted); }
.stat b { display: block; font-family: var(--font-mono); font-size: 1.25rem; font-weight: 600; margin-top: 0.15rem; }
.stat.warn b { color: var(--danger); }
#view-sent .split { border-top: 1px solid var(--border); margin-top: 0.75rem; }

/* ── Toasts ── */
#toasts { position: fixed; top: 2rem; right: 2rem; display: flex; flex-direction: column; gap: 0.6rem; z-index: 10; }
.toast {
  max-width: 22rem;
  padding: 0.75rem 1rem;
  border-radius: var(--r-md);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  box-shadow: var(--shadow-md);
  font-size: 0.92rem;
  animation: slide var(--dur-med) var(--ease);
}
.toast.error { border-left-color: var(--danger); }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes slide { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
