:root {
  --ink: #141414;
  --ink-2: #3a3a3a;
  --muted: #6b6b6b;
  --line: #e2e2e2;
  --bg: #f4f4f2;
  --card: #ffffff;
  --accent: #c8102e;
  --accent-dark: #a00d25;
  --ok: #1f7a3a;
  --ok-bg: #e6f3ea;
  --warn: #8a5a00;
  --warn-bg: #fdf1d8;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.login-brand {
  background: var(--ink);
  display: flex; align-items: center; justify-content: center;
  padding: 48px;
}
.login-brand img { width: min(320px, 70%); height: auto; }
.login-form-wrap { display: flex; align-items: center; justify-content: center; padding: 32px; }
.login-form { width: 100%; max-width: 360px; }
.login-form h1 { font-size: 26px; margin-bottom: 6px; }
.login-form p.sub { color: var(--muted); margin: 0 0 28px; }
.login-logo-mobile { display: none; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--ink-2); }
.field label .req { color: var(--accent); }
.input, select.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cfcfcf;
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}
.input:focus { outline: 2px solid var(--ink); outline-offset: -1px; border-color: var(--ink); }
.input.invalid { border-color: var(--accent); }
.field .err { color: var(--accent); font-size: 12.5px; margin-top: 4px; min-height: 0; }
.input.upper { text-transform: uppercase; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #000; }
.btn.secondary { background: #fff; color: var(--ink); border-color: #cfcfcf; }
.btn.secondary:hover { border-color: var(--ink); }
.btn.danger { background: #fff; color: var(--accent); border-color: #f0c4cb; }
.btn.danger:hover { background: #fdf0f2; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.link-btn { background: none; border: 0; color: var(--ink-2); cursor: pointer; padding: 4px; text-decoration: underline; }

/* ---------- Shell ---------- */
.topbar {
  background: var(--ink); color: #fff;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.topbar .brand img { height: 40px; }
.topbar .brand span { font-weight: 700; letter-spacing: .08em; font-size: 14px; }
.topbar .user { display: flex; align-items: center; gap: 14px; font-size: 14px; color: #ccc; }
.topbar .user button { background: transparent; color: #fff; border: 1px solid #555; border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.topbar .user button:hover { border-color: #fff; }

.tabs { background: #fff; border-bottom: 1px solid var(--line); padding: 0 24px; display: flex; gap: 4px; }
.tabs a {
  padding: 14px 16px; text-decoration: none; color: var(--muted); font-weight: 600;
  border-bottom: 3px solid transparent;
}
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); }

.page { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }

/* ---------- Home menu ---------- */
.modules { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.module {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 28px; text-decoration: none; color: var(--ink);
  display: flex; flex-direction: column; gap: 10px; min-height: 200px;
  transition: border-color .15s, transform .15s;
}
.module:hover { border-color: var(--ink); transform: translateY(-2px); }
.module .ico { width: 44px; height: 44px; border-radius: 10px; background: var(--ink); color: #fff; display: grid; place-items: center; }
.module h2 { font-size: 20px; margin-top: 8px; }
.module p { margin: 0; color: var(--muted); font-size: 14px; }
.module .tag { margin-top: auto; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.module .tag.on { color: var(--ok); }
.module .tag.off { color: var(--muted); }

/* ---------- Sub-nav ---------- */
.subnav { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.subnav a {
  padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--ink-2);
  border: 1px solid var(--line); background: #fff; font-weight: 600; font-size: 14px;
}
.subnav a.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.subnav .count { opacity: .7; font-weight: 500; margin-left: 4px; }

/* ---------- Cards / tables ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.card-pad { padding: 20px; }
.card h3 { font-size: 16px; }
.toolbar { display: flex; gap: 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar .input { max-width: 320px; }
.toolbar .spacer { flex: 1; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; background: #fafafa; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #fafafa; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }

.plate {
  display: inline-block; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-weight: 700;
  letter-spacing: .08em; border: 2px solid var(--ink); border-radius: 4px; padding: 1px 8px; background: #fff;
  border-top-width: 6px; border-top-color: #1d4fa3;
}
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.patio { background: var(--warn-bg); color: var(--warn); }
.badge.done { background: var(--ok-bg); color: var(--ok); }
.badge.low { background: #fde8eb; color: var(--accent); }

.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

/* ---------- Ficha ---------- */
.ficha-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.ficha-grid .span-2 { grid-column: span 2; }
.section-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.section-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.add-line { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: #fafafa; border-radius: 0 0 12px 12px; flex-wrap: wrap; }
.add-line select { flex: 1; min-width: 180px; }
.add-line input[type=number] { width: 90px; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 20px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: #f1f1f1; border-radius: 999px; padding: 6px 8px 6px 14px; font-weight: 600; font-size: 14px; }
.chip button { border: 0; background: #ddd; width: 22px; height: 22px; border-radius: 50%; cursor: pointer; line-height: 1; color: var(--ink); }
.chip button:hover { background: var(--accent); color: #fff; }
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; }
.summary div { padding: 16px 20px; border-right: 1px solid var(--line); }
.summary div:last-child { border-right: 0; }
.summary dt { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.summary dd { margin: 4px 0 0; font-size: 16px; font-weight: 600; }

/* ---------- Placeholder ---------- */
.soon { text-align: center; padding: 72px 24px; }
.soon h2 { font-size: 20px; margin-bottom: 8px; }
.soon p { color: var(--muted); margin: 0; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { font-size: 18px; }
.modal-head button { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 8px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .login-logo-mobile { display: block; width: 120px; margin: 0 auto 24px; }
  .modules { grid-template-columns: 1fr; }
  .ficha-grid { grid-template-columns: 1fr; }
  .ficha-grid .span-2 { grid-column: auto; }
  .summary { grid-template-columns: 1fr 1fr; }
  .summary div:nth-child(2) { border-right: 0; }
  .summary div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .topbar .brand span, .topbar .user .name { display: none; }
  .hide-sm { display: none; }
  th, td { padding: 10px 12px; }
  .page { padding: 20px 14px 48px; }
  .tabs { padding: 0 8px; overflow-x: auto; }
}
