/* Shared base for every e-Tunisia app (Bab, Dorek, …). Colors come from tokens.css. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: var(--fs-md); line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}
:root[lang="ar"] body { line-height: 1.7; }
h1, h2, h3, p { margin: 0; }
a { color: var(--link); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2.5px solid var(--link); outline-offset: 3px; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.ltr { direction: ltr; unicode-bidi: isolate; }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 48px; padding: 0 20px; border-radius: var(--r-sm);
  border: 1px solid transparent; font-weight: 500; text-decoration: none; color: inherit; background: none;
  transition: background-color .15s, border-color .15s, transform .1s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover:not(:disabled) { background: var(--brand-deep); }
.btn-blue { background: var(--door); color: #fff; }
.btn-blue:hover:not(:disabled) { filter: brightness(1.08); }
.btn-quiet { background: var(--bg); border-color: var(--line); }
.btn-quiet:hover:not(:disabled) { background: var(--surface); }
.btn-ghost { color: var(--link); }
.btn-ghost:hover:not(:disabled) { background: var(--surface); }
.btn-danger { color: var(--brand); border-color: color-mix(in srgb, var(--brand) 30%, var(--line)); background: var(--bg); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: var(--fs-sm); border-radius: var(--r-xs); }

/* Forms */
.field { display: grid; gap: 6px; }
.field > span { font-size: var(--fs-sm); font-weight: 500; }
.field small { color: var(--muted); font-size: var(--fs-xs); }
.input, .field input, .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--link); box-shadow: 0 0 0 3px color-mix(in srgb, var(--link) 18%, transparent); }
.form-error { color: var(--brand); font-size: var(--fs-sm); min-height: 1.3em; }

/* Chips, avatars, cards */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 600; background: var(--surface); color: var(--text); white-space: nowrap;
}
.chip.warn { background: color-mix(in srgb, var(--kairouan) 20%, var(--bg)); }
.chip.off { background: var(--medina); color: #fff; }
.chip.ok::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--nabeul); }
.chip .ico { width: 14px; height: 14px; }
.avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--kairouan); color: #fff; font-weight: 600; font-size: var(--fs-xs); flex-shrink: 0; }
.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 24px; }

/* Top bar shared by apps */
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 600; }
.brand svg { width: 28px; height: 28px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: var(--fs-xs); line-height: 1.2; }
.topbar .spacer { flex: 1; }
/* Way back to the portal, at the start of every app's top bar */
.et-home { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px 5px 8px; border-radius: var(--r-pill); border: 1px solid var(--line); color: var(--muted); font-size: var(--fs-xs); font-weight: 600; text-decoration: none; white-space: nowrap; flex-shrink: 0; }
.et-home:hover { color: var(--text); background: var(--surface); }
.et-home svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }

.lang { display: flex; padding: 3px; border: 1px solid var(--line); border-radius: var(--r-pill); }
.lang button { border: 0; background: none; padding: 6px 11px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; color: var(--muted); }
.lang button[aria-pressed="true"] { background: var(--text); color: var(--bg); }

.toast {
  position: fixed; z-index: 90; left: 50%; bottom: 24px; transform: translate(-50%, 16px); opacity: 0;
  background: var(--medina); color: #fff; padding: 12px 18px; border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg); font-size: var(--fs-sm); max-width: 90vw; text-align: center;
  transition: opacity .2s, transform .2s; pointer-events: none;
}
:root[data-theme="dark"] .toast { background: #F4F6F9; color: var(--medina); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* The platform's signature: a Sidi Bou Said door arch with a studded border */
.arch {
  position: relative; background: var(--door); color: #fff;
  border-radius: 50% 50% var(--r-md) var(--r-md) / 42% 42% var(--r-md) var(--r-md);
  box-shadow: 0 0 0 8px var(--door-frame), 0 0 0 9px var(--line);
}
.arch::before {
  content: ""; position: absolute; inset: 14px; border-radius: inherit; pointer-events: none;
  border: 2px dotted rgba(10, 14, 22, .55);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}

/* Phones: keep top bars on one line */
.brand > span { white-space: nowrap; }
@media (max-width: 600px) {
  .topbar { padding: 10px 14px; gap: 8px; }
  .brand small, .hide-sm { display: none; }
  .et-home { padding: 6px; }
  .et-home span { display: none; }
  .topbar .lang button { padding: 6px 8px; }
}
