/* /admin: the announcements control surface (issue #8).
 *
 * Standalone, not part of the app shell: no header, no radio, no page frame.
 * It shares the theme and nothing else, because it is a tool an administrator
 * opens during an incident, not a place a visitor spends time.
 *
 * Mobile-first for the same reason. The stated use case is a phone, so the base
 * rules are the narrow layout and the one media query widens it.
 */

.admin {
  /* Re-binds the type roles on its own root, per theme.css rule 2. This is a
     dense control surface, not reading prose: everything steps down one rung
     from the base ladder so a whole key's worth of entries fits on a phone. */
  --fs-title:     22px;
  --fs-heading:   16px;
  --fs-body:      15px;
  --fs-secondary: 14px;
  --fs-ui:        13px;
  --fs-label:     11px;

  display: block;
  max-width: 760px;
  margin-inline: auto;
  padding: var(--space-6xl) var(--space-2xl) 64px;
  font-family: var(--font-body);
  color: var(--text-body);
}

/* THIS PAGE SCROLLS THE DOCUMENT, and that is a deliberate second attempt.
 *
 * `body` is `overflow: hidden` globally (style.css) because the app shell is a
 * fixed-height terminal whose views scroll internally. /admin is not inside that
 * shell, so it inherited the restriction with none of the compensation and could
 * not be scrolled at all.
 *
 * The first fix made `.admin` its own fixed scroll container. That restored
 * scrolling and broke pull-to-refresh, because the browser's pull-to-refresh is
 * bound to the ROOT scroller: a fixed inner element can never trigger it, and no
 * amount of overscroll tuning changes that. Reimplementing the gesture in JS
 * would have been a worse version of something the platform already does.
 *
 * So the restriction is lifted for this page instead. `:has()` scopes it to the
 * admin view only, so the app shell keeps its fixed-height behaviour untouched,
 * and the document is the scroller again — which is what pull-to-refresh needs.
 */
body:has(.admin) {
  overflow: auto;
  /* `contain` here would block pull-to-refresh just as surely as the fixed
     container did. Say `auto` out loud so a future tidy-up does not "harden" it. */
  overscroll-behavior-y: auto;
}

/* ---- head ---- */

.admin-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2xl);
  flex-wrap: wrap;
  padding-bottom: var(--space-2xl);
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--space-6xl);
}

.admin-title {
  font-family: var(--font-identity);
  font-size: var(--fs-title);
  letter-spacing: var(--tracking-caps);
  color: var(--text);
  margin: 0;
}

.admin-sub {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: var(--tracking-label);
  color: var(--muted);
  margin: var(--space-2xs) 0 0;
  word-break: break-all; /* an email is one long token on a narrow screen */
}

.admin-exit {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-label);
  letter-spacing: var(--tracking-mid);
  border-bottom: 1px solid var(--line-strong);
  flex: none;
}

.admin-section-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-heading);
  letter-spacing: var(--tracking-mid);
  color: var(--primary);
  margin: 0 0 var(--space-2xl);
}

/* ---- banners ----
   One component, three roles. The colour is the only difference, so it is a
   custom property rather than three rule bodies. */

.admin-banner {
  --bn: var(--muted);
  border: 1px solid rgb(from var(--bn) r g b / 0.5);
  border-left-width: 3px;
  background: rgb(from var(--bn) r g b / 0.08);
  color: var(--text-body);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  line-height: 1.6;
  padding: var(--space-lg) var(--space-2xl);
  margin-bottom: var(--space-2xl);

  &.danger { --bn: var(--danger); }
  &.warn   { --bn: var(--secondary); }
  &.ok     { --bn: var(--success); }
}

.admin-raw {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  color: var(--muted);
  background: var(--field-bg);
  border: 1px solid var(--line-faint);
  padding: var(--space-sm);
  margin: var(--space-sm) 0;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---- form ---- */

.admin-form {
  border: 1px solid var(--line);
  background: var(--card-bg);
  padding: var(--space-6xl) var(--space-2xl);
  margin-bottom: var(--section-gap);
}

.admin-levels {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

/* The level chips carry the same colour language as the broadcast panel itself,
   so the choice made here looks like the thing that will appear there. */
.admin-level {
  --lvl: var(--muted);
  /* Two-up on a phone. Left to wrap naturally the four chips break 3 + 1, and a
     lone RESOLVED on its own row reads as a different kind of control. */
  flex: 1 1 calc(50% - var(--space-sm));
  text-align: center;
  background: transparent;
  border: 1px solid rgb(from var(--lvl) r g b / 0.45);
  color: rgb(from var(--lvl) r g b / 0.8);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-label);
  letter-spacing: var(--tracking-mid);
  padding: var(--space-md) var(--space-lg);
  cursor: pointer;

  &.update   { --lvl: var(--primary); }
  &.alert    { --lvl: var(--secondary); }
  &.resolved { --lvl: var(--success); }
  &.info     { --lvl: var(--muted); }

  &.on {
    background: var(--lvl);
    border-color: var(--lvl);
    color: var(--bg);
  }
}

.admin-hint {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  color: var(--placeholder);
  line-height: 1.6;
  margin: var(--space-md) 0 var(--space-6xl);
}

.admin-label {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: var(--tracking-mid);
  color: var(--primary);
  margin-bottom: var(--space-xs);
}

.admin-input {
  width: 100%;
  box-sizing: border-box;
  background: var(--field-bg);
  border: 1px solid rgb(from var(--primary) r g b / 0.4);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  letter-spacing: var(--tracking-tight);
  padding: var(--space-lg) var(--space-xl);
  outline: none;

  &:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px rgb(from var(--primary) r g b / 0.4);
  }
}

.admin-textarea {
  resize: vertical;
  line-height: var(--lh-body);
  font-family: var(--font-body);
}

.admin-date {
  /* The native picker's glyph is black-on-dark by default. */
  color-scheme: dark;
  width: auto;
  min-width: 180px;
}

.admin-count {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  color: var(--muted);
  text-align: right;
  margin: var(--space-2xs) 0 var(--space-2xl);

  /* Over the limit is a refusal, not a nudge: the POST button is disabled while
     this shows, so it has to be unmissable. */
  &.over {
    color: var(--danger);
    font-weight: 600;
  }
}

.admin-actions {
  display: flex;
  gap: var(--space-lg);
  flex-wrap: wrap;
  margin-top: var(--space-2xl);
}

/* ---- buttons ---- */

.admin-btn {
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--primary);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-ui);
  letter-spacing: var(--tracking-mid);
  padding: var(--space-lg) var(--space-4xl);
  cursor: pointer;
  /* A tap target on a phone, which is the stated use case. */
  min-height: 44px;

  &.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--bg);
    box-shadow: 0 0 22px rgb(from var(--primary) r g b / 0.25);

    &:hover:not(:disabled) { box-shadow: 0 0 34px rgb(from var(--primary) r g b / 0.55); }
  }

  &.green  { border-color: var(--success); color: var(--success); }
  &.danger { border-color: rgb(from var(--danger) r g b / 0.6); color: var(--danger); }

  &.small {
    font-size: var(--fs-label);
    padding: var(--space-sm) var(--space-lg);
    min-height: 36px;
  }

  &:disabled {
    border-color: rgb(from var(--muted) r g b / 0.3);
    background: transparent;
    box-shadow: none;
    color: var(--muted);
    opacity: 0.6;
    cursor: not-allowed;
  }
}

/* ---- live keys ---- */

.admin-key {
  border: 1px solid var(--line-faint);
  padding: var(--space-2xl);
  margin-bottom: var(--space-6xl);
}

.admin-key-head {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  flex-wrap: wrap;
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--line-faint);
  margin-bottom: var(--space-2xl);
}

.admin-key-tag {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-label);
  letter-spacing: var(--tracking-caps);
  border: 1px solid currentcolor;
  padding: 2px var(--space-sm);

  &.ops    { color: var(--secondary); }
  &.manual { color: var(--primary); }
}

.admin-key-note {
  flex: 1;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  color: var(--placeholder);
}

.admin-empty {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: var(--tracking-label);
  color: var(--placeholder);
  margin: 0;
}

.admin-entry {
  --lvl: var(--muted);
  border-left: 3px solid var(--lvl);
  background: rgb(from var(--lvl) r g b / 0.05);
  padding: var(--space-lg) var(--space-2xl);
  margin-bottom: var(--space-lg);

  &.update   { --lvl: var(--primary); }
  &.alert    { --lvl: var(--secondary); }
  &.resolved { --lvl: var(--success); }
  &.info     { --lvl: var(--muted); }
}

.admin-entry-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.admin-entry-tag {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-label);
  letter-spacing: var(--tracking-label);
  color: var(--lvl);
}

.admin-entry-title {
  flex: 1;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-secondary);
  letter-spacing: var(--tracking-tight);
  color: var(--text);
}

.admin-entry-date {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  color: var(--muted);
}

.admin-entry-body {
  font-size: var(--fs-secondary);
  line-height: var(--lh-body);
  color: var(--text-body);
  margin: var(--space-xs) 0 var(--space-lg);
}

.admin-entry-actions {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.admin-entry-id {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  color: var(--placeholder);
  margin-top: var(--space-md);
  word-break: break-all;
}

@media (min-width: 720px) {
  .admin {
    padding-inline: var(--frame-gutter);
  }

  .admin-form {
    /* 28px is in the medium band theme.css leaves literal on purpose: it is a
       one-off inset, not a shared role, and naming it would be false uniformity. */
    padding: var(--section-gap) 28px;
  }

  .admin-level {
    flex: 0 0 auto;
    min-width: 110px;
  }
}
