/* Reset, elements, topbar and side nav.
   Layer 2 of 5. Defines the plain selectors that overrides.css later
   intentionally re-declares. */

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: .94rem;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.role-admin,
body.role-vendor,
body.role-delivery_driver {
  --control-height: 34px;
  font-size: .9rem;
}

body.role-customer,
body.role-guest {
  --control-height: 38px;
  font-size: .95rem;
}

::selection { background: var(--accent-soft); color: var(--text); }

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 51;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .4rem clamp(.75rem, 2vw, 1.4rem);
  background: color-mix(in srgb, var(--card-bg) 94%, transparent);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(12px);
  transition: transform .2s ease;
}
.topbar.hidden { transform: translateY(-100%); }

.brand {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  color: var(--text);
  font-weight: 760;
  font-size: 1rem;
  letter-spacing: -.02em;
  white-space: nowrap;
}
.brand:hover { color: var(--text); text-decoration: none; }
.brand-mark {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: -.03em;
  box-shadow: 0 4px 12px var(--focus-ring);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: .3rem;
  margin-left: auto;
}

/* ── Side nav (single responsive drawer) ─────────── */
.side-menu {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  /* Must clear Leaflet's panes, which reach z-index 1000. */
  z-index: 1100;
  width: var(--rail-w);
  max-width: 82vw;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  padding: .7rem .6rem calc(.7rem + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  transform: translateX(-100%);
  visibility: hidden;
  transition: transform .22s ease, visibility .22s;
}
body.nav-rail-open .side-menu {
  transform: none;
  visibility: visible;
}
.side-menu a {
  display: flex;
  align-items: center;
  gap: .45rem;
  min-height: 40px;
  padding: .5rem .65rem;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 620;
  line-height: 1.25;
  transition: background .15s ease, color .15s ease;
}
.side-menu a:hover { text-decoration: none; color: var(--text); background: var(--surface-hover); }
.side-menu a.active { color: var(--primary); background: var(--accent-soft); font-weight: 700; }
.side-menu .who {
  margin-top: auto;
  padding: .6rem .65rem .1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .74rem;
}

/* Overlay backdrop for the narrow drawer only. On wide screens the rail is
   persistent and sits beside the content, so there is nothing to dim. */
.side-menu-scrim {
  position: fixed;
  inset: 0;
  z-index: 1099;
  background: rgba(24, 33, 47, .42);
  opacity: 0;
  visibility: hidden;
  transition: opacity .22s ease, visibility .22s;
}
:root[data-theme="dark"] .side-menu-scrim { background: rgba(0, 0, 0, .58); }

/* Wide screens: persistent rail. In-flow content is offset by the body
   padding; fixed elements need their own offset. */
@media (min-width: 901px) {
  body.nav-rail-open { padding-left: var(--rail-w); }
  body.nav-rail-open .mini-cart-bar { left: var(--rail-w); }
  /* Fixed overlays ignore the body's rail padding, so offset them by hand or
     the rail sits on top of the left edge. */
  body.nav-rail-open .map-sheet { left: var(--rail-w); }
}

/* Narrow screens: overlay drawer, content keeps full width. The rail class
   may still be set (it is the remembered desktop choice) but must not apply. */
@media (max-width: 900px) {
  body.nav-rail-open { padding-left: 0; }
  body.nav-rail-open .mini-cart-bar { left: 0; }
  body.nav-rail-open .map-sheet { left: 0; }
  body.nav-rail-open .side-menu { transform: translateX(-100%); visibility: hidden; }
  body.nav-open .side-menu { transform: none; visibility: visible; }
  body.nav-open .side-menu-scrim { opacity: 1; visibility: visible; }
}

.theme-form, .lang-form { margin: 0; display: inline-block; }
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.3rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
  border-radius: 6px;
  height: 32px;
}
.theme-toggle:hover { background: var(--surface-hover); }

.lang-dropdown{position:relative;display:inline-block;}
.lang-select{background:var(--card-bg);border:1px solid var(--border);color:var(--text);padding:0.3rem 0.5rem;border-radius:6px;font-size:0.85rem;cursor:pointer;height:32px;}
.lang-select:hover{background:var(--surface-hover);}
.lang-options{display:none;position:absolute;top:100%;right:0;margin-top:4px;background:var(--card-bg);border:1px solid var(--border);border-radius:6px;box-shadow:var(--shadow-md);z-index:100;min-width:120px;overflow:hidden;}
.lang-options.open{display:block;}
.lang-option{display:block;width:100%;padding:0.4rem 0.75rem;border:none;background:none;color:var(--text);font-size:0.85rem;text-align:left;cursor:pointer;white-space:nowrap;}
.lang-option:hover{background:var(--surface-hover);}
.lang-option.active{color:var(--primary);font-weight:600;}

main { width: 100%; max-width: 1180px; margin: 0 auto; padding: .9rem 1rem 4rem; }
body.role-customer main,
body.role-guest main { max-width: 960px; }

h1 { margin: .25rem 0 .8rem; font-size: 1.4rem; line-height: 1.2; letter-spacing: -.025em; }
h2 { margin: .85rem 0 .45rem; font-size: 1.08rem; line-height: 1.25; letter-spacing: -.015em; }
/* Dashboard sections: a quiet label above each group of order cards. */
.driver-section { margin: 1.1rem 0 .1rem; color: var(--muted); font-size: .74rem; font-weight: 680; letter-spacing: .05em; text-transform: uppercase; }
.driver-section + .order-cards { margin-top: .4rem; }
.driver-section-hint { margin: .1rem 0 0; font-size: .75rem; }
h3 { font-size: .96rem; line-height: 1.3; }

.view-toggle { display:inline-flex; align-items:center; gap:0.4rem; margin-left:auto; font-size:0.85rem; cursor:pointer; user-select:none; }
.view-toggle input { display:none; }
.view-toggle .track { width:36px; height:20px; background:var(--border); border-radius:999px; position:relative; transition:background 0.2s; }
.view-toggle input:checked + .track { background:var(--primary); }
.view-toggle .thumb { width:16px; height:16px; background:#fff; border-radius:50%; position:absolute; top:2px; left:2px; transition:left 0.2s; box-shadow:0 1px 3px rgba(0,0,0,0.2); }
.view-toggle input:checked + .track .thumb { left:18px; }

.flash {
  width: min(1180px, calc(100% - 2rem));
  margin: .65rem auto 0;
  padding: .55rem .8rem;
  background: var(--flash-bg);
  border: 1px solid var(--flash-border);
  border-radius: 7px;
  color: var(--flash-text);
  font-size: .86rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem;
  box-shadow: var(--shadow-sm);
}
body.role-admin .card,
body.role-vendor .card,
body.role-delivery_driver .card { padding: .72rem; }
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: .7rem; }
.card.narrow { max-width: 380px; margin: 1rem auto; }
.card.narrow form label { margin-bottom: .4rem; }
.card.narrow form input { margin-top: .12rem; }
.card.narrow .pw-wrap { margin-top: .12rem; }
.card h2 { margin: 0 0 .35rem; font-size: 1.3rem; color: var(--text); letter-spacing: -.02em; }
.card h2.order-title, .order-card h2.order-title, .order-title { margin: 0 0 .1rem; color: var(--text); font-size: .96rem; font-weight: 720; letter-spacing: -.01em; }
.order-title a { color: var(--primary); font-weight: 650; text-decoration: none; }
.order-title a:hover { text-decoration: underline; }

.vendor-card { display: block; color: var(--text); }
.vendor-card h2 { margin: 0 0 0.3rem; font-size: 1.1rem; color: var(--text); }

form label { display: block; margin-bottom: .58rem; color: var(--muted); font-size: .8rem; font-weight: 580; }
input[type="radio"], input[type="checkbox"] { accent-color: var(--primary); }
form input:not([type="radio"]):not([type="checkbox"]):not(.search-input), form textarea {
  display: block;
  width: 100%;
  margin-top: .18rem;
  padding: .4rem .55rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-subtle);
  color: var(--text);
  font-family: inherit;
  font-size: .88rem;
  line-height: 1.35;
}
form input:not([type="radio"]):not([type="checkbox"]):not([type="hidden"]):not(.search-input), form textarea { min-height: var(--control-height); }
form textarea { min-height: 5.5em; padding-top: .5rem; resize: vertical; }
form input:not([type="radio"]):not([type="checkbox"]):not([type="hidden"]):not(.search-input):hover, form textarea:hover, .select:hover, .input-sm:hover, .input-msg:hover { border-color: var(--border-strong); }
form input:not([type="radio"]):not([type="checkbox"]):not([type="hidden"]):not(.search-input):focus, form textarea:focus, .select:focus, .input-sm:focus, .input-msg:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  height: var(--control-height);
  padding: 0 .78rem;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--button-primary);
  color: #fff;
  font-size: .84rem;
  font-weight: 680;
  line-height: 1;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .1s ease, box-shadow .15s ease;
}
button:hover, .button:hover { background: var(--button-primary-hover); text-decoration: none; }
button:active, .button:active { transform: translateY(1px); }
button:focus-visible, .button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
button.danger { background: var(--button-danger); }
button.danger:hover { background: var(--button-danger-hover); }
