@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@300;400;500&family=Fraunces:ital,wght@0,300;0,600;1,300&display=swap');

/* ─── Tokens ─────────────────────────────────────────── */
:root {
  --bg:           #ffffff;
  --surface:      #fafafa;
  --surface2:     #f4f4f4;
  --charcoal:     #1a1a1a;

  --border:       #e8e8e8;
  --border-light: #f0f0f0;
  --divider:      #e8e8e8;

  --orange:       #F47920;
  --orange-dim:   #c95f0a;
  --orange-light: #fff3eb;
  --orange-faint: #fff8f4;

  --text:         #1a1a1a;
  --text-dim:     #555555;
  --text-muted:   #999999;

  --red:          #d93025;
  --green:        #16a34a;
  --amber:        #f59e0b;

  --sidebar-w:    200px;
  --topbar-h:     54px;
  --statusbar-h:  28px;
}

/* ─── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ─── Login ──────────────────────────────────────────── */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--charcoal);
  background-image: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(244,121,32,0.18) 0%, transparent 65%);
}

.auth-box {
  width: 360px;
  background: var(--bg);
  border-top: 3px solid var(--orange);
  padding: 44px 40px 40px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}

.auth-logo {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 22px;
  color: var(--orange);
  margin-bottom: 4px;
}

.auth-sub {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.auth-box .field { margin-bottom: 12px; }

.auth-error {
  font-size: 11px;
  color: var(--red);
  min-height: 18px;
  margin-bottom: 12px;
}

/* ─── Topbar ──────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--charcoal);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  z-index: 100;
}

.topbar-brand {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 18px;
  color: var(--orange);
  flex: 1;
}

.topbar-brand span {
  font-size: 9px;
  font-family: 'DM Mono', monospace;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--text-muted);
  display: block;
  margin-top: -4px;
}

.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ─── Buttons ─────────────────────────────────────────── */
.btn-primary {
  display: block;
  width: 100%;
  padding: 11px;
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 0;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary:hover { background: var(--orange-dim); }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-sm {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid #3a3a3a;
  border-radius: 0;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #aaa;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn-sm:hover { border-color: var(--orange); color: var(--orange); }
.btn-sm:disabled { opacity: 0.35; cursor: not-allowed; }

/* Variantes sobre fundo claro */
.btn-sm.light {
  border-color: var(--border);
  color: var(--text-dim);
}
.btn-sm.light:hover { border-color: var(--orange); color: var(--orange); }

.btn-sm.accent {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
}
.btn-sm.accent:hover { background: var(--orange-dim); border-color: var(--orange-dim); }

.btn-sm.danger {
  border-color: transparent;
  color: var(--red);
}
.btn-sm.danger:hover { border-color: var(--red); }

.btn-sm.success {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.btn-sm.success:hover { opacity: .85; }

.btn-sm.warn {
  background: var(--amber);
  border-color: var(--amber);
  color: #fff;
}

/* Botão tracejado "adicionar" */
.btn-add {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 0;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-add:hover { border-color: var(--orange); color: var(--orange); background: var(--orange-faint); }

/* ─── Fields ──────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }

.field label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--text-muted);
  font-weight: 400;
}

.field input,
.field select,
.field textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 0;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: all 0.15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(244,121,32,0.08);
}

.field textarea { resize: vertical; min-height: 60px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row.triple { grid-template-columns: 1fr 1fr 1fr; }
.field-row.full { grid-template-columns: 1fr; }

/* Section label */
.section-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--orange);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

/* ─── App layout ──────────────────────────────────────── */
#app { display: none; }
#app.visible { display: flex; flex-direction: column; }

.app-body {
  display: flex;
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h) - var(--statusbar-h));
}

/* ─── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  padding: 16px 0;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h) - var(--statusbar-h));
  overflow-y: auto;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 18px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 11px;
  transition: all 0.15s;
  border-left: 2px solid transparent;
}

.sidebar nav a .icon { font-size: 13px; width: 16px; text-align: center; }
.sidebar nav a:hover { color: var(--orange); background: var(--orange-faint); }
.sidebar nav a.active {
  border-left-color: var(--orange);
  color: var(--orange);
  background: var(--orange-faint);
  font-weight: 500;
}

/* ─── Content ─────────────────────────────────────────── */
.content {
  flex: 1;
  padding: 28px 32px;
  overflow-y: auto;
  min-height: calc(100vh - var(--topbar-h) - var(--statusbar-h));
}

.secao { display: none; }
.secao.ativa { display: block; }

.secao-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.secao-titulo {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 20px;
  color: var(--charcoal);
}

/* ─── Toolbar ─────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar input,
.toolbar select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 0;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: all 0.15s;
}

.toolbar input:focus,
.toolbar select:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(244,121,32,0.08);
}

/* ─── Tables ──────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  background: var(--charcoal);
  color: #aaa;
  padding: 9px 12px;
  text-align: left;
  font-size: 9px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  white-space: nowrap;
}

thead th.num { text-align: right; }

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  vertical-align: middle;
}

tbody td.num { text-align: right; }

tbody tr:hover td { background: var(--orange-faint); }

tr.total-row td {
  border-top: 2px solid var(--orange);
  background: var(--orange-light);
  color: var(--orange);
  font-weight: 500;
}

.item-name { color: var(--text); font-weight: 500; font-size: 12px; }
.item-sub { font-size: 10px; color: var(--text-muted); margin-top: 1px; }

/* Saldo indicators */
.saldo-critico td { background: rgba(217,48,37,0.05) !important; }
.saldo-critico .saldo-val { color: var(--red) !important; font-weight: 500; }

.saldo-atencao td { background: rgba(245,158,11,0.05) !important; }
.saldo-atencao .saldo-val { color: #92400e !important; font-weight: 500; }

/* Tags */
.tag {
  display: inline-block;
  padding: 2px 7px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}

.tag-entrada { background: rgba(22,163,74,0.1); color: var(--green); }
.tag-saida { background: rgba(217,48,37,0.1); color: var(--red); }
.tag-origem { background: var(--surface2); color: var(--text-muted); }

/* Inline edit */
.inline-edit {
  background: transparent;
  border: none;
  border-bottom: 1px dashed var(--border);
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--text-dim);
  width: 72px;
  padding: 2px 4px;
  cursor: pointer;
  border-radius: 0;
}

.inline-edit:focus {
  outline: none;
  border-bottom-color: var(--orange);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(244,121,32,0.08);
}

/* ─── Kanban ──────────────────────────────────────────── */
.kanban {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  align-items: start;
}

.kanban-col {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 12px;
  min-height: 180px;
}

.kanban-col-header {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.col-aprovada .kanban-col-header { color: var(--amber); }
.col-concluida .kanban-col-header { color: var(--green); }

.kcount {
  background: var(--border);
  color: var(--text-muted);
  font-size: 9px;
  padding: 1px 6px;
}

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  padding: 12px;
  margin-bottom: 8px;
  transition: all 0.15s;
}

.card:hover { border-left-color: var(--orange); background: var(--orange-faint); }

.col-aprovada .card { border-left-color: var(--amber); }
.col-concluida .card { border-left-color: var(--green); }
.col-concluida .card:hover { background: var(--bg); border-left-color: var(--green); }

.card-id { font-size: 9px; color: var(--text-muted); letter-spacing: 0.05em; margin-bottom: 5px; }
.card-cliente { font-size: 13px; font-weight: 500; color: var(--text); }
.card-cidade { font-size: 10px; color: var(--text-muted); margin-bottom: 8px; }

.card-valor {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--orange);
  margin-bottom: 4px;
}

.card-data { font-size: 10px; color: var(--text-muted); margin-bottom: 10px; }

.card-itens {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.card-itens ul { padding-left: 12px; }
.card-itens li { margin-bottom: 2px; }

.card-aviso {
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.3);
  padding: 6px 8px;
  font-size: 10px;
  color: #92400e;
  margin-bottom: 10px;
}

.card-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ─── Result cards (métricas) ────────────────────────── */
.result-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  margin-bottom: 24px;
}

.result-card {
  background: var(--bg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}

.result-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--orange);
  opacity: 0.25;
}

.result-card:first-child::before { opacity: 1; }

.rc-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.rc-value {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 23px;
  color: var(--charcoal);
}

.result-card:first-child .rc-value { color: var(--orange); }
.rc-sub { font-size: 10px; color: var(--text-muted); margin-top: 4px; }

/* ─── Modals ──────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.58);
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--bg);
  border-top: 3px solid var(--orange);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.2);
}

.modal-box.wide { max-width: 660px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header span {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--orange);
  font-weight: 500;
}

.modal-header button {
  background: none;
  border: none;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  transition: color 0.15s;
}

.modal-header button:hover { color: var(--text); }

.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ─── Status bar ──────────────────────────────────────── */
.statusbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--statusbar-h);
  background: var(--charcoal);
  border-top: 2px solid var(--orange);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 24px;
  z-index: 100;
  font-size: 10px;
  color: #888;
}

.statusbar strong { color: var(--orange); }

/* ─── Avisos panel ────────────────────────────────────── */
.avisos-panel {
  position: fixed;
  top: var(--topbar-h);
  right: -360px;
  width: 360px;
  height: calc(100vh - var(--topbar-h) - var(--statusbar-h));
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0,0,0,0.1);
  z-index: 150;
  transition: right 0.22s ease;
  overflow-y: auto;
}

.avisos-panel.aberto { right: 0; }

.avisos-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--charcoal);
}

.avisos-header span {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--orange);
}

.avisos-header button {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 14px;
  transition: color 0.15s;
}

.avisos-header button:hover { color: #fff; }

.avisos-body { padding: 12px; }

.aviso-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  margin-bottom: 8px;
  background: var(--bg);
}

.aviso-item.critico { border-left-color: var(--red); }
.aviso-item.pendente { border-left-color: var(--amber); }

.aviso-label { font-size: 12px; font-weight: 500; color: var(--text); margin-bottom: 3px; }
.aviso-detalhe { font-size: 10px; color: var(--text-muted); }

/* Badge */
.badge {
  background: var(--red);
  color: #fff;
  font-size: 9px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
  display: inline-block;
}

/* ─── Edit items modal ───────────────────────────────── */
.itens-list { display: flex; flex-direction: column; gap: 6px; }

.item-check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  font-size: 12px;
  transition: background 0.1s;
}

.item-check-row:hover { background: var(--surface); }
.item-check-row.removido { opacity: 0.4; }
.item-check-row input[type=checkbox] { cursor: pointer; accent-color: var(--orange); }
.item-check-row label { flex: 1; cursor: pointer; }

.extra-row {
  display: grid;
  grid-template-columns: 1fr 72px 26px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.extra-row select,
.extra-row input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 0;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  outline: none;
}

.extra-row select:focus,
.extra-row input:focus {
  border-color: var(--orange);
}

.btn-icon-sm {
  width: 26px;
  height: 26px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.15s;
}

.btn-icon-sm:hover { border-color: var(--red); color: var(--red); }

/* ─── Empty states ───────────────────────────────────── */
.empty {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 11px;
}

/* ─── Toast ──────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--statusbar-h) + 12px);
  right: 20px;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  z-index: 999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  animation: toastIn 0.15s ease;
}

.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

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

/* ─── Print ──────────────────────────────────────────── */
@media print {
  .topbar, .sidebar, .statusbar, .btn-sm, .toolbar, .card-actions { display: none !important; }
  .content { padding: 0; }
}

/* ─── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); }
::-webkit-scrollbar-thumb:hover { background: #ccc; }
