/* Tungsten Automation AI Ops — Status page
   Design tokens in :root; dark theme default with a light override via
   prefers-color-scheme. State is always conveyed with text + a shape, never
   colour alone. Mobile-first: base styles target ~390px, min-width queries
   layer up. */

:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev-2: #1c232c;
  --border: #2a323c;
  --text: #e6edf3;
  --text-muted: #9aa6b2;
  --brand: #ff7a18;

  --ok: #2ecc71;
  --degraded: #f5c518;
  --down: #ff4d4f;
  --blocked: #58a6ff;
  --maint: #8b7dff;
  --none: #3a434e;

  --ok-soft: rgba(46, 204, 113, 0.14);
  --degraded-soft: rgba(245, 197, 24, 0.14);
  --down-soft: rgba(255, 77, 79, 0.14);
  --blocked-soft: rgba(88, 166, 255, 0.14);
  --maint-soft: rgba(139, 125, 255, 0.16);

  /* Minimum touch target on mobile — every control honours this. */
  --tap: 44px;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --maxw: 980px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fa;
    --bg-elev: #ffffff;
    --bg-elev-2: #eef1f5;
    --border: #d8dee6;
    --text: #1b2430;
    --text-muted: #5b6673;
    --shadow: 0 4px 18px rgba(20, 30, 45, 0.08);
    --none: #cdd5de;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px;
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
a { color: inherit; }
.muted { color: var(--text-muted); }

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

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  padding-bottom: 12px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark { font-size: 22px; }
.brand-text { display: flex; flex-direction: column; }
.brand-text strong { font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--text-muted); }

.header-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---- Overall banner ------------------------------------------------------ */

.status-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 20px 0 16px;
  padding: 18px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  box-shadow: var(--shadow);
}

.status-banner h1 { font-size: 20px; }
.status-banner p { margin: 2px 0 0; font-size: 14px; color: var(--text-muted); }

.banner-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  flex: none;
  background: var(--none);
}

.status-banner[data-state="operational"] { border-color: var(--ok); background: linear-gradient(0deg, var(--ok-soft), var(--ok-soft)), var(--bg-elev); }
.status-banner[data-state="operational"] .banner-dot { background: var(--ok); }
.status-banner[data-state="degraded"] { border-color: var(--degraded); background: linear-gradient(0deg, var(--degraded-soft), var(--degraded-soft)), var(--bg-elev); }
.status-banner[data-state="degraded"] .banner-dot { background: var(--degraded); }
.status-banner[data-state="down"] { border-color: var(--down); background: linear-gradient(0deg, var(--down-soft), var(--down-soft)), var(--bg-elev); }
.status-banner[data-state="down"] .banner-dot { background: var(--down); }
.status-banner[data-state="maintenance"] { border-color: var(--maint); background: linear-gradient(0deg, var(--maint-soft), var(--maint-soft)), var(--bg-elev); }
.status-banner[data-state="maintenance"] .banner-dot { background: var(--maint); }
.status-banner[data-state="loading"] .banner-dot { animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.35; } }

/* ---- Notices ------------------------------------------------------------- */

.notice {
  margin: 0 0 16px;
  padding: 12px 16px;
  font-size: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  border-left-width: 4px;
  background: var(--bg-elev);
}
.notice p { margin: 6px 0 0; }
.notice--info { border-color: var(--blocked); background: var(--blocked-soft); }
.notice--warn { border-color: var(--degraded); background: var(--degraded-soft); }
.notice--maint { border-color: var(--maint); background: var(--maint-soft); }

.maint-items { margin: 8px 0 0; padding-left: 18px; }
.maint-items li { margin: 4px 0; }

.maint-tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid currentColor;
  vertical-align: 1px;
}
.maint-tag.active { color: var(--maint); background: var(--maint-soft); }
.maint-tag.scheduled { color: var(--blocked); background: var(--blocked-soft); }
.maint-tag.completed { color: var(--text-muted); background: var(--bg-elev-2); }
.maint-tag.cancelled { color: var(--text-muted); background: var(--bg-elev-2); text-decoration: line-through; }
.maint-tag.deploy { color: var(--brand); background: rgba(255, 122, 24, 0.14); }

/* ---- Sections ------------------------------------------------------------ */

.section-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 26px 0 12px;
}

/* ---- App cards ----------------------------------------------------------- */

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

.app-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.app-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px 4px;
  flex-wrap: wrap;
}

.app-name { font-size: 17px; }
.app-desc { margin: 0 18px 6px; font-size: 13px; color: var(--text-muted); }
.app-link { font-size: 13px; color: var(--text-muted); white-space: nowrap; }

.env-block { padding: 12px 18px 16px; border-top: 1px solid var(--border); }
.env-block.secondary { background: var(--bg-elev-2); }

.env-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.env-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.operational { color: var(--ok); background: var(--ok-soft); }
.pill.degraded { color: var(--degraded); background: var(--degraded-soft); }
.pill.down { color: var(--down); background: var(--down-soft); }
.pill.blocked { color: var(--blocked); background: var(--blocked-soft); }
.pill.maintenance { color: var(--maint); background: var(--maint-soft); }
.pill.unknown, .pill.none { color: var(--text-muted); background: var(--bg-elev-2); }

.env-meta { margin-left: auto; font-size: 12px; color: var(--text-muted); text-align: right; }

.env-detail { margin: 6px 0 0; font-size: 12.5px; color: var(--text-muted); }

/* Uptime bar strip: 90 cells, one per day */
.bars {
  display: flex;
  gap: 2px;
  margin: 12px 0 6px;
  height: 34px;
  align-items: stretch;
}

.bars .bar {
  flex: 1 1 0;
  min-width: 2px;
  border-radius: 2px;
  background: var(--none);
  cursor: default;
}
.bar[data-state="operational"] { background: var(--ok); }
.bar[data-state="degraded"] { background: var(--degraded); }
.bar[data-state="down"] { background: var(--down); }
.bar[data-state="maintenance"] { background: var(--maint); }

.bars-legend {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

/* Availability stat row */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.stat {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--bg);
}
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.stat .v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 11px; color: var(--text-muted); }

/* ---- Incidents ------------------------------------------------------------ */

.incident-list { display: flex; flex-direction: column; gap: 10px; }

.incident {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  padding: 12px 14px;
}
.incident.down { border-left-color: var(--down); }
.incident.degraded { border-left-color: var(--degraded); }

.incident-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.incident-title { font-weight: 600; font-size: 14px; }
.incident-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 8px;
  border-radius: 999px;
}
.incident-tag.resolved { color: var(--ok); background: var(--ok-soft); }
.incident-tag.ongoing { color: var(--down); background: var(--down-soft); }
.incident-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ---- Skeletons / tooltip / footer ----------------------------------------- */

.skeleton-card {
  height: 150px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(100deg, var(--bg-elev) 40%, var(--bg-elev-2) 50%, var(--bg-elev) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.bar-tooltip {
  position: fixed;
  z-index: 50;
  max-width: 240px;
  padding: 8px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  pointer-events: none;
}

.site-footer {
  margin-top: 40px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 20px 0 28px;
  font-size: 13px;
  color: var(--text-muted);
}
.site-footer p { margin: 8px 0; }

/* ---- Page furniture ------------------------------------------------------- */

.header-nav { display: flex; gap: 12px; margin-bottom: 2px; }
.header-nav a {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.header-nav a:hover, .header-nav a:focus-visible { color: var(--text); border-bottom-color: var(--brand); }

.page-title { font-size: 22px; margin: 22px 0 6px; }
.page-lead { margin: 0 0 18px; font-size: 14px; color: var(--text-muted); max-width: 68ch; }
.section-foot { margin: 10px 0 0; font-size: 13px; }
.section-foot a { color: var(--text-muted); }

.env-detail--maint { color: var(--maint); }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  box-shadow: var(--shadow);
}
.card--pad { padding: 16px 18px; font-size: 14px; }
.card--pad p { margin: 0 0 8px; }
.card--pad p:last-child { margin-bottom: 0; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-elev-2);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 10px 16px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--text-muted); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #1b1205; }
.btn--primary:hover { filter: brightness(1.07); }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--down); border-color: var(--down); background: var(--down-soft); }
.btn--danger:hover { background: var(--down); color: #2a0708; }
/* Compact only where there is a pointer — on mobile every control keeps the
   44px touch target. */
.btn--sm { font-size: 13px; }

/* Visible focus ring everywhere — never `outline: none` alone. */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.spinner {
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Forms --------------------------------------------------------------- */

.form { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 0; }

.field label, .filter-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}
.field label span { color: var(--down); }

input[type="text"], input[type="search"], input[type="datetime-local"],
select, textarea {
  min-height: var(--tap);
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 100%;
}
textarea { min-height: 84px; resize: vertical; }

.field-hint { margin: 0; font-size: 12px; color: var(--text-muted); }
.field-error, .form-error {
  margin: 0;
  font-size: 12.5px;
  color: var(--down);
}
.form-error {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--down);
  background: var(--down-soft);
}

.quick-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.form-actions { display: flex; }
.form-actions .btn { width: 100%; }

/* ---- Maintenance window list --------------------------------------------- */

.window-list { display: flex; flex-direction: column; gap: 10px; }

.window {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  padding: 12px 14px;
}
.window.active { border-left-color: var(--maint); }
.window.scheduled { border-left-color: var(--blocked); }
.window.completed, .window.cancelled { border-left-color: var(--none); }

.window-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.window-title { font-weight: 600; font-size: 14px; }
.window-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.window-desc { margin: 8px 0 0; font-size: 13px; }
.window-actions { margin-top: 10px; }
.window-actions .btn { width: 100%; }

/* ---- Modal --------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  background: rgba(0, 0, 0, 0.55);
}
.modal[hidden] { display: none; }

.modal-card {
  width: 100%;
  max-width: 460px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--bg-elev);
  box-shadow: var(--shadow);
}
.modal-card h3 { font-size: 17px; margin-bottom: 8px; }
.modal-card p { margin: 6px 0; font-size: 13.5px; }
.modal-actions { display: flex; flex-direction: column-reverse; gap: 8px; margin-top: 16px; }
.modal-actions .btn { width: 100%; }

/* ---- Stat row (history counts) ------------------------------------------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 0 0 16px;
}
.stat-row .v { font-size: 22px; }

/* ---- Filters ------------------------------------------------------------- */

.filter-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.filter-bar input[type="search"] { flex: 1 1 auto; }
.filter-toggle { flex: none; white-space: nowrap; }

.filter-count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  border-radius: 999px;
  background: var(--brand);
  color: #1b1205;
}

/* Mobile: the filter set lives in a bottom sheet (Rule UI-1). */
.filter-sheet {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 90;
  transform: translateY(101%);
  transition: transform 0.18s ease-out;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  max-height: 84vh;
  overflow-y: auto;
}
.filter-sheet.is-open { transform: translateY(0); }
.filter-sheet-inner { padding: 18px 16px 22px; display: flex; flex-direction: column; gap: 16px; }
.filter-group { display: flex; flex-direction: column; gap: 8px; }
.filter-sheet-actions { display: flex; flex-direction: column-reverse; gap: 8px; }
.filter-sheet-actions .btn { width: 100%; }

.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: var(--tap);
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.chip.is-active {
  color: var(--text);
  border-color: var(--brand);
  background: rgba(255, 122, 24, 0.12);
}

/* ---- Event history list --------------------------------------------------- */

.event-list { display: flex; flex-direction: column; gap: 10px; }

.event {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  padding: 12px 14px;
}
.event.down { border-left-color: var(--down); }
.event.degraded { border-left-color: var(--degraded); }
.event.maintenance { border-left-color: var(--maint); }

.event-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.event-title { font-weight: 600; font-size: 14px; }
.event-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.event-desc { margin: 8px 0 0; font-size: 13px; }

.event-kind {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 7px;
  border-radius: 4px;
}
.event-kind.incident { color: var(--down); background: var(--down-soft); }
.event-kind.maintenance { color: var(--maint); background: var(--maint-soft); }

.event-tag {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 8px;
  border-radius: 999px;
}
.event-tag.resolved, .event-tag.completed { color: var(--ok); background: var(--ok-soft); }
.event-tag.ongoing, .event-tag.active { color: var(--down); background: var(--down-soft); }
.event-tag.scheduled { color: var(--blocked); background: var(--blocked-soft); }
.event-tag.cancelled { color: var(--text-muted); background: var(--bg-elev-2); }

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

@media (min-width: 768px) {
  .container { padding: 0 24px; }
  .status-banner h1 { font-size: 24px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .stat-row { grid-template-columns: repeat(4, 1fr); }
  .page-title { font-size: 26px; }

  .form-row { flex-direction: row; }
  .form-actions .btn, .window-actions .btn { width: auto; }
  .btn--sm { min-height: 36px; padding: 6px 12px; }
  .modal { align-items: center; padding: 24px; }
  .modal-card { border-radius: var(--radius); }
  .modal-actions { flex-direction: row; justify-content: flex-end; }
  .modal-actions .btn { width: auto; }

  /* Desktop: filters are inline, the sheet trigger disappears. */
  .filter-toggle { display: none; }
  .filter-sheet {
    position: static;
    transform: none;
    max-height: none;
    overflow: visible;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
  }
  .filter-sheet-inner { flex-direction: row; align-items: flex-end; flex-wrap: wrap; }
  .filter-group { flex: 1 1 170px; }
  /* The type chips need room for all three on one row. */
  .filter-group:has(.pill-group) { flex: 0 0 auto; }
  .filter-sheet-actions { flex-direction: row; margin-left: auto; }
  .filter-sheet-actions .btn { width: auto; }
  #filter-apply { display: none; }
}

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