/* MadeMech admin. Plain CSS, no build step. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --border-strong: #c9ced6;
  --text: #1c2430;
  --muted: #5f6b7a;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: #e8eefc;
  --good: #067647;
  --good-soft: #dcfae6;
  --warn: #b54708;
  --warn-soft: #fef0c7;
  --bad: #b42318;
  --bad-soft: #fee4e2;
  --radius: 8px;
  --sidebar: 220px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .75rem; }
code, pre { font-family: var(--mono); font-size: .85em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Layout */
body.admin { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: #111827; color: #d1d5db; padding: 1rem .75rem; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar__brand { color: #fff; font-weight: 700; font-size: 1.1rem; padding: .25rem .5rem 1rem; }
.sidebar__brand:hover { text-decoration: none; }
.sidebar__footer { margin-top: auto; padding: .75rem .5rem 0; border-top: 1px solid #1f2937; display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.sidebar .link-button { color: #d1d5db; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__heading { margin: 1rem .5rem .25rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: #6b7280; }
.nav__link { color: #d1d5db; padding: .4rem .5rem; border-radius: 6px; display: flex; justify-content: space-between; align-items: center; }
.nav__link:hover { background: #1f2937; text-decoration: none; }
.nav__link--active { background: #1f2937; color: #fff; }
.nav__count { background: var(--bad); color: #fff; border-radius: 999px; padding: 0 .45rem; font-size: .75rem; }
.main { padding: 1.5rem 2rem 3rem; max-width: 1280px; width: 100%; min-width: 0; }

.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-header__back { display: inline-block; font-size: .85rem; margin-bottom: .25rem; }
.page-header__actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.page-header h1 { margin: 0; }
.page-header p { margin: .25rem 0 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; min-width: 0; }
.card__header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: .5rem; flex-wrap: wrap; }
.card__header--sub { margin-top: 1rem; padding-top: .75rem; border-top: 1px solid var(--border); }
.card__header h2, .card__header h3 { margin: 0; }
.grid { display: grid; gap: 0 1rem; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid > .card { margin-bottom: 1rem; }
.grid.grid--2:has(> .card) { gap: 0 1rem; }
.stack > * + * { margin-top: .75rem; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; display: flex; flex-direction: column; color: var(--text); }
.stat:hover { text-decoration: none; border-color: var(--border-strong); }
.stat__value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat__label { color: var(--muted); font-size: .85rem; }
.stat--bad .stat__value { color: var(--bad); }

/* Tables and lists */
.table { width: 100%; border-collapse: collapse; }
.card > .table { margin: 0 -.25rem; width: calc(100% + .5rem); }
.table th, .table td { padding: .55rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.table tbody tr:last-child td, .table tbody tr:last-child th { border-bottom: 0; }
.table th.num, .table td.num { text-align: right; }
.table--compact th, .table--compact td { padding: .3rem .5rem; }
.table--compact tbody th { width: 1%; white-space: nowrap; font-weight: 400; }
.row--muted { opacity: .6; }
.row--diff td { background: var(--warn-soft); }
.actions { display: flex; gap: .75rem; align-items: center; justify-content: flex-end; white-space: nowrap; flex-wrap: wrap; }
td.actions { display: table-cell; text-align: right; }
td.actions > * { margin-left: .6rem; display: inline-block; vertical-align: middle; }
td.actions form { display: inline; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; justify-content: space-between; gap: 1rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.history { list-style: none; margin: 0; padding: 0; }
.history li { padding: .3rem 0; border-bottom: 1px dashed var(--border); }
.history li:last-child { border-bottom: 0; }
.history .muted:first-child { display: inline-block; min-width: 8.5rem; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 .75rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.empty { color: var(--muted); margin: .5rem 0; }
.note { background: var(--warn-soft); border-radius: 6px; padding: .5rem .75rem; }
.warnings { margin: .5rem 0 0; padding-left: 1.2rem; color: var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: .05rem .4rem; }
.code { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: .6rem .75rem; overflow-x: auto; white-space: pre; }

/* Badges */
.badge { display: inline-block; font-size: .75rem; line-height: 1.4; padding: .05rem .5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; vertical-align: 1px; margin-left: .25rem; }
.badge:first-child { margin-left: 0; }
.badge--good { background: var(--good-soft); border-color: transparent; color: var(--good); }
.badge--warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.badge--bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.freshness { white-space: nowrap; }
.whatsapp { color: #067647; }

/* Buttons */
.button, .link-button { font: inherit; cursor: pointer; }
.button { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); padding: .45rem .85rem; border-radius: 6px; font-weight: 500; line-height: 1.2; }
.button:hover { background: var(--bg); text-decoration: none; }
.button--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button--primary:hover { background: var(--accent-hover); }
.button--danger { color: var(--bad); border-color: var(--bad-soft); }
.button--danger:hover { background: var(--bad-soft); }
.button--ghost { border-color: transparent; background: transparent; }
.button--small { padding: .3rem .6rem; font-size: .85rem; }
.button--block { width: 100%; justify-content: center; }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); }
.link-button:hover { text-decoration: underline; }
.link-button--danger { color: var(--bad); }
form.button_to { display: inline; }
.card__header .actions form { display: inline; }

/* Forms */
.form .card h2 { margin-bottom: .75rem; }
.field { margin-bottom: .9rem; min-width: 0; }
.field > label { display: block; font-weight: 600; margin-bottom: .25rem; }
.field--check > label { display: flex; gap: .5rem; align-items: flex-start; font-weight: 500; }
.field--check input { margin-top: .2rem; }
.field--inline { align-self: end; padding-bottom: .5rem; }
.field__hint { color: var(--muted); font-size: .8rem; margin: .25rem 0 0; }
.field__error { color: var(--bad); font-size: .85rem; margin: .25rem 0 0; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=tel], input[type=url],
input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; font: inherit; color: inherit; padding: .45rem .6rem; border: 1px solid var(--border-strong); border-radius: 6px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field--error input, .field--error select, .field--error textarea { border-color: var(--bad); }
.form-actions { display: flex; gap: .5rem; margin-top: .5rem; flex-wrap: wrap; }
.danger-zone { margin: 1.5rem 0 0; }
.filters { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters > * { width: auto; }
.filters__search { flex: 1 1 280px; }
.decode-panel { background: var(--bg); border: 1px dashed var(--border-strong); border-radius: 6px; padding: .75rem; margin-bottom: 1rem; }
.map { height: 360px; border-radius: 6px; border: 1px solid var(--border); margin-bottom: .75rem; }

.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.tabs__tab { padding: .5rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs__tab:hover { text-decoration: none; color: var(--text); }
.tabs__tab--active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.pagination { display: flex; gap: .75rem; align-items: center; justify-content: flex-end; padding-top: .75rem; }

.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.flash ul { margin: .25rem 0 0; padding-left: 1.2rem; }
.flash p { margin: 0; }
.flash--notice { background: var(--accent-soft); color: #1e3a8a; }
.flash--alert { background: var(--bad-soft); color: var(--bad); }

/* Sign-in */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth__card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2rem; width: 100%; max-width: 380px; }
.auth__brand { font-size: 1.25rem; margin-bottom: 1.25rem; }

@media (max-width: 900px) {
  body.admin { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav__heading { display: none; }
  .main { padding: 1rem; }
  .grid--2, .grid--3 { grid-template-columns: 1fr; }
  .card { overflow-x: auto; }
}

/* WhatsApp conversation view */
.chat { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.chat__message { max-width: 70%; padding: .5rem .75rem; border-radius: 10px; }
.chat__message p { margin: 0 0 .25rem; }
.chat__message--inbound { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); }
.chat__message--outbound { align-self: flex-end; background: #dcf8c6; }
.chat__message--failed { outline: 2px solid var(--bad); }
.chat__meta { margin-top: .25rem; }

.inline-form { display: inline-flex; gap: .35rem; align-items: center; }
.input-small { width: 9rem !important; padding: .25rem .4rem !important; font-size: .85rem; }
