:root {
  color-scheme: dark;
  --bg: #0e1013;
  --panel: #15181d;
  --panel-2: #1a1e24;
  --line: #262b33;
  --text: #e8ebf0;
  --muted: #8b95a4;
  --amber: #ffb000;
  --amber-soft: #ffce63;
  --red: #ff3b30;
  --green: #36d36b;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%; /* don't let iOS inflate text on rotate */
  -webkit-tap-highlight-color: transparent; /* no grey flash when tapping links/buttons */
}
a { color: inherit; }

.app {
  max-width: 820px; /* fills iPad mini 6 (744pt) and most iPads in portrait, caps on desktop */
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

/* Header */
header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  /* env(safe-area-inset-top) keeps the header below the iOS status bar in the
     standalone PWA (status-bar-style is black-translucent, so we draw under it). */
  padding: calc(14px + env(safe-area-inset-top, 0px)) 18px 14px;
  background: rgba(15, 17, 20, 0.88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; justify-content: center; line-height: 1.15; }
.brand-name { font-weight: 700; letter-spacing: .04em; }
.brand-sub { font-family: var(--mono); font-size: 15px; font-weight: 700; color: var(--amber-soft); letter-spacing: .01em; margin-top: 3px; }
.spacer { flex: 1; }
nav.tabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
nav.tabs a { font-size: 13px; color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 7px; }
nav.tabs a.active { background: var(--amber); color: #1a1205; font-weight: 600; }
.icons { display: flex; gap: 6px; align-items: center; }
.logout-form { margin: 0; display: inline; }
.iconbtn { width: 34px; height: 34px; display: grid; place-items: center; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 9px; cursor: pointer; text-decoration: none; font-size: 15px; }
.iconbtn:hover, .iconbtn.active { color: var(--amber); border-color: #3a424f; }
.icon { width: 18px; height: 18px; display: block; }

main { flex: 1; }

/* Admin sub-tabs */
.subtabs { display: flex; gap: 18px; padding: 16px 18px 0; }
.subtabs a { font-size: 14px; color: var(--muted); text-decoration: none; padding-bottom: 10px; border-bottom: 2px solid transparent; }
.subtabs a.active { color: var(--text); border-color: var(--amber); font-weight: 600; }

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px; border-bottom: 1px solid var(--line); }
.panel-head-text { min-width: 0; }
.panel-head h2 { margin: 0; font-size: 17px; }
.btn-add { flex: none; font: inherit; font-size: 13px; font-weight: 700; color: #1a1205; background: var(--amber); border: 0; padding: 11px 18px; border-radius: 10px; cursor: pointer; white-space: nowrap; }
.btn-add:hover { background: var(--amber-soft); }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

/* Message stream */
.stream { padding: 10px 0 80px; }
.msg { padding: 13px 18px; border-bottom: 1px solid var(--line); position: relative; }
.msg:hover { background: var(--panel); }
.msg .meta { display: flex; align-items: baseline; gap: 10px; margin-bottom: 5px; }
.msg .sender { font-size: 13px; font-weight: 700; letter-spacing: .03em; color: var(--amber-soft); }
.msg .time { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.msg .body { font-size: 15.5px; line-height: 1.5; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.msg .arch { position: absolute; top: 11px; right: 14px; opacity: 0; transition: opacity .12s; }
.msg:hover .arch { opacity: 1; }
.ghost { font: inherit; font-size: 12px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); padding: 5px 10px; border-radius: 8px; cursor: pointer; }
.ghost:hover { color: var(--amber); border-color: #3a424f; }
.new-flash { animation: flash 1.2s ease; }
@keyframes flash { from { background: rgba(255, 176, 0, .16); } to { background: transparent; } }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; font-size: 14px; }

/* Scroll-aware "N new messages" pill */
.newpill {
  display: none;
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 22px;
  z-index: 25;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: #1a1205;
  background: var(--amber);
  border: 0;
  border-radius: 999px;
  padding: 9px 16px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .45);
  cursor: pointer;
}
.newpill.show { display: inline-flex; align-items: center; }
.newpill:hover { background: var(--amber-soft); }

/* Connection banner */
.banner { display: none; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 30; padding: 12px 18px; font-size: 13.5px; font-weight: 600; }
.banner.show { display: flex; }
.banner.reconnecting { background: rgba(255, 176, 0, .16); color: var(--amber-soft); border-bottom: 1px solid rgba(255, 176, 0, .4); }
.banner.lost { background: var(--red); color: #fff; }
.banner #bannerReload { margin-left: auto; font: inherit; font-size: 12.5px; font-weight: 700; border: 0; border-radius: 8px; padding: 6px 12px; cursor: pointer; background: rgba(255, 255, 255, .22); color: #fff; }
.banner.reconnecting #bannerReload { display: none; }

/* Forms / inputs */
label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px; letter-spacing: .03em; }
input[type=text], input[type=password], select {
  width: 100%; font: inherit; font-size: 14px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px;
}
input:focus, select:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px rgba(255, 176, 0, .18); }
.btn-primary { width: 100%; margin-top: 20px; font: inherit; font-size: 14px; font-weight: 700; color: #1a1205; background: var(--amber); border: 0; padding: 12px; border-radius: 10px; cursor: pointer; }
.btn-primary:hover { background: var(--amber-soft); }
.form-error { color: #ffd2cf; background: rgba(255, 59, 48, .12); border: 1px solid rgba(255, 59, 48, .4); border-radius: 9px; padding: 10px 12px; font-size: 13px; margin-top: 12px; }
.form-ok { color: #bdf0cf; background: rgba(54, 211, 107, .12); border: 1px solid rgba(54, 211, 107, .4); border-radius: 9px; padding: 10px 12px; font-size: 13px; }
.inset { margin: 16px 18px 0; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.card h2 { margin: 0 0 4px; font-size: 19px; }

/* Admin tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 12px 18px; border-bottom: 1px solid var(--line); }
td { padding: 13px 18px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
/* Shared column widths so the first (User/Name) and date (Last active/Last used)
   columns line up across the Users and Webhooks tables. The Role column shrinks to its
   chip; the actions column absorbs the remaining width and right-aligns the kebab, so
   it sits at the table's right edge in the same spot on every admin page. */
.col-name { width: 40%; }
.col-date { width: 28%; }
.col-role { width: 1%; white-space: nowrap; }
th.actions-col, td.actions { text-align: right; }
.chip { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.chip.admin { color: var(--amber); background: rgba(255, 176, 0, .12); border: 1px solid rgba(255, 176, 0, .3); }
.chip.user { color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); }
.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.inline .mini { width: 130px; padding: 7px 9px; font-size: 12.5px; }
.row-action { font: inherit; font-size: 12px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); padding: 6px 10px; border-radius: 7px; cursor: pointer; }
.row-action:hover { color: var(--amber); border-color: #3a424f; }
.row-action.danger { color: #ff8a82; border-color: rgba(255, 59, 48, .3); }
.row-action.danger:hover { color: #fff; background: rgba(255, 59, 48, .2); }
.row-action.primary { color: #1a1205; background: var(--amber); border-color: var(--amber); font-weight: 700; }
.row-action.primary:hover { color: #1a1205; background: var(--amber-soft); }

/* Row "burger" menu (native <details> popover) */
.rowmenu { position: relative; display: inline-block; }
.rowmenu > summary { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; list-style: none; }
.rowmenu > summary::-webkit-details-marker { display: none; }
.rowmenu > summary::marker { display: none; content: ""; }
.rowmenu > summary:hover, .rowmenu[open] > summary { color: var(--amber); border-color: #3a424f; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 184px; display: flex; flex-direction: column; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; box-shadow: 0 12px 30px rgba(0, 0, 0, .5); }
.menu form { display: contents; }
.menu-item { width: 100%; text-align: left; font: inherit; font-size: 13px; color: var(--text); background: transparent; border: 0; padding: 9px 11px; border-radius: 7px; cursor: pointer; }
.menu-item:hover { background: var(--panel-2); color: var(--amber); }
.menu-item.danger { color: #ff8a82; }
.menu-item.danger:hover { color: #fff; background: rgba(255, 59, 48, .16); }

/* Modal dialogs */
.modal { width: calc(100% - 32px); max-width: 420px; color: var(--text); text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; }
.modal::backdrop { background: rgba(0, 0, 0, .6); }
.modal h3 { margin: 0 0 8px; font-size: 16px; }
.modal-text { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.add-form, .settings-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; padding: 18px; }
.settings-form { flex-direction: column; align-items: stretch; max-width: 420px; }
.add-form .field { flex: 1; min-width: 140px; }
.add-form label, .settings-form label { margin-top: 0; }
/* iOS-style toggle switch (replaces a bare checkbox), label stacked above like other fields */
.field-toggle { display: flex; flex-direction: column; }
.toggle { display: flex; align-items: center; height: 42px; margin: 0; cursor: pointer; user-select: none; }
.toggle input { position: absolute; width: 0; height: 0; opacity: 0; }
.toggle .switch { position: relative; flex: none; width: 38px; height: 22px; border-radius: 999px; background: var(--line); transition: background .15s; }
.toggle .switch::before { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.toggle input:checked + .switch { background: var(--amber); }
.toggle input:checked + .switch::before { transform: translateX(16px); background: #1a1205; }
.toggle input:focus-visible + .switch { box-shadow: 0 0 0 3px rgba(255, 176, 0, .18); }
.add-form button { font: inherit; font-size: 13px; font-weight: 700; color: #1a1205; background: var(--amber); border: 0; padding: 11px 16px; border-radius: 9px; cursor: pointer; height: 42px; }

.danger-zone { margin: 8px 18px 24px; max-width: 420px; padding: 16px; border: 1px solid rgba(255, 59, 48, .3); border-radius: 12px; background: rgba(255, 59, 48, .05); }
.danger-zone h3 { margin: 0 0 4px; font-size: 14px; color: #ff8a82; }
.danger-zone .hint { margin: 0 0 12px; }

.webhook-box { padding: 18px; max-width: 560px; }
.webhook-url { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.webhook-url input { font-family: var(--mono); font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.empty-cell { text-align: center; color: var(--muted); padding: 30px 18px; }

/* Touch devices have no hover: never hide an action behind :hover */
@media (hover: none) {
  .msg .arch { opacity: 1; }
  /* iOS auto-zooms on focus when a control's font-size is under 16px. Match the base
     selectors' specificity (and number, which the base rule omits) so this wins. */
  input[type=text], input[type=password], input[type=number], input[type=email], select, textarea { font-size: 16px; }
}

/* Phones & small tablets */
@media (max-width: 560px) {
  .app { border-left: 0; border-right: 0; }
  header { gap: 8px; padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 12px; }
  .brand-name { font-size: 14px; letter-spacing: .03em; }
  nav.tabs a { padding: 6px 10px; }
  .iconbtn { width: 36px; height: 36px; }
  .msg { padding: 13px 14px; }
  .msg .body { font-size: 16px; }
  .msg .arch { position: static; opacity: 1; margin-top: 10px; }
  .ghost { padding: 8px 14px; font-size: 13px; }
  .banner { padding: 12px 14px; }
  .panel-head, th, td, .add-form, .settings-form, .webhook-box, .subtabs { padding-left: 14px; padding-right: 14px; }
}
