/* assets/ios.css — shared visual system for the FEX Driver Hub
 *
 * Apple-style (iOS / iPadOS) treatment shared by every page:
 *   • system font stack (SF Pro on Apple devices)
 *   • light + dark palettes driven by CSS tokens
 *   • appearance follows the device by default; assets/shell.js stamps
 *     data-theme="light" | "dark" on <html> when the user picks one
 *   • rail navigation, buttons, cards, segmented controls, forms,
 *     modals, toasts, tables
 *
 * Page-specific styles live in each page's own <style> block and build
 * on the tokens and components defined here.
 */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── TOKENS ─────────────────────────────────────────────────────── */
:root {
  /* iOS light system palette */
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --card2: #F2F2F7;
  --fill: #E5E5EA;
  --fill2: #D1D1D6;
  --label: #1C1C1E;
  --label2: rgba(60, 60, 67, .6);
  --label3: rgba(60, 60, 67, .3);
  --sep: rgba(60, 60, 67, .18);
  --blue: #007AFF;   --blue-soft: rgba(0, 122, 255, .12);
  --orange: #FF9500; --orange-soft: rgba(255, 149, 0, .14);
  --green: #34C759;  --green-soft: rgba(52, 199, 89, .14);
  --red: #FF3B30;    --red-soft: rgba(255, 59, 48, .12);
  --purple: #AF52DE; --purple-soft: rgba(175, 82, 222, .13);
  --yellow: #FFCC00; --yellow-soft: rgba(255, 204, 0, .18);
  --on-accent: #FFFFFF;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .05);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .22);
  --overlay: rgba(0, 0, 0, .35);
  --r-xl: 22px; --r-lg: 18px; --r-md: 14px; --r-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card: #1C1C1E;
    --card2: #2C2C2E;
    --fill: #3A3A3C;
    --fill2: #48484A;
    --label: #FFFFFF;
    --label2: rgba(235, 235, 245, .6);
    --label3: rgba(235, 235, 245, .3);
    --sep: rgba(84, 84, 88, .6);
    --blue: #0A84FF;   --blue-soft: rgba(10, 132, 255, .18);
    --orange: #FF9F0A; --orange-soft: rgba(255, 159, 10, .18);
    --green: #30D158;  --green-soft: rgba(48, 209, 88, .18);
    --red: #FF453A;    --red-soft: rgba(255, 69, 58, .18);
    --purple: #BF5AF2; --purple-soft: rgba(191, 90, 242, .18);
    --yellow: #FFD60A; --yellow-soft: rgba(255, 214, 10, .16);
    --shadow: none;
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
    --overlay: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --card: #1C1C1E;
  --card2: #2C2C2E;
  --fill: #3A3A3C;
  --fill2: #48484A;
  --label: #FFFFFF;
  --label2: rgba(235, 235, 245, .6);
  --label3: rgba(235, 235, 245, .3);
  --sep: rgba(84, 84, 88, .6);
  --blue: #0A84FF;   --blue-soft: rgba(10, 132, 255, .18);
  --orange: #FF9F0A; --orange-soft: rgba(255, 159, 10, .18);
  --green: #30D158;  --green-soft: rgba(48, 209, 88, .18);
  --red: #FF453A;    --red-soft: rgba(255, 69, 58, .18);
  --purple: #BF5AF2; --purple-soft: rgba(191, 90, 242, .18);
  --yellow: #FFD60A; --yellow-soft: rgba(255, 214, 10, .16);
  --shadow: none;
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
  --overlay: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ── BASE ───────────────────────────────────────────────────────── */
html, body { background: var(--bg); }
body {
  font-family: var(--font);
  color: var(--label);
  font-size: 15px;
  line-height: 1.35;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* Inline SVG icons (see assets/shell.js) */
.ico { width: 1em; height: 1em; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; display: inline-block; vertical-align: -.15em; }

/* ── APP SHELL + RAIL ───────────────────────────────────────────── */
#appShell { display: none; }
#appShell.ready { display: flex; }

.rail {
  width: 76px; background: var(--card); border-right: 1px solid var(--sep);
  display: flex; flex-direction: column; align-items: center;
  padding: 18px 0 16px; gap: 4px; flex-shrink: 0;
  position: sticky; top: 0; height: 100vh;
}
.rail .logo { width: 44px; height: 44px; border-radius: 12px; background: #fff; border: 1px solid var(--sep); display: flex; align-items: center; justify-content: center; margin-bottom: 12px; overflow: hidden; flex-shrink: 0; }
.rail .logo img { width: 34px; display: block; }
.rail-btn {
  width: 56px; height: 52px; border-radius: 14px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px; color: var(--label2);
  cursor: pointer; transition: background .18s, color .18s; text-decoration: none;
}
.rail-btn .ico { width: 22px; height: 22px; stroke-width: 1.8; }
.rail-btn small { font-size: 9px; font-weight: 600; letter-spacing: .01em; line-height: 1; }
.rail-btn:hover { background: var(--card2); color: var(--label); }
.rail-btn.active { color: var(--blue); }
.rail-btn.active .ico { stroke-width: 2.2; }
.rail-spacer { flex: 1; }
.rail-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--blue-soft); color: var(--blue);
  display: flex; align-items: center; justify-content: center; text-decoration: none; flex-shrink: 0;
}
.rail-avatar .ico { width: 18px; height: 18px; }
.rail-avatar.guest { background: var(--fill); color: var(--label2); }
.rail-avatar.guest:hover { color: var(--blue); }

/* Appearance toggle (Auto / Light / Dark) */
.theme-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--fill);
  color: var(--label2); display: flex; align-items: center; justify-content: center;
  margin-bottom: 8px; transition: color .18s, background .18s;
}
.theme-btn .ico { width: 18px; height: 18px; }
.theme-btn:hover { color: var(--blue); }

/* ── MAIN + TOPBAR ──────────────────────────────────────────────── */
.main-wrap { flex: 1; padding: 24px 32px 44px; max-width: 1500px; min-width: 0; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 18px; flex-wrap: wrap; }
.greet .eyebrow { font-size: 13px; font-weight: 600; color: var(--label2); margin-bottom: 4px; }
.greet h1 { font-size: 34px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; color: var(--label); text-wrap: balance; }
.greet p { font-size: 15px; color: var(--label2); margin-top: 6px; max-width: 62ch; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── BUTTONS ────────────────────────────────────────────────────── */
.btn {
  border: none; cursor: pointer; font-weight: 600; font-size: 15px; padding: 10px 16px;
  border-radius: 12px; transition: background .18s, color .18s, filter .18s, transform .1s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; line-height: 1;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn .ico { width: 16px; height: 16px; stroke-width: 2.2; }
.btn-ghost, .btn-secondary { background: var(--blue-soft); color: var(--blue); }
.btn-ghost:hover, .btn-secondary:hover { background: color-mix(in srgb, var(--blue) 22%, transparent); }
.btn-primary { background: var(--blue); color: var(--on-accent); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: color-mix(in srgb, var(--red) 24%, transparent); }
.btn-plain { background: transparent; color: var(--blue); }
.btn-plain:hover { background: var(--blue-soft); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn-icon { padding: 7px 9px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  background: transparent; border: none; color: var(--blue); width: 30px; height: 30px; border-radius: 50%;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: background .15s; padding: 0;
}
.icon-btn .ico { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--blue-soft); }
.icon-btn.danger { color: var(--red); }
.icon-btn.danger:hover { background: var(--red-soft); }

/* ── SURFACES ───────────────────────────────────────────────────── */
.card { background: var(--card); border-radius: var(--r-xl); box-shadow: var(--shadow); }

/* Segmented control — the iOS pill row with a raised selected segment */
.seg { display: inline-flex; background: var(--fill); border-radius: 10px; padding: 2px; gap: 2px; max-width: 100%; }
.seg > * {
  background: transparent; border: none; color: var(--label); font-size: 13px; font-weight: 600;
  padding: 6px 14px; border-radius: 8px; cursor: pointer; transition: background .15s, box-shadow .15s;
  user-select: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.seg > .on, .seg > .active { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .14); }
.seg.wide > * { flex: 1; }

/* Search field + select */
.search-wrap { position: relative; flex: 1; min-width: 180px; }
.search-wrap input {
  width: 100%; padding: 9px 14px 9px 34px; border: none; border-radius: 11px; font-size: 15px;
  background: var(--fill); color: var(--label); outline: none; transition: box-shadow .2s;
}
.search-wrap input::placeholder { color: var(--label3); }
.search-wrap input:focus { box-shadow: 0 0 0 3px var(--blue-soft); }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--label3); pointer-events: none; display: flex; }
.search-icon .ico { width: 16px; height: 16px; stroke-width: 2.2; }
.sort-select {
  padding: 9px 32px 9px 12px; border: none; border-radius: 11px; font-size: 14px; font-weight: 500;
  background: var(--fill); color: var(--label); outline: none; cursor: pointer; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 9l5-5 5 5M7 15l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
.sort-select:focus { box-shadow: 0 0 0 3px var(--blue-soft); }
.record-count { color: var(--label2); font-size: 13px; font-weight: 500; margin-left: auto; font-variant-numeric: tabular-nums; }

/* Status / type tags */
.tag { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 6px; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.tag-blue   { background: var(--blue-soft);   color: var(--blue); }
.tag-green  { background: var(--green-soft);  color: var(--green); }
.tag-orange { background: var(--orange-soft); color: var(--orange); }
.tag-red    { background: var(--red-soft);    color: var(--red); }
.tag-purple { background: var(--purple-soft); color: var(--purple); }
.tag-gray   { background: var(--fill);        color: var(--label2); }

/* ── TABLES ─────────────────────────────────────────────────────── */
.table-wrap { background: var(--card); border-radius: var(--r-xl); box-shadow: var(--shadow); overflow: auto; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table-wrap thead tr { background: var(--card); }
.table-wrap th {
  padding: 12px 16px; text-align: left; font-weight: 600; font-size: 12px; color: var(--label2);
  text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--sep); white-space: nowrap; user-select: none;
}
.table-wrap th[onclick] { cursor: pointer; }
.table-wrap th[onclick]:hover, .table-wrap th.sorted { color: var(--blue); }
.table-wrap tbody tr { border-bottom: 1px solid var(--sep); transition: background .15s; }
.table-wrap tbody tr:last-child { border-bottom: none; }
.table-wrap tbody tr:hover { background: var(--card2); }
.table-wrap td { padding: 13px 16px; vertical-align: middle; }
.table-wrap td.name-cell { font-weight: 600; color: var(--label); }
.table-wrap td.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-wrap td.muted { color: var(--label3); }
.action-cell { display: flex; gap: 6px; justify-content: flex-end; }
.empty-row td { padding: 48px 20px; text-align: center; color: var(--label2); font-size: 15px; }

/* ── FORMS ──────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--label2); }
.form-group input, .form-group select, .form-group textarea {
  padding: 11px 13px; border: none; border-radius: var(--r-sm); font-size: 16px;
  outline: none; background: var(--card2); color: var(--label); transition: box-shadow .2s; width: 100%;
}
.form-group input::placeholder, .form-group textarea::placeholder { color: var(--label3); }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { box-shadow: 0 0 0 3px var(--blue-soft); }
.form-group input:disabled { color: var(--label3); cursor: not-allowed; }
.form-group textarea { resize: vertical; min-height: 72px; line-height: 1.45; }
.form-group select { appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 9l5-5 5 5M7 15l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.error-msg { color: var(--red); font-size: 13px; font-weight: 500; }
.error-msg:empty { display: none; }

/* Type / frequency toggles inside forms behave like segmented controls */
.type-toggle-row, .freq-toggle-row { display: flex; background: var(--fill); border-radius: 10px; padding: 2px; gap: 2px; }
.type-toggle, .freq-toggle {
  flex: 1; padding: 8px 0; text-align: center; background: transparent; border: none; border-radius: 8px;
  color: var(--label); font-size: 13px; font-weight: 600; cursor: pointer; transition: background .15s, box-shadow .15s; user-select: none;
}
.type-toggle.active, .freq-toggle.active { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .14); }

/* ── MODALS + CONFIRM ───────────────────────────────────────────── */
.modal-overlay, .confirm-overlay {
  position: fixed; inset: 0; background: var(--overlay);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px; animation: fadeIn .15s ease;
}
.confirm-overlay { z-index: 300; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(16px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal {
  background: var(--card); border-radius: var(--r-xl); padding: 26px 28px 24px; width: 100%; max-width: 540px;
  box-shadow: var(--shadow-lg); animation: slideUp .2s ease; max-height: 90vh; overflow-y: auto;
}
.modal h2 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; color: var(--label); margin-bottom: 18px; }
.modal-sub { font-size: 14px; color: var(--label2); line-height: 1.5; margin: -10px 0 18px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.confirm-box {
  background: var(--card); border-radius: var(--r-xl); padding: 24px 24px 20px; max-width: 360px; width: 100%;
  box-shadow: var(--shadow-lg); animation: slideUp .2s ease; text-align: center;
}
.confirm-box h3 { font-size: 19px; font-weight: 700; letter-spacing: -.01em; color: var(--label); margin-bottom: 8px; }
.confirm-box p { font-size: 14px; color: var(--label2); margin-bottom: 20px; line-height: 1.5; }
.confirm-actions { display: flex; gap: 8px; }
.confirm-actions .btn { flex: 1; padding: 12px; }

.info-row { margin-bottom: 14px; }
.info-row:last-child { margin-bottom: 0; }
.info-label { font-size: 12px; font-weight: 600; color: var(--label2); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.info-value { font-size: 15px; color: var(--label); line-height: 1.55; white-space: pre-wrap; }
.info-hint { font-size: 13px; color: var(--label2); line-height: 1.5; margin-top: 14px; }

/* ── TOAST + LOADING ────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 80px);
  background: var(--card); color: var(--label); border-radius: 999px; padding: 12px 20px; font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .18); border: 1px solid var(--sep); opacity: 0; transition: transform .3s ease, opacity .3s ease; z-index: 999;
  max-width: calc(100vw - 32px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast.success { color: var(--blue); }
#toast.danger, #toast.error { color: var(--red); }

#loadingBanner {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--orange-soft); color: var(--orange); border-radius: var(--r-md);
  padding: 10px 20px; font-size: 13px; font-weight: 600; margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 1s linear infinite; display: inline-block; }

/* ── RESPONSIVE RAIL ────────────────────────────────────────────── */
@media (max-width: 1150px) {
  .main-wrap { padding: 22px 22px 40px; }
}
@media (max-width: 620px) {
  #appShell.ready { flex-direction: column; }
  .rail {
    width: 100%; flex-direction: row; height: 60px; padding: 0 10px; gap: 2px; border-right: none;
    border-bottom: 1px solid var(--sep); position: sticky; top: 0; z-index: 20;
    background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: saturate(180%) blur(18px); -webkit-backdrop-filter: saturate(180%) blur(18px);
  }
  .rail .logo { width: 34px; height: 34px; margin-bottom: 0; border-radius: 9px; margin-right: 4px; }
  .rail .logo img { width: 26px; }
  .rail-btn { width: 44px; height: 44px; border-radius: 12px; }
  .rail-btn small { display: none; }
  .rail-avatar { width: 32px; height: 32px; }
  .theme-btn { width: 32px; height: 32px; margin: 0 4px 0 0; }
  .main-wrap { padding: 18px 14px 34px; }
  .greet h1 { font-size: 30px; }
  .topbar { flex-direction: column; align-items: stretch; gap: 14px; }
  .top-actions .btn { flex: 1; padding: 12px 8px; font-size: 13px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { padding: 22px 18px 20px; }
}
