:root {
  --bg: #101317;
  --bg-elevated: #171b20;
  --surface: #1c2128;
  --surface-2: #23282f;
  --steel: #3a4048;
  --steel-line: #2b3038;
  --brass: #c98a3e;
  --brass-soft: #e0a860;
  --brass-dim: #7a5a30;
  --text: #e8eaed;
  --text-dim: #9aa4ae;
  --text-faint: #626b74;
  --danger: #c1543f;
  --ok: #5c9b6e;
  --warn: #c98a3e;
  --radius: 10px;
  --radius-lg: 16px;
  --font-display: 'Barlow Condensed', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  background-image:
    radial-gradient(circle at 15% 0%, rgba(201,138,62,0.06), transparent 40%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.012) 0px, rgba(255,255,255,0.012) 1px, transparent 1px, transparent 24px),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.012) 0px, rgba(255,255,255,0.012) 1px, transparent 1px, transparent 24px);
  min-height: 100vh;
  padding-bottom: 84px;
}

button { font-family: inherit; }

::selection { background: var(--brass-dim); color: #fff; }

a { color: var(--brass-soft); }

/* ---------- Top App Bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: linear-gradient(180deg, var(--bg-elevated), rgba(23,27,32,0.92));
  border-bottom: 1px solid var(--steel-line);
  backdrop-filter: blur(6px);
}

.badge-hex {
  width: 38px;
  height: 38px;
  position: relative;
  flex-shrink: 0;
}
.badge-hex svg { width: 100%; height: 100%; }

.brand {
  display: flex;
  flex-direction: column;
  line-height: 1;
}
.brand .name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 21px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text);
}
.brand .name span { color: var(--brass); }
.brand .sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-faint);
  text-transform: uppercase;
  margin-top: 2px;
}

.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

/* ---------- Layout ---------- */
.container {
  max-width: 880px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.view { display: none; animation: fadein .25s ease; }
.view.active { display: block; }

@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Panels (signature: corner-bracket armored panel) ---------- */
.panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--steel-line);
  border-radius: var(--radius-lg);
  padding: 18px 18px 20px;
  margin-bottom: 16px;
}
.panel::before, .panel::after,
.panel .cb-br, .panel .cb-bl {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid var(--brass-dim);
  opacity: 0.7;
}
.panel::before { top: -1px; left: -1px; border-right: none; border-bottom: none; border-top-left-radius: 6px; }
.panel::after { top: -1px; right: -1px; border-left: none; border-bottom: none; border-top-right-radius: 6px; }
.panel .cb-bl { bottom: -1px; left: -1px; border-right: none; border-top: none; border-bottom-left-radius: 6px; }
.panel .cb-br { bottom: -1px; right: -1px; border-left: none; border-top: none; border-bottom-right-radius: 6px; }

.panel-title {
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 15px;
  color: var(--brass-soft);
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-title .num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  border: 1px solid var(--steel);
  border-radius: 4px;
  padding: 1px 6px;
}

/* ---------- Form elements ---------- */
label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1 1 160px; }

input[type=text], input[type=tel], input[type=number], input[type=date],
select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--steel);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 15px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color .15s;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus { border-color: var(--brass); }
textarea { min-height: 70px; resize: vertical; }

.seg {
  display: flex;
  border: 1px solid var(--steel);
  border-radius: var(--radius);
  overflow: hidden;
}
.seg button {
  flex: 1;
  padding: 10px 8px;
  background: var(--bg);
  color: var(--text-dim);
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  border-right: 1px solid var(--steel);
}
.seg button:last-child { border-right: none; }
.seg button.active {
  background: var(--brass-dim);
  color: #fff;
}

/* checklist items */
.check-list { display: flex; flex-direction: column; gap: 2px; }
.check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--steel-line);
  cursor: pointer;
  user-select: none;
}
.check-item:last-child { border-bottom: none; }
.check-item input[type=checkbox] { display: none; }
.checkbox {
  width: 20px;
  height: 20px;
  border: 2px solid var(--steel);
  border-radius: 5px;
  flex-shrink: 0;
  position: relative;
  transition: all .15s;
}
.check-item input:checked + .checkbox {
  background: var(--brass);
  border-color: var(--brass);
}
.check-item input:checked + .checkbox::after {
  content: "";
  position: absolute;
  left: 6px; top: 2px;
  width: 5px; height: 10px;
  border: solid #14171a;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.check-item .label-text { flex: 1; font-size: 15px; }
.check-item .price-tag {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--brass-soft);
}
.remove-x {
  color: var(--text-faint);
  padding: 2px 6px;
  font-size: 16px;
  cursor: pointer;
}
.remove-x:hover { color: var(--danger); }

.add-item-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.add-item-row input { flex: 1; }

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--steel);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all .12s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--brass-dim); }
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--brass);
  border-color: var(--brass);
  color: #14171a;
}
.btn-primary:hover { background: var(--brass-soft); }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-icon { width: 38px; height: 38px; padding: 0; border-radius: 50%; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

/* total bar */
.total-bar {
  position: sticky;
  bottom: 68px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
  border: 1px solid var(--brass-dim);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  margin: 10px 0 20px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.total-bar .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); }
.total-bar .val { font-family: var(--font-mono); font-size: 26px; color: var(--brass-soft); font-weight: 600; }

/* bottom nav */
.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid var(--steel-line);
  z-index: 60;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0 8px;
  font-size: 11px;
  letter-spacing: 0.4px;
  cursor: pointer;
  text-transform: uppercase;
  font-weight: 600;
}
.bottomnav button svg { width: 21px; height: 21px; }
.bottomnav button.active { color: var(--brass-soft); }

/* order list */
.order-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--steel-line);
  border-radius: var(--radius);
  margin-bottom: 10px;
  cursor: pointer;
}
.order-card:hover { border-color: var(--brass-dim); }
.order-card .os-num {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--brass-soft);
  border: 1px solid var(--steel);
  border-radius: 4px;
  padding: 3px 7px;
  flex-shrink: 0;
}
.order-card .info { flex: 1; min-width: 0; }
.order-card .info .cliente { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-card .info .meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.order-card .valor { font-family: var(--font-mono); color: var(--brass-soft); font-weight: 600; flex-shrink: 0; }

.status-chip {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 700;
  flex-shrink: 0;
}
.status-aberta { background: rgba(154,164,174,0.15); color: var(--text-dim); }
.status-andamento { background: rgba(201,138,62,0.18); color: var(--brass-soft); }
.status-concluida { background: rgba(92,155,110,0.18); color: var(--ok); }
.status-entregue { background: rgba(92,155,110,0.3); color: var(--ok); }

.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-faint);
}
.empty-state svg { width: 54px; height: 54px; margin-bottom: 14px; opacity: 0.5; }

.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input { flex: 1; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-chip {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--steel);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
}
.filter-chip.active { background: var(--brass-dim); border-color: var(--brass-dim); color: #fff; }

/* preco rows */
.preco-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--steel-line);
}
.preco-row:last-child { border-bottom: none; }
.preco-row .nome { flex: 1; font-size: 14px; }
.preco-row .inputs { display: flex; gap: 8px; }
.preco-row .inputs input { width: 90px; text-align: right; }
.preco-row .inputs .u { font-size: 10px; color: var(--text-faint); text-align: center; margin-bottom: 2px; }

/* toast */
#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--brass);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  transition: all .25s;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(8,10,12,0.7);
  z-index: 150;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--steel-line);
  border-radius: 18px 18px 0 0;
  width: 100%;
  max-width: 880px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px;
  animation: slideup .25s ease;
}
@media (min-width: 700px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 16px; margin: 20px; }
}
@keyframes slideup { from { transform: translateY(30px); opacity:0; } to { transform: translateY(0); opacity:1; } }
.modal-header { display: flex; align-items: center; margin-bottom: 14px; }
.modal-header h3 { font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.5px; margin: 0; font-size: 19px; color: var(--brass-soft);}
.modal-header .btn { margin-left: auto; }

/* section divider label */
.section-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 22px 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-eyebrow::after { content: ""; flex: 1; height: 1px; background: var(--steel-line); }

/* ---------- Print (Ordem de Serviço) ---------- */
.print-doc { display: none; }
@media print {
  body * { visibility: hidden; }
  .print-doc, .print-doc * { visibility: visible; }
  .print-doc {
    display: block;
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    color: #000;
    background: #fff;
    font-family: 'Inter', Arial, sans-serif;
    padding: 20px;
  }
}
.print-doc .p-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  border-bottom: 3px solid #000; padding-bottom: 12px; margin-bottom: 16px;
}
.print-doc .p-brand { font-family: 'Barlow Condensed', sans-serif; font-size: 28px; font-weight: 700; text-transform: uppercase; }
.print-doc .p-brand span { color: #c98a3e; }
.print-doc .p-osnum { text-align: right; font-family: monospace; font-size: 14px; }
.print-doc h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid #999; padding-bottom: 4px; margin: 16px 0 8px; }
.print-doc table { width: 100%; border-collapse: collapse; font-size: 13px; }
.print-doc td { padding: 4px 0; }
.print-doc .p-total { text-align: right; font-size: 20px; font-weight: 700; margin-top: 10px; }
.print-doc .p-sign { display: flex; justify-content: space-between; margin-top: 60px; }
.print-doc .p-sign div { width: 45%; text-align: center; border-top: 1px solid #000; padding-top: 6px; font-size: 12px; }

/* ---------- Assinatura ---------- */
.sig-preview {
  border: 1px dashed var(--steel);
  border-radius: var(--radius);
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
  padding: 4px;
}
.sig-preview img { max-height: 90px; max-width: 100%; background: #fff; border-radius: 4px; }
.sig-preview .none { font-size: 12px; color: var(--text-faint); }
.sig-preview button.btn { margin: 6px; }

.sig-canvas-wrap {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--steel);
  overflow: hidden;
  touch-action: none;
}
#sig-canvas { width: 100%; height: 220px; display: block; touch-action: none; cursor: crosshair; }

@media (max-width: 480px) {
  .brand .name { font-size: 18px; }
  .total-bar .val { font-size: 22px; }
}
