/* =========================================================================
   Status Monitor – Light / Dark Theme
   =========================================================================
   Light palette lives on :root.
   Dark palette applies via two guards:
     1. @media (prefers-color-scheme: dark) when no explicit override exists
     2. :root[data-theme="dark"] which always wins.
   ========================================================================= */

/* ---------- Light tokens ------------------------------------------------ */
:root {
  --color-bg:          #ffffff;
  --color-surface:     #f5f6f8;
  --color-surface-alt: #ebedf0;
  --color-border:      #d0d3d8;
  --color-text:        #1a1d21;
  --color-text-muted:  #5f6775;
  --color-primary:     #2563eb;
  --color-primary-fg:  #ffffff;
  --color-error:       #b91c1c;
  --color-error-bg:    #fef2f2;
  --color-success:     #15803d;
  --color-success-bg:  #f0fdf4;

  /* Status colours – paired with icons so hue is never sole signal */
  --st-operational:    #15803d;
  --st-operational-bg: #dcfce7;
  --st-degraded:       #b45309;
  --st-degraded-bg:    #fef3c7;
  --st-outage:         #b91c1c;
  --st-outage-bg:      #fee2e2;

  --radius:            6px;
  --shadow-sm:         0 1px 2px rgba(0,0,0,.06);
  --shadow-md:         0 2px 8px rgba(0,0,0,.08);
  --max-content-width: 860px;
}

/* ---------- Dark auto (OS preference, unless user chose light) ----------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg:          #111318;
    --color-surface:     #1c1e24;
    --color-surface-alt: #26282f;
    --color-border:      #3a3d45;
    --color-text:        #e4e6ea;
    --color-text-muted:  #9ca0ab;
    --color-primary:     #60a5fa;
    --color-primary-fg:  #111318;
    --color-error:       #f87171;
    --color-error-bg:    #2a1215;
    --color-success:     #4ade80;
    --color-success-bg:  #122a1c;

    --st-operational:    #4ade80;
    --st-operational-bg: #122a1c;
    --st-degraded:       #fbbf24;
    --st-degraded-bg:    #2a2206;
    --st-outage:         #f87171;
    --st-outage-bg:      #2a1215;
  }
}

/* ---------- Dark explicit ----------------------------------------------- */
:root[data-theme="dark"] {
  --color-bg:          #111318;
  --color-surface:     #1c1e24;
  --color-surface-alt: #26282f;
  --color-border:      #3a3d45;
  --color-text:        #e4e6ea;
  --color-text-muted:  #9ca0ab;
  --color-primary:     #60a5fa;
  --color-primary-fg:  #111318;
  --color-error:       #f87171;
  --color-error-bg:    #2a1215;
  --color-success:     #4ade80;
  --color-success-bg:  #122a1c;

  --st-operational:    #4ade80;
  --st-operational-bg: #122a1c;
  --st-degraded:       #fbbf24;
  --st-degraded-bg:    #2a2206;
  --st-outage:         #f87171;
  --st-outage-bg:      #2a1215;
}

/* =========================================================================
   Base
   ========================================================================= */

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); }
a:hover { text-decoration: none; }

/* =========================================================================
   Header
   ========================================================================= */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.product-name {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.header-right {
  display: flex;
  gap: 8px;
}

.btn-icon {
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  font-size: 0.85rem;
}
.btn-icon:hover { background: var(--color-surface-alt); }

/* =========================================================================
   Main
   ========================================================================= */

.main-content {
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: 20px 16px 48px;
  width: 100%;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.card-heading {
  margin: 0 0 16px;
  font-size: 1rem;
  font-weight: 600;
}

/* =========================================================================
   Status banner
   ========================================================================= */

.banner-section { margin-bottom: 20px; }

.status-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  border-left: 4px solid transparent;
}

.status-banner--operational {
  background: var(--st-operational-bg);
  color: var(--st-operational);
  border-left-color: var(--st-operational);
}
.status-banner--degraded {
  background: var(--st-degraded-bg);
  color: var(--st-degraded);
  border-left-color: var(--st-degraded);
}
.status-banner--outage {
  background: var(--st-outage-bg);
  color: var(--st-outage);
  border-left-color: var(--st-outage);
}

.banner-updated {
  font-weight: 400;
  font-size: 0.8rem;
  opacity: 0.7;
  margin-left: auto;
}

/* =========================================================================
   Status icon (colour-blind safe – always shown alongside text)
   ========================================================================= */

.status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4em;
  height: 1.4em;
  font-size: 1rem;
  line-height: 1;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-icon--operational {
  background: var(--st-operational);
  color: #fff;
}
.status-icon--degraded {
  background: var(--st-degraded);
  color: #fff;
}
.status-icon--outage {
  background: var(--st-outage);
  color: #fff;
}

/* =========================================================================
   Component list
   ========================================================================= */

.component-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.component-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
}
.component-row:last-child { border-bottom: none; }

.component-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.component-name {
  font-weight: 600;
}

.component-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.component-badge--operational {
  background: var(--st-operational-bg);
  color: var(--st-operational);
}
.component-badge--degraded {
  background: var(--st-degraded-bg);
  color: var(--st-degraded);
}
.component-badge--outage {
  background: var(--st-outage-bg);
  color: var(--st-outage);
}

.component-desc {
  margin: 4px 0 0;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}
.component-message {
  margin: 4px 0 0;
  font-size: 0.85rem;
  font-style: italic;
}

/* =========================================================================
   Incidents
   ========================================================================= */

.incidents-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.incident-card {
  padding: 16px;
  background: var(--color-surface-alt);
  border-radius: var(--radius);
  overflow-x: auto;
}

.incident-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.incident-title {
  font-weight: 600;
}

.incident-phase,
.incident-date {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.incident-meta {
  display: flex;
  gap: 16px;
  margin: 6px 0 12px;
  flex-wrap: wrap;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 2px solid var(--color-border);
}
.timeline li {
  padding: 8px 0 8px 16px;
  position: relative;
}
.timeline li::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 14px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-primary);
}

.timeline-phase {
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: capitalize;
  margin-right: 8px;
}

.timeline-time {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.timeline-message {
  margin: 4px 0 0;
  font-size: 0.9rem;
}

/* =========================================================================
   Tickets
   ========================================================================= */

.tickets-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.ticket-row {
  padding: 10px 12px;
  background: var(--color-surface-alt);
  border-radius: var(--radius);
  overflow-x: auto;
}

.ticket-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ticket-title { font-weight: 600; }

.ticket-priority {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}
.ticket-priority--low    { background: var(--st-operational-bg); color: var(--st-operational); }
.ticket-priority--medium { background: var(--st-degraded-bg);    color: var(--st-degraded); }
.ticket-priority--high   { background: var(--st-outage-bg);      color: var(--st-outage); }
.ticket-priority--urgent { background: var(--st-outage-bg);      color: var(--st-outage); }

.ticket-status {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  text-transform: capitalize;
}

.ticket-meta {
  display: flex;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 4px;
}

.ticket-component {
  font-style: italic;
}

.raise-ticket-details {
  border-top: 1px solid var(--color-border);
  padding-top: 12px;
}
.raise-ticket-details summary {
  cursor: pointer;
  font-weight: 600;
  padding: 6px 0;
}
.raise-ticket-details summary:hover { color: var(--color-primary); }

/* =========================================================================
   Forms (shared)
   ========================================================================= */

.ticket-form,
.subscriptions-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 480px;
  margin-top: 12px;
}

.ticket-form label,
.subscriptions-form label,
.subscriptions-form legend {
  font-size: 0.85rem;
  font-weight: 600;
}

.subscriptions-form fieldset {
  border: none;
  padding: 0;
  margin: 0;
}
.subscriptions-form legend {
  font-weight: 600;
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 0.9rem;
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
  cursor: pointer;
  margin-right: 16px;
}

button[type="submit"] {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  background: var(--color-primary);
  color: var(--color-primary-fg);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  align-self: flex-start;
}
button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
button[type="submit"]:hover:not(:disabled) {
  filter: brightness(1.1);
}

.error-text {
  color: var(--color-error);
  font-size: 0.85rem;
}
.success-text {
  color: var(--color-success);
  font-size: 0.85rem;
}

.empty-state {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* =========================================================================
   Login page
   ========================================================================= */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow-md);
}

.login-card h1 {
  margin: 0 0 20px;
  font-size: 1.25rem;
  text-align: center;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#login-form label {
  font-size: 0.85rem;
  font-weight: 600;
}

#login-submit {
  margin-top: 6px;
}

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 480px) {
  .site-header { padding: 10px 12px; }
  .product-name { font-size: 1rem; }
  .main-content { padding: 12px 10px 32px; }
  .card { padding: 14px 12px; }
  .status-banner { padding: 10px 14px; font-size: 0.95rem; }
  .incident-card { padding: 12px; }
  .ticket-form,
  .subscriptions-form { max-width: 100%; }
  .ticket-header { flex-direction: column; align-items: flex-start; gap: 4px; }
  .banner-updated { display: block; margin-left: 0; margin-top: 4px; }
}

/* ---------------------------------------------------------------------------
   90-day history strip
   Reuses the --st-* status tokens so a bar and its badge always agree, and so
   both themes are covered without a second palette.
   --------------------------------------------------------------------------- */
.history-strip {
  margin-top: 0.75rem;
}

.history-track {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  width: 100%;
  /* Bars shrink to fit rather than overflowing the card on narrow screens. */
  overflow: hidden;
}

.history-day {
  flex: 1 1 0;
  min-width: 2px;
  height: 26px;
  border-radius: 2px;
  background: var(--st-operational);
  opacity: 0.85;
  transition: opacity 0.12s ease;
}

.history-day:hover {
  opacity: 1;
}

.history-day--operational { background: var(--st-operational); }
.history-day--degraded    { background: var(--st-degraded); }
.history-day--outage      { background: var(--st-outage); }
.history-day--maintenance { background: var(--color-text-muted); }

.history-legend {
  display: flex;
  justify-content: space-between;
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* Login secondary actions -------------------------------------------------- */
.login-actions {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.75rem;
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 0.875rem;
  color: var(--color-primary);
  cursor: pointer;
  text-decoration: underline;
}

.btn-link:hover { opacity: 0.8; }

.login-hint {
  margin-top: 0.9rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* Success/neutral messages reuse the error element, so it must be able to
   stop looking like an error. */
.notice-text {
  color: var(--color-success) !important;
}

.banner--error {
  background: var(--color-error-bg);
  color: var(--color-error);
  border-left-color: var(--color-error);
}

/* Login feedback must be impossible to miss - it was a single line of 0.85rem
   text directly above the submit button. */
.message-box {
  display: block;
  margin: 0.75rem 0;
  padding: 0.7rem 0.85rem;
  border-radius: 6px;
  border: 1px solid currentColor;
  background: var(--color-error-bg);
  font-size: 0.9rem;
  line-height: 1.4;
}

.message-box.notice-text {
  background: var(--color-success-bg);
}

/* Login branding. An unbranded credential form is indistinguishable from a
   phishing page - to users and to Safe Browsing alike. */
.login-brand {
  margin-bottom: 1.25rem;
}

.login-org {
  margin: 0 0 0.15rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-primary);
}

.login-brand h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.25;
}

.login-sub {
  margin: 0.3rem 0 0;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* Tab bar ------------------------------------------------------------------ */
.tab-bar {
  display: flex;
  gap: 0.25rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.7rem 1rem;
  font: inherit;
  font-size: 0.925rem;
  color: var(--color-text-muted);
  cursor: pointer;
}

.tab:hover { color: var(--color-text); }

.tab--active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  font-weight: 600;
}

.subheading {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.95rem;
}

.component-badge--maintenance,
.status-icon--maintenance {
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
}
