/* Isleox Bridge — compact. Warm paper and ink, one sea-green accent.
   Colours use light-dark(); the active scheme comes from the system,
   or from data-theme on <html> once the person picks one (theme.js). */

:root {
  color-scheme: light dark;

  --bg:           light-dark(#f6f5f1, #121311);
  --surface:      light-dark(#ffffff, #1a1b19);
  --surface-2:    light-dark(#f0eee8, #232421);
  --text:         light-dark(#1d1c19, #ecebe6);
  --muted:        light-dark(#67645c, #a6a39a);
  --faint:        light-dark(#8f8b81, #7c796f);
  --line:         light-dark(#e5e2da, #2a2b28);
  --line-strong:  light-dark(#d0ccc1, #3b3c38);

  --accent:       light-dark(#1d6b59, #63c3a6);
  --accent-hover: light-dark(#165545, #84d2ba);
  --accent-text:  light-dark(#1a6352, #7ed0b6);
  --accent-soft:  light-dark(#e4f0ea, rgb(99 195 166 / .11));
  --accent-line:  light-dark(#c4ddd2, rgb(99 195 166 / .26));
  --on-accent:    light-dark(#ffffff, #0b1d17);

  --danger:       light-dark(#b23d2c, #f2907e);
  --danger-soft:  light-dark(#fbede9, rgb(242 144 126 / .1));
  --danger-line:  light-dark(#f0d0c8, rgb(242 144 126 / .26));

  --shadow-sm:    0 1px 2px light-dark(rgb(40 36 26 / .05), rgb(0 0 0 / .3));
  --shadow:       0 1px 2px light-dark(rgb(40 36 26 / .04), rgb(0 0 0 / .3)),
                  0 8px 24px -12px light-dark(rgb(40 36 26 / .14), rgb(0 0 0 / .6));

  --radius-sm: 6px;
  --radius: 10px;
  --control: 1.875rem;   /* 30px: buttons */
  --field: 2.125rem;     /* 34px: inputs */
  --header: 3rem;
  --sans: Inter, "Geist", "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-size: .875rem;
}
h1, h2, h3, p, dl, dd { margin: 0; }
[hidden] { display: none !important; }
a { color: var(--accent-text); text-underline-offset: .2em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); }
button, input { font: inherit; color: inherit; }
form { margin: 0; }
::selection { background: var(--accent-soft); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.wrap {
  width: min(100% - 2rem, 56rem);
  margin-inline: auto;
}

.icon {
  width: 1rem;
  height: 1rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  min-height: var(--header);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  color: var(--text);
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: -.01em;
  text-decoration: none;
}
.brand:hover { color: var(--text); }
.brand-sub { color: var(--muted); font-weight: 500; }

.brand-mark { width: 1.5rem; height: 1.5rem; margin-right: .25rem; flex: none; }

.header-actions { display: flex; align-items: center; gap: .25rem; }

/* ---------- Buttons ---------- */

button, .quiet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-height: var(--control);
  padding: .25rem .7rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: .8125rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .12s, border-color .12s, color .12s;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .12);
}
.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.secondary {
  background: var(--surface);
  border-color: var(--line-strong);
}
.secondary:hover { background: var(--surface-2); }

.quiet { color: var(--muted); }
.quiet:hover { background: var(--surface-2); color: var(--text); }
.quiet.danger { color: var(--danger); }
.quiet.danger:hover { background: var(--danger-soft); color: var(--danger); }

.block { width: 100%; min-height: var(--field); }

.icon-button {
  width: var(--control);
  padding: 0;
  color: var(--muted);
}
.icon-button:hover { color: var(--text); background: var(--surface-2); }

/* Show the icon for the theme you would switch to. */
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

/* ---------- Surfaces & form controls ---------- */

.surface {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

input:not([type=hidden]) {
  width: 100%;
  min-width: 0;
  height: var(--field);
  padding: 0 .65rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .875rem;
  font-weight: 400;
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder { color: var(--faint); }
input:hover { border-color: color-mix(in srgb, var(--line-strong) 60%, var(--muted)); }
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:-webkit-autofill { -webkit-text-fill-color: var(--text); box-shadow: 0 0 0 100px var(--surface) inset; }

.notice {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  padding: .5rem .7rem;
  margin-block: .75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: .8125rem;
}
.notice .icon { margin-top: .1rem; width: .95rem; height: .95rem; }
.error { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }

/* ---------- Sign in / register ---------- */

.credentials {
  display: grid;
  justify-items: center;
  align-content: start;
  min-height: calc(100dvh - var(--header));
  padding-block: clamp(2rem, 14vh, 7rem) 2rem;
}

.auth-card {
  width: min(100%, 21.5rem);
  padding: 1.35rem 1.4rem 1.1rem;
  box-shadow: var(--shadow);
}

.auth-head { display: grid; gap: .15rem; }
.auth-card h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: -.015em; line-height: 1.35; }
.lede { color: var(--muted); font-size: .8125rem; }

.auth-form { display: grid; gap: .75rem; margin-top: 1rem; }
.auth-form button { margin-top: .25rem; }
.field { display: grid; gap: .3rem; }
.field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: .8rem;
  font-weight: 600;
}
.field-hint { color: var(--faint); font-size: .75rem; font-weight: 400; }

.auth-switch {
  margin-top: 1rem;
  padding-top: .85rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .8125rem;
  text-align: center;
}
.auth-switch a { font-weight: 600; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

/* ---------- Dashboard ---------- */

.dashboard { padding-block: 1.5rem 3rem; }

.page-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem 1rem;
  margin-bottom: 1rem;
}
.page-title h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.3; }

.account-email {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  min-width: 0;
  max-width: 100%;
  color: var(--muted);
  font-size: .8125rem;
}
.account-email .icon { width: .9rem; height: .9rem; color: var(--faint); }
.account-email span { overflow-wrap: anywhere; }

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  min-width: 0;
  padding: .7rem .9rem .75rem;
}
.stat + .stat { border-left: 1px solid var(--line); }
.stat dt { color: var(--muted); font-size: .75rem; }
.stat-value {
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -.015em;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.stat-unit { margin-left: .3em; color: var(--faint); font-size: .75rem; font-variant-numeric: tabular-nums; }

.meter {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  height: 3px;
  margin-top: .3rem;
  border: 0;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}
.meter::-webkit-progress-bar { background: var(--surface-2); border-radius: 99px; }
.meter::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
.meter::-moz-progress-bar { background: var(--accent); border-radius: 99px; }

.last-sync {
  padding-top: .2rem;
  font-size: .8125rem;
  font-weight: 600;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
.last-sync.empty { color: var(--faint); font-weight: 400; }

/* ---------- Keys ---------- */

.admin-stats, .keys { margin-top: 1.5rem; }
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .15rem .75rem;
  margin-bottom: .6rem;
}
.section-head h2 { font-size: .95rem; font-weight: 680; }
.section-head p { color: var(--faint); font-size: .75rem; }

.key-list { overflow: hidden; }

.key-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: .75rem;
  padding: .65rem .9rem;
}
.key-row + .key-row { border-top: 1px solid var(--line); }
.key-row.isolated-row { grid-template-columns: minmax(0, 1fr) auto; }
.isolated-row code { overflow-wrap: anywhere; }

.key-icon {
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--faint);
}
.key-icon .icon { width: .9rem; height: .9rem; }
.key-icon.active { background: var(--accent-soft); color: var(--accent-text); }

.key-title { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .45rem; }
.key-title h3 { font-size: .85rem; font-weight: 650; }
.key-info p { color: var(--muted); font-size: .75rem; }
.key-info .key-meta { margin-top: .1rem; color: var(--faint); }

.key-status {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: 0 .4rem;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--faint);
  font-size: .6875rem;
  font-weight: 600;
  line-height: 1.6;
}
.key-status::before {
  content: '';
  width: .35rem;
  height: .35rem;
  border-radius: 50%;
  background: currentColor;
  opacity: .7;
}
.key-status.active { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-text); }
.key-status.active::before { opacity: 1; }
.key-status.off { color: var(--danger); border-color: var(--danger-line); background: var(--danger-soft); }
.key-status.empty { border-style: dashed; }

.prefix {
  padding: 0 .35rem;
  background: var(--surface-2);
  border-radius: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .72rem;
  line-height: 1.6;
}

.key-actions { display: flex; align-items: center; gap: .25rem; }

/* ---------- Newly issued key (shown once, inside its row) ---------- */

.key-row.is-fresh { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }

.key-reveal {
  grid-column: 2 / -1;
  padding: .6rem .7rem .65rem;
  background: var(--surface);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-sm);
}
.reveal-title {
  display: flex;
  align-items: center;
  gap: .35rem;
  color: var(--accent-text);
  font-size: .8rem;
  font-weight: 650;
}
.reveal-title .icon { width: .9rem; height: .9rem; }
.reveal-hint { margin-top: .1rem; color: var(--muted); font-size: .75rem; }

.copy-row { display: flex; gap: .4rem; margin-top: .5rem; }
.copy-row input { font-family: var(--mono); font-size: .8rem; background: var(--surface-2); }
.copy-row button { min-height: var(--field); min-width: 4.25rem; }
.copy-status:not(:empty) {
  display: block;
  margin-top: .3rem;
  color: var(--accent-text);
  font-size: .75rem;
  font-weight: 550;
}

/* ---------- Responsive ---------- */

@media (max-width: 44rem) {
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(odd) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
}

@media (max-width: 32rem) {
  .wrap { width: calc(100% - 1.5rem); }
  .dashboard { padding-top: 1.1rem; }
  .key-row { gap: .6rem; padding-inline: .75rem; }
  .key-actions button { padding-inline: .55rem; }
  .copy-row { flex-direction: column; }
  .key-reveal { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
