:root {
  --accent: #c2410c; --accent-dark: #9a3412; --brand: #f6660d; --bg: #f4f6f9; --card: #fff; --text: #1f2933;
  --muted: #6b7280; --border: #e2e6ec; --green: #1f9d55; --red: #d64545; --amber: #c98a12;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 "Segoe UI", Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 20px 0 8px; }
.muted { color: var(--muted); }
.num { text-align: right; white-space: nowrap; }
.text-red { color: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 24px; }

/* layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; flex: none; background: #fff; border-right: 1px solid var(--border); padding: 16px 12px;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; padding-bottom: 16px; font-weight: 600; text-align: center; }
.brand img { width: 90px; height: auto; }
.brand-name { font-size: 20px; font-weight: 800; letter-spacing: .08em; color: var(--brand); }
.brand-sub { font-size: 12px; font-weight: 500; color: var(--muted); }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar nav a { padding: 9px 12px; border-radius: 6px; color: var(--text); text-decoration: none; font-weight: 500; }
.sidebar nav a:hover { background: #fdf1ea; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.side-foot { border-top: 1px solid var(--border); padding-top: 12px; font-size: 13px; }
.content { flex: 1; min-width: 0; padding: 20px 24px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; }

/* buttons */
.btn { display: inline-block; padding: 7px 14px; border: 1px solid var(--accent); background: #fff; color: var(--accent);
  border-radius: 6px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; text-align: center; }
.btn:hover { background: #fdf1ea; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-whatsapp { background: var(--green); border-color: var(--green); color: #fff; }
.btn-whatsapp:hover { background: #18804a; }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: #fdeeee; }
.btn-link { border: 0; background: none; padding: 4px 0; }
.btn-block { width: 100%; }

/* forms */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label, .trow label { font-weight: 600; font-size: 13px; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #cdd3dc; border-radius: 6px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f6c9ab; border-color: var(--accent); }
input.invalid { border-color: var(--red); background: #fff6f6; }
textarea { resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
fieldset.block { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 0; }
fieldset.block legend { font-weight: 600; padding: 0 6px; }
.check { display: flex; align-items: center; gap: 6px; }
.check input { width: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* tables */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; color: var(--accent-dark);
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: #fafbfd; }
.table td { padding: 9px 12px; border-bottom: 1px solid #eef1f5; vertical-align: top; }
.table th.num { text-align: right; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover { background: #fdf6f1; }
tr.voided td { color: var(--muted); text-decoration: line-through; }
.filters { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.filters select { width: auto; }
.filters input { max-width: 280px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 12px; }

/* items table in the form */
.items-table td { padding: 6px; }
.items-table textarea { min-width: 260px; }
.items-table input { min-width: 70px; }
.items-table .n { width: 28px; color: var(--muted); }
.items-table .t { font-weight: 600; }
.item-actions { display: flex; gap: 10px; margin: 10px 0 16px; flex-wrap: wrap; align-items: center; }
.item-actions select { width: auto; min-width: 220px; }
.totals { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 12px; align-self: start; }
.trow { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.trow input { max-width: 140px; text-align: right; }
.trow.total { border-top: 1px solid var(--border); padding-top: 8px; font-weight: 700; font-size: 16px; margin-bottom: 0; }

/* badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.badge-new { background: #fff4d6; color: var(--amber); }
.badge-invoiced, .badge-paid { background: #dff5e8; color: var(--green); }
.badge-unpaid, .badge-cancelled { background: #fdeaea; color: var(--red); }
.badge-partial { background: #fff1cf; color: var(--amber); }

/* document view page */
.view { display: flex; gap: 20px; align-items: flex-start; }
.view-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.doc-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 16px; overflow-x: auto; }
.actions { width: 220px; flex: none; display: flex; flex-direction: column; gap: 8px; }
.actions hr { width: 100%; border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.statusbox { border: 1px solid var(--border); background: #fff; border-radius: 6px; text-align: center; padding: 10px; }
.status-big { font-size: 22px; font-weight: 600; text-transform: uppercase; }
.status-new, .status-partial { color: var(--amber); }
.status-invoiced, .status-paid { color: var(--green); }
.status-unpaid, .status-cancelled { color: var(--red); }
.panel h2 { margin-top: 0; }
.pay-summary { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.pay-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; margin-top: 12px; }
.pay-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* dialog */
dialog { border: 0; border-radius: 10px; padding: 20px; width: min(520px, 94vw); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }

/* toasts and banner */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { padding: 10px 14px; border-radius: 6px; color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.2); max-width: 360px; }
.toast-ok { background: var(--green); }
.toast-error { background: var(--red); }
.banner-error { background: var(--red); color: #fff; text-align: center; padding: 8px 12px; }

/* login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: #fff; border: 1px solid var(--border); border-top: 4px solid var(--brand); border-radius: 10px; padding: 28px; width: min(380px, 92vw); text-align: center; }
.login-card form { text-align: left; margin-top: 16px; }
.login-logo { width: 120px; height: auto; }
.login-name { font-size: 22px; font-weight: 800; letter-spacing: .08em; color: var(--brand); margin-top: 4px; }

@media print {
  .no-print { display: none !important; }
}

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
  .brand { flex-direction: row; padding: 0; }
  .brand img { width: 40px; }
  .brand-sub { display: none; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { border: 0; padding: 0; }
  .content { padding: 12px; }
  .grid-2 { grid-template-columns: 1fr; }
  .view { flex-direction: column; }
  .actions { width: 100%; }
}
