/* Mex Estate — shared stylesheet. Light and dark via prefers-color-scheme. */
:root {
  --bg: #f7f3ee; --surface: #fffdf9; --ink: #1f2933; --muted: #5b6770; --line: #ddd5ca;
  --brand: #0f6b5c; --brand-ink: #ffffff; --accent: #c2541a; --err: #a12622; --ok: #1e6b34;
  --radius: 12px; --nav-h: 64px;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121619; --surface: #1a1f23; --ink: #e9e5df; --muted: #9aa5ad; --line: #2c3338;
    --brand: #3fb59d; --brand-ink: #0b1210; --accent: #f08a4b; --err: #ff8a80; --ok: #7fd18e; }
}
* { box-sizing: border-box; }
/* overflow-x on html, NOT body: a body scroll container would break the sticky navbar (AG-WEB 1.2). */
html { overflow-x: hidden; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: var(--brand); }
[hidden] { display: none !important; }
section[id], h2[id] { scroll-margin-top: calc(var(--nav-h) + 24px); }

/* ---- navbar ---- */
.navbar { position: sticky; top: 0; z-index: 1000; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: var(--nav-h); padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--line);
  transition: box-shadow 0.25s ease; }
.navbar.scrolled { box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12); }
.navbar-brand { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; color: inherit; text-decoration: none; }
.navbar-logo { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--brand);
  color: var(--brand-ink); font-weight: 800; letter-spacing: 0.5px; }
.navbar-brand-name { display: block; font-weight: 700; }
.navbar-brand-tagline { display: block; font-size: 12px; color: var(--muted); }
.navbar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.nav-user { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.nav-link { display: inline-flex; align-items: center; min-height: 40px; padding: 6px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink); font: inherit; text-decoration: none; cursor: pointer; }
.nav-link:hover, .nav-link:focus-visible { background: var(--surface); }
@media (max-width: 560px) { .navbar-brand-tagline { display: none; } .navbar { flex-wrap: wrap; } }

/* ---- language selector (markup from AG-WEB-STANDARDS 2.5) ---- */
.lang-selector-wrapper { position: relative; }
.lang-selector-btn { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 8px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); color: var(--ink); font: inherit; cursor: pointer; }
.lang-dropdown { position: absolute; top: calc(100% + 8px); right: 0; width: 280px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 18px 40px rgba(0, 0, 0, 0.2);
  overflow: hidden; opacity: 0; visibility: hidden; transform: translateY(-6px); transition: opacity 0.2s, transform 0.2s, visibility 0.2s; z-index: 1200; }
.lang-dropdown.active { opacity: 1; visibility: visible; transform: none; }
.lang-search { padding: 8px; border-bottom: 1px solid var(--line); }
.lang-search input { width: 100%; min-height: 40px; }
.lang-list { list-style: none; margin: 0; padding: 6px; max-height: 320px; overflow-y: auto; }
.lang-item { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.lang-item:hover, .lang-item.active { background: var(--bg); }
.lang-endonym { margin-left: auto; color: var(--muted); font-size: 13px; }

/* ---- layout ---- */
main { width: min(1100px, 100% - 32px); margin: 24px auto 48px; }
main.narrow { width: min(560px, 100% - 32px); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(16px, 4vw, 28px); margin-bottom: 20px; }
h1 { font-size: clamp(24px, 5vw, 32px); margin: 0 0 12px; }
h2 { font-size: 20px; margin: 0 0 12px; }
.lede, .muted { color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 20px; }

/* ---- forms ---- */
label { display: block; margin: 12px 0; font-weight: 600; }
label .hint { display: block; font-weight: 400; color: var(--muted); font-size: 14px; }
input, select, textarea { display: block; width: 100%; min-height: 44px; margin-top: 6px; padding: 8px 12px; font: inherit; color: inherit;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 400; min-height: 44px; }
label.check input { width: 22px; height: 22px; min-height: 0; margin: 0; }
.field-error { color: var(--err); font-size: 14px; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.actions.stack { display: grid; }
button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 16px; font: inherit;
  font-weight: 600; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; }
button.primary, .button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.danger { border-color: var(--err); color: var(--err); }
button:disabled { opacity: 0.6; cursor: progress; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.status { color: var(--muted); }
.error { color: var(--err); font-weight: 600; }
.ok { color: var(--ok); font-weight: 600; }
.dev-link { padding: 10px 12px; border: 1px dashed var(--accent); border-radius: 8px; word-break: break-all; }
.secret { padding: 10px 12px; border: 1px solid var(--accent); border-radius: 8px; word-break: break-all; font-family: ui-monospace, monospace; }

/* ---- lists and tables ---- */
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; }
.list li .meta { display: block; color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); white-space: nowrap; }
/* Phones: rows become labelled stacked cards (AG-APP Part 3). */
@media (max-width: 700px) {
  table.stack thead { display: none; }
  table.stack tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.stack td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 6px 12px; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 13px; }
}
.phone-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 8px; align-items: end;
  padding: 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; }
.phone-row label { margin: 0; }

/* ---- dialog ---- */
dialog { width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: clamp(16px, 4vw, 24px);
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
/* Hints and field errors sit just after their label (linked by aria-describedby), so they never become
   part of the input's accessible name. */
label + .hint, label + .field-error, .hint + .field-error { display: block; margin: -6px 0 10px; font-size: 14px; }
.hint { color: var(--muted); }
.actions .grow { flex: 1 1 260px; margin: 0; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 13px; border: 1px solid var(--line); }
.badge.off { border-color: var(--err); color: var(--err); }

/* ---- fixes from the visual review (2026-10-20) ---- */
/* Nav links are buttons too: keep them flat (the generic button rule above would box them). */
.navbar .nav-link { min-height: 40px; padding: 6px 10px; border: 0; background: transparent; font-weight: 500; }
/* Phones: brand + language on row 1; links on row 2. Nothing sits off-screen. */
@media (max-width: 560px) {
  .navbar { row-gap: 4px; padding: 6px 12px; }
  /* The language button joins the brand on row 1, so the links get all of row 2. */
  .navbar { flex-wrap: wrap; }
  .navbar-actions { display: contents; }
  .lang-selector-wrapper { order: 1; margin-left: auto; }
  .nav-user { order: 2; width: 100%; flex-wrap: wrap; justify-content: space-between; min-width: 0; }
  .nav-user .nav-link { white-space: nowrap; padding: 6px 8px; }
}
/* Search + "New user" row: align to the input, not stretch to the label. */
.actions:has(> .grow) { align-items: flex-end; margin-bottom: 16px; }
td { vertical-align: middle; }
td .actions { margin: 0; }
/* Two-column cards keep their own height instead of stretching to the taller column. */
.grid-2 { align-items: start; }
@media (max-width: 700px) {
  /* The actions cell needs no label on stacked phone rows. */
  table.stack td[data-label=""]::before { content: none; }
  table.stack td[data-label=""] { justify-content: flex-end; }
}
