/* Status page — Apple HIG 2025 inspired.
   Principles: Hierarchy, Harmony (concentric corners), Consistency.
   Two layers: functional (banner, nav) above content (rows, history). */

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

:root {
  color-scheme: light dark;

  /* System font stack — SF Pro on Apple platforms, fallback elsewhere */
  --font-body: -apple-system, "SF Pro Text", BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --font-display: -apple-system, "SF Pro Display", BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  /* Typography — iOS text styles */
  --text-largetitle: 34px;
  --text-title1:     28px;
  --text-title2:     22px;
  --text-title3:     20px;
  --text-headline:   17px;
  --text-body:       17px;
  --text-callout:    16px;
  --text-subhead:    15px;
  --text-footnote:   13px;
  --text-caption1:   12px;
  --text-caption2:   11px;

  /* Spacing — 8pt grid */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
  --sp-12: 48px; --sp-16: 64px; --sp-20: 80px;

  /* Radii — concentric */
  --r-xl:  24px;  /* banner */
  --r-lg:  18px;  /* services container */
  --r-md:  14px;  /* cards internos */
  --r-sm:  10px;  /* history item */
  --r-pill: 9999px;

  /* Light theme — iOS system palette */
  --bg-base:         #fafafa;
  --bg-elevated:     #ffffff;
  --bg-secondary:    #f2f2f7;
  --bg-tertiary:     #f9f9fb;

  --label-primary:   rgba(0,0,0,0.92);
  --label-secondary: rgba(60,60,67,0.60);
  --label-tertiary:  rgba(60,60,67,0.38);

  --separator:       rgba(60,60,67,0.12);
  --border-hair:     rgba(0,0,0,0.08);

  --accent:          #6d5e97;
  --accent-soft:     color-mix(in srgb, var(--accent) 12%, transparent);

  /* Status semantic colors — iOS system */
  --ok:     #30b07a;
  --ok-bg:  color-mix(in srgb, #30b07a 14%, transparent);
  --warn:   #f0a04b;
  --warn-bg:color-mix(in srgb, #f0a04b 14%, transparent);
  --down:   #e5484d;
  --down-bg:color-mix(in srgb, #e5484d 14%, transparent);
  --maint:  #8e8e93;
  --maint-bg:color-mix(in srgb, #8e8e93 14%, transparent);
  --unknown:#59687a;
  --unknown-bg:color-mix(in srgb, #59687a 12%, transparent);

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 0 0 0.5px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.05), 0 0 0 0.5px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.05), 0 0 0 0.5px rgba(0,0,0,0.04);

  /* Motion */
  --ease-out:      cubic-bezier(0.16, 1, 0.3, 1);
  --ease-standard: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --dur-fast:   200ms;
  --dur-normal: 320ms;
  --dur-slow:   500ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-base:         #000000;
    --bg-elevated:     #1c1c1e;
    --bg-secondary:    #1c1c1e;
    --bg-tertiary:     #2c2c2e;

    --label-primary:   rgba(255,255,255,0.96);
    --label-secondary: rgba(235,235,245,0.60);
    --label-tertiary:  rgba(235,235,245,0.38);

    --separator:       rgba(84,84,88,0.45);
    --border-hair:     rgba(255,255,255,0.08);

    --accent:          #8b7cc7;
    --accent-soft:     color-mix(in srgb, #8b7cc7 16%, transparent);

    --ok:     #30d37e;
    --warn:   #ffa94d;
    --down:   #ff6369;
    --maint:  #98989d;
    --unknown:#a8b4c3;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.24), 0 0 0 0.5px rgba(255,255,255,0.05);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.32), 0 1px 3px rgba(0,0,0,0.24), 0 0 0 0.5px rgba(255,255,255,0.06);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.40), 0 4px 12px rgba(0,0,0,0.28), 0 0 0 0.5px rgba(255,255,255,0.06);
  }

  .brand { filter: brightness(0.95); }
}

/* ============================================== */

html, body {
  background: var(--bg-base);
  color: var(--label-primary);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: 1.4;
  letter-spacing: -0.01em;
  min-height: 100vh;
}

body {
  padding: max(env(safe-area-inset-top), var(--sp-8)) var(--sp-4) var(--sp-16);
}

.page {
  max-width: 680px;
  margin: 0 auto;
  animation: page-fade var(--dur-slow) var(--ease-out) both;
}

@keyframes page-fade {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============== HEADER ============== */

.top {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-2) var(--sp-8);
}

.brand {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex-shrink: 0;
}

.title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

h1 {
  font-family: var(--font-display);
  font-size: var(--text-headline);
  font-weight: 600;
  letter-spacing: -0.022em;
  color: var(--label-primary);
}

.timestamp {
  font-size: var(--text-footnote);
  color: var(--label-tertiary);
  font-variant-numeric: tabular-nums;
}

/* ============== BANNER (functional layer — elevated) ============== */

.banner {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-6);
  margin-bottom: var(--sp-4);
  border-radius: var(--r-xl);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transition: box-shadow var(--dur-normal) var(--ease-out);
}

.banner::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, color-mix(in srgb, var(--state-color, var(--ok)) 6%, transparent), transparent 60%);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease-out);
}

.banner[data-state] { --state-color: var(--ok); }
.banner[data-state="warn"]  { --state-color: var(--warn); }
.banner[data-state="down"]  { --state-color: var(--down); }
.banner[data-state="maint"] { --state-color: var(--maint); }
.banner[data-state="unknown"] { --state-color: var(--unknown); }
.banner[data-state]::before { opacity: 1; }

.banner-indicator {
  position: relative;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.indicator-dot,
.indicator-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--state-color, var(--maint));
}

.indicator-dot {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--state-color, var(--maint)) 18%, transparent);
  z-index: 1;
}

/* Pulse only when operational */
.banner[data-state="ok"] .indicator-pulse {
  animation: pulse 2.4s var(--ease-out) infinite;
}
.banner:not([data-state="ok"]) .indicator-pulse {
  display: none;
}

@keyframes pulse {
  0%   { transform: scale(1);   opacity: 0.55; }
  70%  { transform: scale(2.4); opacity: 0; }
  100% { transform: scale(2.4); opacity: 0; }
}

.banner-text {
  flex: 1;
  min-width: 0;
}

.banner h2 {
  font-family: var(--font-display);
  font-size: var(--text-title3);
  font-weight: 600;
  letter-spacing: -0.022em;
  color: var(--label-primary);
}

.banner p {
  margin-top: 2px;
  font-size: var(--text-subhead);
  color: var(--label-secondary);
  letter-spacing: -0.01em;
}

/* ============== SERVICES LIST (content layer) ============== */

.services {
  background: var(--bg-elevated);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  animation: list-fade var(--dur-slow) var(--ease-out) 120ms both;
}

@keyframes list-fade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.service-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  position: relative;
  transition: background var(--dur-fast) var(--ease-out);
}

.service-row + .service-row::before {
  content: "";
  position: absolute;
  top: 0;
  left: var(--sp-5);
  right: var(--sp-5);
  height: 0.5px;
  background: var(--separator);
}

.service-row:hover {
  background: var(--bg-secondary);
}

.service-dot {
  position: relative;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--maint);
}

.service-row[data-state="ok"]    .service-dot { background: var(--ok); }
.service-row[data-state="warn"]  .service-dot { background: var(--warn); }
.service-row[data-state="down"]  .service-dot { background: var(--down); }
.service-row[data-state="maint"] .service-dot { background: var(--maint); }
.service-row[data-state="unknown"] .service-dot { background: var(--unknown); }

/* Pulse dot only when ok */
.service-row[data-state="ok"] .service-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse-small 2.8s var(--ease-out) infinite;
  animation-delay: var(--delay, 0s);
}

@keyframes pulse-small {
  0%   { transform: scale(1);   opacity: 0.4; }
  70%  { transform: scale(2.2); opacity: 0; }
  100% { transform: scale(2.2); opacity: 0; }
}

.service-name {
  font-size: var(--text-body);
  font-weight: 500;
  color: var(--label-primary);
  letter-spacing: -0.011em;
}

.service-status-label {
  font-size: var(--text-footnote);
  font-weight: 500;
  color: var(--label-secondary);
  letter-spacing: -0.008em;
  font-variant-numeric: tabular-nums;
}

.service-row[data-state="warn"]  .service-status-label { color: var(--warn); }
.service-row[data-state="down"]  .service-status-label { color: var(--down); }
.service-row[data-state="maint"] .service-status-label { color: var(--maint); }
.service-row[data-state="unknown"] .service-status-label { color: var(--unknown); }

.service-detail {
  grid-column: 1 / -1;
  margin-top: var(--sp-1);
  padding-left: calc(10px + var(--sp-4));
  font-size: var(--text-footnote);
  color: var(--label-secondary);
  line-height: 1.5;
}

/* ============== HISTORY ============== */

.history-section {
  margin-top: var(--sp-10);
  animation: list-fade var(--dur-slow) var(--ease-out) 240ms both;
}

.section-title {
  font-size: var(--text-footnote);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--label-tertiary);
  padding: 0 var(--sp-2);
  margin-bottom: var(--sp-3);
}

.history {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.empty {
  padding: var(--sp-6);
  text-align: center;
  font-size: var(--text-subhead);
  color: var(--label-tertiary);
  background: var(--bg-elevated);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}

.history-item {
  background: var(--bg-elevated);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

.history-item:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.history-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.history-head .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.history-head .name {
  font-size: var(--text-subhead);
  font-weight: 600;
  color: var(--label-primary);
  flex: 1;
  letter-spacing: -0.01em;
}

.history-head .duration {
  font-size: var(--text-caption1);
  color: var(--label-tertiary);
  font-variant-numeric: tabular-nums;
}

.history-title {
  margin-top: var(--sp-1);
  padding-left: calc(8px + var(--sp-2));
  font-size: var(--text-subhead);
  color: var(--label-primary);
  letter-spacing: -0.01em;
}

.history-dates {
  margin-top: 2px;
  padding-left: calc(8px + var(--sp-2));
  font-size: var(--text-caption1);
  color: var(--label-tertiary);
  font-variant-numeric: tabular-nums;
}

/* ============== FOOTER ============== */

.foot {
  margin-top: var(--sp-10);
  text-align: center;
}

.foot p {
  font-size: var(--text-caption1);
  color: var(--label-tertiary);
}

.foot a {
  color: var(--accent);
  text-decoration: none;
  transition: opacity var(--dur-fast) var(--ease-out);
}
.foot a:hover { opacity: 0.72; }

/* ============== RESPONSIVE ============== */

@media (max-width: 540px) {
  body { padding: var(--sp-6) var(--sp-3) var(--sp-12); }
  .top { padding: var(--sp-2) 0 var(--sp-6); }
  .banner { padding: var(--sp-4) var(--sp-5); }
  .banner h2 { font-size: var(--text-title3); }
  .service-row { padding: var(--sp-3) var(--sp-4); }
  .service-name { font-size: var(--text-callout); }
}

/* ============== A11Y ============== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
