:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --text: #1d2733;
  --muted: #5d6b7a;
  --line: #cfd6df;
  --accent: #1f5fa8;
  --accent-ink: #ffffff;
  --accent-soft: #e3edf9;
  --danger: #b3261e;
  --ok: #1e7b3a;
  --sidebar: #1b2a3a;
  --sidebar-ink: #d7e0ea;
  --sidebar-hover: #27405a;
  --row-sel: #fff2c7;
  --radius: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.4 "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login {
  width: 100%; max-width: 360px; background: var(--panel); border-radius: 10px;
  padding: 28px; box-shadow: 0 8px 30px rgba(0,0,0,.08);
}
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login p { margin: 0 0 18px; color: var(--muted); }
.login label { display: block; margin: 12px 0 4px; font-weight: 600; }
.login input { width: 100%; }
.login button { width: 100%; margin-top: 18px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; grid-template-rows: 48px 1fr; height: 100%; }
.topbar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; color: var(--accent); }
.topbar .empresa { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.topbar .menu-btn { display: none; }
.sidebar { background: var(--sidebar); color: var(--sidebar-ink); overflow-y: auto; padding: 8px 0 24px; }
.sidebar .grp { padding: 12px 16px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; opacity: .65; }
.sidebar a {
  display: block; padding: 7px 16px 7px 22px; color: inherit; text-decoration: none; cursor: pointer;
}
.sidebar a:hover, .sidebar a:focus { background: var(--sidebar-hover); outline: none; }
.sidebar a.active { background: var(--accent); color: var(--accent-ink); }
.main { overflow: auto; padding: 16px; }

/* ---------- paneles y formularios ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px;
}
.panel > h2, .page-title { margin: 0 0 12px; font-size: 17px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px 14px; margin: 0 0 14px; }
legend { padding: 0 6px; font-weight: 700; color: var(--accent); }
.grid { display: grid; gap: 8px 14px; grid-template-columns: repeat(12, 1fr); align-items: end; }
.grid > * { min-width: 0; }
.c2 { grid-column: span 2; } .c3 { grid-column: span 3; } .c4 { grid-column: span 4; }
.c5 { grid-column: span 5; } .c6 { grid-column: span 6; } .c8 { grid-column: span 8; }
.c9 { grid-column: span 9; } .c12 { grid-column: span 12; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
.field .row { display: flex; gap: 6px; }
.field .row > input { flex: 1; min-width: 0; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[readonly] { background: #f4f6f8; }
input.num { text-align: right; }
textarea { min-height: 120px; font-family: Consolas, "Courier New", monospace; }
.check { display: flex; align-items: center; gap: 6px; font-weight: 600; }

button, .btn {
  border: 1px solid var(--line); background: #f7f9fb; border-radius: 4px; padding: 6px 12px; cursor: pointer;
  white-space: nowrap;
}
button:hover { background: #edf1f5; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.actions .spacer { flex: 1; }

/* ---------- tablas ---------- */
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 4px; background: #fff; max-height: 55vh; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { padding: 5px 8px; border-bottom: 1px solid #edf0f3; text-align: left; white-space: nowrap; }
.tbl th { position: sticky; top: 0; background: #f4f6f8; font-size: 12px; color: var(--muted); z-index: 1; }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl tbody tr { cursor: default; }
.tbl tbody tr:hover { background: #f6f9fd; }
.tbl tbody tr.sel { background: var(--row-sel); }
.tbl tbody tr:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.empty { padding: 14px; color: var(--muted); }

/* ---------- venda ---------- */
.totais { display: flex; gap: 24px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.totais .t { text-align: right; }
.totais .t span { display: block; font-size: 12px; font-weight: 700; color: var(--muted); }
.totais .t b { font-size: 22px; }

/* ---------- modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(20,30,40,.45); display: flex; align-items: flex-start;
  justify-content: center; padding: 6vh 16px 16px; z-index: 50; overflow: auto;
}
.modal { background: var(--panel); border-radius: 8px; width: 100%; max-width: 720px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal.wide { max-width: 1000px; }
.modal.narrow { max-width: 440px; }
.modal header { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; font-size: 16px; flex: 1; }
.modal header button { border: 0; background: none; font-size: 20px; line-height: 1; padding: 2px 6px; }
.modal .body { padding: 14px 16px; }
.modal footer { padding: 10px 16px 14px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- menú de contexto ---------- */
.ctx { position: fixed; z-index: 60; background: #fff; border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: 4px 0; min-width: 220px; }
.ctx button { display: block; width: 100%; text-align: left; border: 0; background: none; border-radius: 0; padding: 7px 14px; }
.ctx button:hover, .ctx button:focus { background: var(--accent-soft); outline: none; }

/* ---------- avisos ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: #22303f; color: #fff; padding: 10px 14px; border-radius: 6px; max-width: 420px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
.muted { color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
.hidden { display: none !important; }
.badge { display: inline-block; padding: 1px 6px; border-radius: 10px; font-size: 12px; background: var(--accent-soft); color: var(--accent); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: 48px; bottom: 0; left: 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .topbar .menu-btn { display: inline-block; }
  .topbar .empresa, .topbar [data-relogio] { display: none; }
  .grid { grid-template-columns: repeat(6, 1fr); }
  .c2, .c3 { grid-column: span 3; } .c4, .c5, .c6, .c8, .c9, .c12 { grid-column: span 6; }
  .main { padding: 12px; }
}
