/* ELS Connector design system — Apple-style, light & dark.
   Tokens follow iOS semantic colors; every page uses only these variables. */

:root {
  color-scheme: light;
  --bg: #f2f2f7;               /* grouped background */
  --bg-elev: #ffffff;          /* cards, sheets */
  --bg-elev2: #f7f7fa;         /* rows inside cards */
  --fill: rgba(120, 120, 128, 0.12);
  --fill-2: rgba(120, 120, 128, 0.08);
  --ink: #1c1c1e;
  --ink-2: rgba(60, 60, 67, 0.62);
  --ink-3: rgba(60, 60, 67, 0.32);
  --line: rgba(60, 60, 67, 0.13);
  --accent: #007aff;   --accent-bg: rgba(0, 122, 255, 0.12);
  --ok: #248a3d;       --ok-solid: #34c759; --ok-bg: rgba(52, 199, 89, 0.15);
  --err: #d70015;      --err-solid: #ff3b30; --err-bg: rgba(255, 59, 48, 0.12);
  --warn: #b25000;     --warn-solid: #ff9500; --warn-bg: rgba(255, 149, 0, 0.16);
  --indigo: #5856d6;
  --chrome: rgba(249, 249, 251, 0.74);
  --chrome-line: rgba(60, 60, 67, 0.12);
  --scrim: rgba(0, 0, 0, 0.32);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 20px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.06), 0 18px 48px rgba(0, 0, 0, 0.12);
  --radius: 16px; --radius-sm: 10px; --radius-lg: 22px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --spring: cubic-bezier(0.32, 0.72, 0, 1); /* critically damped feel */

  /* aliases used by older page styles */
  --panel: var(--bg-elev); --panel2: var(--bg-elev2); --muted: var(--ink-2);
  --busy: var(--accent); --busy-bg: var(--accent-bg); --blue: var(--accent); --blue-bg: var(--accent-bg);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --bg-elev: #1c1c1e;
  --bg-elev2: #2c2c2e;
  --fill: rgba(118, 118, 128, 0.24);
  --fill-2: rgba(118, 118, 128, 0.16);
  --ink: #ffffff;
  --ink-2: rgba(235, 235, 245, 0.62);
  --ink-3: rgba(235, 235, 245, 0.3);
  --line: rgba(84, 84, 88, 0.6);
  --accent: #0a84ff;   --accent-bg: rgba(10, 132, 255, 0.2);
  --ok: #30d158;       --ok-solid: #30d158; --ok-bg: rgba(48, 209, 88, 0.18);
  --err: #ff453a;      --err-solid: #ff453a; --err-bg: rgba(255, 69, 58, 0.2);
  --warn: #ff9f0a;     --warn-solid: #ff9f0a; --warn-bg: rgba(255, 159, 10, 0.2);
  --indigo: #5e5ce6;
  --chrome: rgba(22, 22, 24, 0.72);
  --chrome-line: rgba(255, 255, 255, 0.08);
  --scrim: rgba(0, 0, 0, 0.55);
  --shadow-sm: none;
  --shadow: 0 0 0 1px rgba(255, 255, 255, 0.04);
  --shadow-lg: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 24px 60px rgba(0, 0, 0, 0.6);
}

/* Ease light <-> dark instead of an abrupt brightness jump */
:root.theme-anim, :root.theme-anim * { transition: background-color 280ms var(--ease), color 280ms var(--ease), border-color 280ms var(--ease) !important; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.47 var(--font); letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 700; }
.large-title { font-size: 30px; line-height: 1.1; letter-spacing: -0.025em; font-weight: 800; }
.title { font-size: 20px; line-height: 1.2; letter-spacing: -0.02em; font-weight: 700; }
.headline { font-size: 17px; font-weight: 600; letter-spacing: -0.015em; }
.subhead, .muted { color: var(--ink-2); font-size: 13px; letter-spacing: 0; }
.caps { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); }
.mono { font-family: var(--mono); letter-spacing: 0; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- translucent top bar (content scrolls under it) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 20px; min-height: 56px;
  background: var(--chrome);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--chrome-line);
}
.topbar .brand { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }
.topbar .brand .dot { width: 22px; height: 22px; border-radius: 7px; background: linear-gradient(135deg, var(--accent), var(--indigo)); box-shadow: inset 0 0 0 1px rgba(255,255,255,.2); }
.topbar .sp { flex: 1; }
.topbar nav { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; }
.topbar nav a { color: var(--ink-2); font-size: 14px; font-weight: 500; padding: 6px 10px; border-radius: 8px; }
.topbar nav a:hover { color: var(--ink); background: var(--fill-2); }

/* ---------- segmented control ---------- */
.seg { display: inline-flex; padding: 2px; border-radius: 10px; background: var(--fill); gap: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 13px; font-weight: 600;
  padding: 6px 14px; border-radius: 8px; cursor: pointer; letter-spacing: -0.01em; min-height: 0;
  transition: background-color 200ms var(--ease), box-shadow 200ms var(--ease), transform 100ms ease-out;
}
.seg button:not(.on) { color: var(--ink-2); }
.seg button.on { background: var(--bg-elev); box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 0 0 0.5px rgba(0,0,0,.04); color: var(--ink); }
:root[data-theme="dark"] .seg button.on { background: #636366; }
.seg button:active { transform: scale(0.96); }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit; font-size: 14px; font-weight: 600; letter-spacing: -0.01em;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 0; cursor: pointer;
  background: var(--fill); color: var(--accent); text-decoration: none;
  transition: transform 100ms ease-out, background-color 160ms var(--ease), opacity 160ms;
}
button:hover, .btn:hover { background: var(--fill); filter: brightness(0.97); }
button:active, .btn:active { transform: scale(0.97); }
button:disabled { opacity: 0.4; pointer-events: none; }
button.primary, .btn.primary { background: var(--accent); color: #fff; }
button.ok, .btn.ok { background: var(--ok-solid); color: #fff; }
button.danger, .btn.danger { color: var(--err); }
button.plain, .btn.plain { background: transparent; }
button.big, .btn.big { min-height: 50px; font-size: 17px; border-radius: 14px; padding: 0 20px; }

/* ---------- inputs ---------- */
input, select, textarea {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--fill-2);
  border: 1px solid transparent; border-radius: var(--radius-sm); padding: 8px 12px; min-height: 36px;
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease), background-color 160ms;
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-bg); background: var(--bg-elev); }
select { appearance: none; -webkit-appearance: none; padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
input[type="checkbox"] { min-height: 0; width: 18px; height: 18px; accent-color: var(--accent); vertical-align: -3px; }
label { color: var(--ink-2); font-size: 13px; }

/* ---------- surfaces ---------- */
.card { background: var(--bg-elev); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.group { background: var(--bg-elev); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.group > .cell { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 48px; position: relative; }
.group > .cell + .cell::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--line); }

/* ---------- pills / badges ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; letter-spacing: 0;
  border-radius: 99px; padding: 2px 9px; background: var(--fill); color: var(--ink-2); white-space: nowrap; }
.pill.ok, .pill.delivered, .pill.fulfilled { background: var(--ok-bg); color: var(--ok); }
.pill.err, .pill.error, .pill.problem { background: var(--err-bg); color: var(--err); }
.pill.warn, .pill.returning, .pill.returned, .pill.els_created { background: var(--warn-bg); color: var(--warn); }
.pill.blue, .pill.in_transit { background: var(--accent-bg); color: var(--accent); }
.bin { display: inline-block; font-family: var(--mono); font-weight: 700; font-size: 12px; letter-spacing: 0;
  background: var(--ink); color: var(--bg-elev); padding: 1px 7px; border-radius: 6px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 8px 10px; letter-spacing: 0; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- theme switch ---------- */
.theme-switch { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--fill); }
.theme-switch button { min-height: 26px; padding: 0 9px; border-radius: 7px; background: transparent; color: var(--ink-2); font-size: 12px; font-weight: 600; }
.theme-switch button.on { background: var(--bg-elev); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
:root[data-theme="dark"] .theme-switch button.on { background: #636366; }
.theme-switch svg { width: 14px; height: 14px; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; z-index: 100;
  background: var(--ink); color: var(--bg-elev); padding: 10px 16px; border-radius: 14px; font-weight: 600; box-shadow: var(--shadow-lg);
  transition: transform 350ms var(--spring), opacity 200ms; pointer-events: none; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- accessibility ---------- */
:focus-visible { outline: 3px solid var(--accent-bg); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
  button:active, .btn:active, .seg button:active { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .topbar { background: var(--bg-elev); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  :root { --line: rgba(60, 60, 67, 0.4); --ink-2: rgba(60, 60, 67, 0.85); }
  :root[data-theme="dark"] { --line: rgba(235, 235, 245, 0.4); --ink-2: rgba(235, 235, 245, 0.85); }
  .card, .group { box-shadow: 0 0 0 1px var(--line); }
}
@media print {
  :root, :root[data-theme="dark"] { color-scheme: light; --bg: #fff; --bg-elev: #fff; --ink: #000; --ink-2: #444; --line: #ccc; }
  .topbar, .theme-switch, .no-print { display: none !important; }
  .card { box-shadow: none; }
}

/* Show / hide password */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 44px; }
.pw-wrap .pw-toggle { margin: 0; position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; padding: 0; border: 0; border-radius: 10px;
  background: transparent; color: var(--ink-2); display: grid; place-items: center; cursor: pointer; min-height: 0; box-shadow: none; }
.pw-toggle:hover { color: var(--ink); background: var(--fill); }
.pw-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pw-toggle svg { width: 20px; height: 20px; }
