:root {
  --bg: #130f0c;
  --panel: #1d1712;
  --panel-strong: #261d17;
  --ink: #fff7eb;
  --muted: #c9b7a2;
  --line: #3b2d24;
  --soft: #2a2019;
  --green: #4fa076;
  --green-soft: #203a2d;
  --brick: #e26d45;
  --blue: #8bb7d2;
  --gold: #f0b949;
  --cream: #ffe3a3;
  --shadow: 0 18px 44px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }

html { min-height: 100%; overflow-x: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(10, 7, 5, .9) 0%, rgba(10, 7, 5, .82) 42%, rgba(10, 7, 5, .6) 100%),
    linear-gradient(180deg, rgba(240, 185, 73, .13), transparent 38%),
    url("/karlinha-login-bg.png") center / cover fixed no-repeat,
    linear-gradient(180deg, #1a100d, var(--bg));
  font-family: "Segoe UI", Arial, sans-serif;
}

button, input, textarea, select { font: inherit; }

button {
  min-height: 42px;
  padding: 10px 13px;
  border: 1px solid var(--gold);
  border-radius: 8px;
  color: #1b120d;
  background: var(--gold);
  font-weight: 800;
  cursor: pointer;
}

button:hover { filter: brightness(.97); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.secondary { color: var(--ink); background: var(--soft); border-color: var(--line); }
button.ghost { color: var(--ink); background: transparent; border-color: transparent; }
button.compact { width: auto; min-height: 38px; padding-inline: 12px; }
.danger-text { color: #ff9d7c !important; }

input, textarea, select {
  width: 100%;
  min-height: 42px;
  margin-top: 6px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #120d0a;
  outline: none;
}

textarea { resize: vertical; line-height: 1.45; }
label { display: block; margin-top: 14px; color: var(--muted); font-size: 13px; font-weight: 800; }
pre { min-height: 180px; max-height: 65vh; overflow: auto; margin: 10px 0 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #0b0806; color: #fff7eb; white-space: pre-wrap; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.hidden { display: none !important; }
.msg { min-height: 22px; color: var(--muted); }
.field-help { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.toast { position: fixed; right: 16px; top: 16px; z-index: 80; width: min(380px, calc(100vw - 32px)); padding: 13px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); box-shadow: var(--shadow); }

.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; flex: 0 0 44px; border-radius: 8px; color: #1b120d; background: linear-gradient(135deg, var(--gold), var(--brick)); font-weight: 950; font-size: 22px; }
.brand-row h1, .brand-row p, .brand-row strong, .brand-row small { margin: 0; }
.brand-row p, .brand-row small { color: var(--muted); }

.login-shell {
  position: relative;
  min-height: 100vh;
  display: grid;
  align-items: center;
  justify-items: start;
  overflow: hidden;
  padding: clamp(18px, 5vw, 64px);
  background:
    linear-gradient(90deg, rgba(10, 7, 5, .94) 0%, rgba(10, 7, 5, .78) 42%, rgba(10, 7, 5, .28) 70%),
    linear-gradient(180deg, rgba(240, 185, 73, .12), transparent 35%);
}

.login-shell::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 9px;
  background: linear-gradient(90deg, var(--gold), #fff24f, var(--brick));
}

.client-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(120deg, rgba(240, 185, 73, .12), transparent 38%),
    rgba(10, 7, 5, .48);
}

.login-card {
  width: min(500px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(29, 23, 18, .92);
  box-shadow: var(--shadow);
}

.login-card {
  position: relative;
  z-index: 1;
  margin-left: clamp(0px, 4vw, 72px);
  background: rgba(29, 23, 18, .92);
  backdrop-filter: blur(8px);
}

.client-card {
  width: min(940px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(29, 23, 18, .92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.login-card button, .client-card button { width: 100%; margin-top: 10px; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: rgba(16, 11, 9, .94);
}

.sidebar-brand { margin-bottom: 22px; }
.nav-list { display: grid; gap: 7px; }
.nav-item { width: 100%; justify-content: flex-start; color: var(--ink); background: transparent; border-color: transparent; text-align: left; }
.nav-item.active { color: #1a100b; background: var(--gold); border-color: var(--gold); }
#btnSairPainel { width: 100%; margin-top: 24px; text-align: left; }

.main { min-width: 0; padding: 22px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: rgba(29, 23, 18, .92); box-shadow: var(--shadow); }
.topbar h2 { margin: 0 0 3px; }
.topbar span { color: var(--muted); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

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

.metric {
  min-width: 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(29, 23, 18, .92);
  box-shadow: var(--shadow);
}

.metric span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.metric strong { display: block; margin-top: 7px; font-size: clamp(22px, 3vw, 30px); overflow-wrap: anywhere; }
.metric.green strong { color: var(--green); }
.metric.brick strong { color: var(--brick); }
.metric.gold strong { color: var(--gold); }
.metric.blue strong { color: var(--blue); }

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 430px);
  gap: 14px;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(29, 23, 18, .92);
  box-shadow: var(--shadow);
}

.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-head h3 { margin: 3px 0 0; }
.kicker { color: var(--cream); font-size: 11px; font-weight: 900; letter-spacing: .05em; text-transform: uppercase; }

.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.quick-grid button { min-height: 76px; background: var(--soft); color: var(--ink); border-color: var(--line); text-align: left; }

.status-list { display: grid; gap: 8px; margin: 0; }
.status-list div { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--soft); }
.status-list dt { color: var(--muted); font-weight: 800; }
.status-list dd { margin: 0; overflow-wrap: anywhere; }

.clientes-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.client-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 215px);
  overflow: auto;
  margin-top: 12px;
  padding-right: 2px;
}

.client-item {
  width: 100%;
  display: grid;
  gap: 4px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #140f0c;
  text-align: left;
}

.client-item.active { border-color: var(--gold); box-shadow: inset 4px 0 0 var(--gold); }
.client-item strong, .client-item span { overflow-wrap: anywhere; }
.client-item span { color: var(--muted); font-size: 12px; }

.detail-panel { min-height: 420px; }
.empty-state { min-height: 200px; display: grid; place-items: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; text-align: center; padding: 16px; }

.account-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.account-head h3 { margin: 0 0 4px; }
.account-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.account-actions button { width: auto; }

.money-line {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  margin: 12px 0;
}

.money-line div { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); }
.money-line span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; }
.money-line strong { display: block; margin-top: 4px; font-size: 20px; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: 10px; border-bottom: 1px solid var(--soft); text-align: left; vertical-align: top; }
th { color: var(--cream); font-size: 12px; text-transform: uppercase; background: #120d0a; }
tr:last-child td { border-bottom: 0; }
.status-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 800; background: var(--soft); color: var(--ink); }
.status-pill.aberto, .status-pill.pendente { color: #2a1b08; background: #ffd46f; }
.status-pill.confirmado, .status-pill.quitado { color: #bff4d8; background: var(--green-soft); }
.status-pill.cancelado, .status-pill.revisao { color: #ffd0c1; background: #4b1f18; }

.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.button-row button { width: auto; }
.lookup-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; align-items: end; }
.lookup-row button { width: auto; margin-top: 6px; }
.form-row { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px; align-items: end; }

.payment-list { display: grid; gap: 8px; }
.payment-item { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #140f0c; }
.payment-item strong, .payment-item span { display: block; overflow-wrap: anywhere; }
.payment-item small { color: var(--muted); }

.client-account { display: grid; gap: 14px; margin-top: 14px; }
.client-pay-box { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--green-soft); }
.client-pay-box button { width: 100%; }
.first-access { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.first-access h2 { margin: 0 0 4px; font-size: 20px; }
.first-access p { margin: 0 0 8px; color: var(--muted); }

#printArea { display: none; }

@media (max-width: 1050px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-grid, .clientes-layout { grid-template-columns: minmax(0, 1fr); }
  .client-list { max-height: 360px; }
}

@media (max-width: 900px) {
  body { background-attachment: scroll; }

  .app { display: block; }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: rgba(16, 11, 9, .97);
    backdrop-filter: blur(10px);
  }

  .sidebar-brand {
    min-width: 0;
    margin-bottom: 0;
  }

  .sidebar-brand .brand-mark {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
    font-size: 20px;
  }

  .sidebar-brand strong,
  .sidebar-brand small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .nav-list {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .nav-item {
    flex: 0 0 auto;
    width: auto;
    min-height: 38px;
    padding: 8px 11px;
    white-space: nowrap;
    text-align: center;
  }

  #btnSairPainel {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
    justify-self: end;
    width: auto;
    min-height: 38px;
    margin-top: 0;
    padding-inline: 12px;
    text-align: center;
  }

  .main { padding: 14px; }
  .topbar { align-items: flex-start; }
  .topbar h2 { font-size: 24px; }
  .panel { padding: 14px; }
  .account-actions { justify-content: flex-start; }
}

@media (max-width: 760px) {
  .login-shell {
    align-items: end;
    justify-items: center;
    padding: 18px;
    background:
      linear-gradient(180deg, rgba(10, 7, 5, .42), rgba(10, 7, 5, .96) 58%);
  }

  .login-card { margin-left: 0; }
  .main { padding: 12px; }
  .client-shell { align-items: start; padding: 12px; }
  .login-card, .client-card { padding: 18px; }
  .account-head { flex-direction: column; align-items: stretch; }
  .topbar { align-items: center; }
  .topbar > div { min-width: 0; }
  #subtituloAba { display: none; }
  .money-line, .quick-grid, .lookup-row, .form-row { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .metric { padding: 12px; }
  .metric strong { font-size: 21px; }
  .button-row button, .account-actions button, .lookup-row button { width: 100%; }
  .panel-head { flex-direction: column; align-items: stretch; }
  pre { max-height: 50vh; }
}

@media (max-width: 620px) {
  .table-wrap {
    overflow: visible;
    border: 0;
  }

  .table-wrap table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 8px;
  }

  .table-wrap thead { display: none; }
  .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; }

  .table-wrap tr {
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #140f0c;
  }

  .table-wrap td {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 227, 163, .08);
    overflow-wrap: anywhere;
  }

  .table-wrap td:last-child { border-bottom: 0; }

  .table-wrap td::before {
    color: var(--cream);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
  }

  .table-wrap td:nth-child(1)::before { content: "Data"; }
  .table-wrap td:nth-child(2)::before { content: "Item"; }
  .table-wrap td:nth-child(3)::before { content: "Qtd"; }
  .table-wrap td:nth-child(4)::before { content: "Valor"; }
  .table-wrap td:nth-child(5)::before { content: "Status"; }
  .table-wrap td:nth-child(6)::before { content: "ID"; }
}

@media (max-width: 420px) {
  .brand-row { gap: 9px; }
  .status-list div { grid-template-columns: 1fr; }
  .table-wrap td { grid-template-columns: 76px minmax(0, 1fr); }
}

@media print {
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; color: #000; background: #fff; }
  #printArea h1, #printArea h2, #printArea h3 { margin: 0 0 6px; }
  #printArea table { min-width: 0; font-size: 12px; }
  #printArea th, #printArea td { padding: 5px; border-bottom: 1px solid #ddd; color: #000; background: #fff; }
  body.print-cupom #printArea { width: 72mm; padding: 2mm; font-family: ui-monospace, Consolas, monospace; font-size: 11px; }
  body.print-a4 #printArea { padding: 14mm; font-size: 12px; }
}

@page { margin: 8mm; }
body.print-cupom { size: 80mm auto; }
