:root {
  --brand: #1e4f90;
  --brand-dark: #163a6b;
  --accent: #2bb3e0;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #5d6779;
  --line: #dde2ea;
  --ok: #1d7a46;
  --warn: #a35c00;
  --bad: #b3261e;
  --radius: 8px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* Top bar */
.topbar { background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 10; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.topbar-inner { max-width: 1280px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; }
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; font-weight: 700; white-space: nowrap; }
.brand img { height: 34px; width: 34px; background: #fff; border-radius: 50%; padding: 2px; }
.brand small { display: block; font-weight: 400; font-size: .7rem; opacity: .85; }
.nav { display: flex; gap: .15rem; flex: 1; overflow-x: auto; }
.nav a { color: #dbe7f7; padding: .45rem .7rem; border-radius: 6px; white-space: nowrap; }
.nav a:hover, .nav a.active { background: rgba(255,255,255,.15); color: #fff; text-decoration: none; }
.userbox { display: flex; gap: .5rem; align-items: center; font-size: .85rem; white-space: nowrap; }
.userbox a, .userbox button { color: #dbe7f7; background: none; border: 0; font: inherit; cursor: pointer; padding: 0; }

.container { max-width: 1280px; margin: 0 auto; padding: 1rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* Cards & grid */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card > h2:first-child { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; }
.stat .n { font-size: 1.8rem; font-weight: 700; line-height: 1.1; color: var(--brand); }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat.alert .n { color: var(--bad); }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f8f9fb; }
tr:hover td { background: #fafbfd; }
tfoot td { font-weight: 700; }
td.num, th.num { text-align: right; white-space: nowrap; }

/* Badges */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; white-space: nowrap; }
.st-open { background: #e3effd; color: #1a56a8; }
.st-in_progress { background: #fff1d6; color: #8a5300; }
.st-on_hold { background: #f3e5f5; color: #6a1b9a; }
.st-closed { background: #e4f4ea; color: var(--ok); }
.cov-warranty { background: #e4f4ea; color: var(--ok); }
.cov-amc { background: #e0f5fb; color: #0b6f8c; }
.cov-none { background: #fde8e7; color: var(--bad); }
.tag { background: #eef1f5; color: var(--muted); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: .5rem .9rem; border-radius: 6px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 40px; }
.btn:hover { text-decoration: none; background: #f2f4f8; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { color: var(--bad); }
.btn-small { padding: .25rem .6rem; min-height: 30px; font-size: .85rem; }
.btn-link { border: 0; background: none; color: var(--brand); padding: 0; min-height: 0; font-weight: 400; cursor: pointer; font: inherit; }
.flag-btn { border: 0; background: none; cursor: pointer; font-size: 1.25rem; line-height: 1; padding: .1rem; color: #b9c0cc; }
.flag-btn.on { color: #e0a100; }

/* Forms */
form.stack { display: grid; gap: .9rem; }
.field label { display: block; font-weight: 600; margin-bottom: .25rem; font-size: .9rem; }
.field .help { color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.field .errors { color: var(--bad); font-size: .85rem; margin-top: .2rem; }
.field.has-error .input { border-color: var(--bad); }
.field.req label::after { content: " *"; color: var(--bad); }
.input { width: 100%; padding: .55rem .65rem; border: 1px solid #c8cfda; border-radius: 6px; font: inherit; background: #fff; min-height: 42px; }
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.check { width: 20px; height: 20px; vertical-align: middle; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .9rem; }
.form-grid .wide { grid-column: 1 / -1; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .6rem; align-items: end; }
.filters .field label { font-size: .8rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem 1rem; margin: 0; }
legend { font-weight: 700; padding: 0 .3rem; }
.nonfield { background: #fde8e7; color: var(--bad); padding: .6rem .8rem; border-radius: 6px; }

/* Messages */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: .5rem; }
.messages li { padding: .65rem .9rem; border-radius: 6px; background: #e4f4ea; color: var(--ok); border: 1px solid #c4e5d1; }
.messages li.error { background: #fde8e7; color: var(--bad); border-color: #f5c6c3; }
.messages li.warning { background: #fff1d6; color: var(--warn); border-color: #f3dca8; }

/* Timeline (action log) */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline > li { border-left: 3px solid var(--line); padding: 0 0 1rem 1rem; position: relative; }
.timeline > li::before { content: ""; position: absolute; left: -8px; top: 4px; width: 13px; height: 13px; border-radius: 50%; background: var(--brand); border: 2px solid #fff; }
.timeline > li.visit::before { background: #e0a100; }
.timeline .meta { display: flex; flex-wrap: wrap; gap: .4rem .8rem; align-items: center; font-size: .88rem; color: var(--muted); }
.timeline .meta strong { color: var(--text); }
.timeline .body { margin-top: .35rem; white-space: pre-line; }
.timeline .visit-box { background: #fffaf0; border: 1px solid #f3e3bf; border-radius: 6px; padding: .5rem .75rem; margin-top: .5rem; font-size: .9rem; }
.pre { white-space: pre-line; }

.status-forms details { margin-bottom: .5rem; }
.status-forms summary { cursor: pointer; list-style: none; }
.status-forms summary::-webkit-details-marker { display: none; }
.status-forms form { margin-top: .5rem; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .75rem; }
.thumb { border: 1px solid var(--line); border-radius: 6px; padding: .4rem; background: #fff; font-size: .8rem; word-break: break-word; }
.thumb img { width: 100%; height: 100px; object-fit: cover; border-radius: 4px; display: block; margin-bottom: .3rem; }
.thumb .icon { height: 100px; display: flex; align-items: center; justify-content: center; font-size: 2rem; background: #f2f4f8; border-radius: 4px; margin-bottom: .3rem; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; }
.login-card img { width: 100%; margin-bottom: 1rem; }
.login-links { margin: 1rem 0 0; text-align: center; }
.pw-wrap { position: relative; display: block; }
.pw-wrap .input { padding-right: 4.2rem; width: 100%; }
.pw-toggle { position: absolute; right: .35rem; top: 50%; transform: translateY(-50%); border: 0; background: none;
  color: var(--brand); font: inherit; font-size: .85rem; padding: .3rem .4rem; cursor: pointer; }

.empty { color: var(--muted); padding: .75rem 0; }
.pagination { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; }

@media (max-width: 760px) {
  body { font-size: 16px; }
  .topbar-inner { flex-wrap: wrap; padding: .5rem .75rem; gap: .4rem; }
  .nav { order: 3; width: 100%; flex: none; }
  .userbox { margin-left: auto; }
  .container { padding: .75rem; }
  .hide-sm { display: none; }
  .card { padding: .85rem; }
  dl.kv { grid-template-columns: 1fr; gap: 0; }
  dl.kv dd { margin-bottom: .4rem; }
  .page-head .actions .btn { flex: 1; }
  .mobile-sticky { position: sticky; bottom: 0; background: var(--bg); padding: .6rem 0; border-top: 1px solid var(--line); }
  .mobile-sticky { flex-wrap: nowrap !important; }
  .mobile-sticky .btn { flex: 1 1 auto; padding: .5rem .6rem; }
}
@media print {
  .topbar, .no-print, .btn { display: none !important; }
  body { background: #fff; }
  .card { border: 0; }
}

.visit-entry { border-bottom: 1px dashed var(--line); padding-bottom: .75rem; margin-bottom: .75rem; }
.visit-entry .field.req label::after { content: ""; }

.activity { display: inline-flex; flex-wrap: wrap; gap: .25rem; }
.act-PHONE { background: #e3effd; color: #1a56a8; }
.act-WHATSAPP { background: #e4f4ea; color: var(--ok); }
.act-EMAIL { background: #eef1f5; color: var(--muted); }
.act-ONSITE { background: #fff1d6; color: #8a5300; }
.act-OTHER { background: #eef1f5; color: var(--muted); }

.back-link { display: inline-flex; align-items: center; gap: .3rem; margin-bottom: .6rem; font-weight: 600; font-size: .95rem; padding: .3rem .1rem; }
.range-error { color: var(--bad); font-size: .85rem; margin-top: .2rem; }

.cover-box { border-left: 5px solid var(--line); }
.cover-box.cover-warranty { border-left-color: var(--ok); }
.cover-box.cover-amc { border-left-color: #0b6f8c; }
.cover-box.cover-none { border-left-color: var(--bad); }
.cover-box dl.kv { grid-template-columns: 210px 1fr; }
.cov-expiring { background: #fff1d6; color: var(--warn); }
