/* =========================================================================
   ECG Engine Monitor — Shared Stylesheet
   East Coast Generators corporate colour scheme
   ========================================================================= */
:root {
  /* ECG brand colours */
  --ecg-blue:        #2E8FCC;
  --ecg-blue-light:  #5FB0E0;
  --ecg-blue-pale:   #D9ECF7;
  --ecg-blue-dark:   #1A5A8C;
  --ecg-navy:        #0F2A47;
  --ecg-navy-soft:   #1E3A5F;

  /* Surfaces */
  --bg:        #F4F7FA;
  --bg-alt:    #EAF1F7;
  --surface:   #FFFFFF;
  --border:    #E1E8EF;
  --border-strong: #C9D5E0;

  /* Text */
  --text:      #1F2937;
  --text-muted:#64748B;
  --text-soft: #94A3B8;
  --text-on-blue: #FFFFFF;

  /* Status */
  --success:   #10B981;
  --success-bg:#D1FAE5;
  --warning:   #F59E0B;
  --warning-bg:#FEF3C7;
  --danger:    #EF4444;
  --danger-bg: #FEE2E2;
  --neutral:   #94A3B8;
  --neutral-bg:#F1F5F9;

  /* Typography */
  --sans:  "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --mono:  "SF Mono", Consolas, "Courier New", monospace;
  --display: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;

  /* Spacing & shape */
  --radius:    8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(15,42,71,0.06);
  --shadow:    0 4px 12px rgba(15,42,71,0.08);
  --shadow-lg: 0 8px 24px rgba(15,42,71,0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: var(--sans);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--ecg-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: var(--sans);
  font-size: 14px;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 9px 18px;
  transition: all 0.15s ease;
  font-weight: 500;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--ecg-blue);
  color: var(--text-on-blue);
}
.btn-primary:hover:not(:disabled)  { background: var(--ecg-blue-dark); }

.btn-secondary {
  background: var(--surface);
  color: var(--ecg-navy);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-alt);
  border-color: var(--ecg-blue);
  color: var(--ecg-blue-dark);
}

.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: white;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) { color: var(--ecg-blue); }

input:not([type="radio"]):not([type="checkbox"]),
select, textarea {
  font-family: var(--sans);
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:not([type="radio"]):not([type="checkbox"]):focus,
select:focus, textarea:focus {
  outline: none;
  border-color: var(--ecg-blue);
  box-shadow: 0 0 0 3px rgba(46,143,204,0.15);
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ecg-navy);
  margin-bottom: 6px;
}

.field { margin-bottom: 18px; }
.field-help { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ==== Header (used on every page) ==================================== */
.app-header {
  background: var(--surface);
  border-bottom: 3px solid var(--ecg-blue);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  /* v5.6.9: don't wrap the three top-level header children. Brand sits
     on the left, sign-out on the right, nav-actions take the middle and
     wrap their own internal buttons across multiple rows if needed. This
     keeps Sign Out anchored to the top-right at every laptop width, only
     wrapping below the brand at mobile (handled by media query below). */
  flex-wrap: nowrap;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 46px; height: 46px;
  background: linear-gradient(135deg, var(--ecg-blue) 0%, var(--ecg-blue-light) 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 1px;
  box-shadow: 0 2px 8px rgba(46,143,204,0.4);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name {
  font-size: 18px;
  font-weight: 800;
  color: var(--ecg-navy);
  letter-spacing: 0.5px;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 2px;
}
.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  /* Wrap to multiple rows on narrow viewports (mobile portrait) instead
     of overflowing horizontally. On wide viewports where everything fits
     in one row, wrap is a no-op so desktop layout is unchanged. */
  flex-wrap: wrap;
  /* v5.6.9: take available space AND allow shrinking to zero - the
     combination flex:1 1 0 + min-width:0 lets this container squeeze
     down without forcing the parent to wrap (which would push Sign Out
     to row 2). Internal flex-wrap handles overflow by stacking buttons. */
  flex: 1 1 0;
  min-width: 0;
}
/* Right-anchored container for actions that should always sit on the
   top row next to the brand (typically Sign Out). margin-left: auto
   pushes it to the far right of row 1. */
.header-actions-end {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-left: auto;
  flex-shrink: 0;
}
/* On narrow viewports (mobile portrait), restore the wrap on the parent
   so the nav-actions container can move onto its own row below the brand
   and right-anchored end actions. order: 2 ensures it renders after the
   brand row regardless of source order. */
@media (max-width: 720px) {
  .app-header { flex-wrap: wrap; }
  .header-actions {
    flex-basis: 100%;
    order: 2;
    justify-content: flex-start;
  }
}
.user-chip {
  background: var(--ecg-blue-pale);
  color: var(--ecg-blue-dark);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

/* ==== Main container ================================================= */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 28px;
}
@media (max-width: 600px) { main { padding: 20px 16px; } }

.page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--ecg-navy);
  margin-bottom: 4px;
}
.page-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* ==== Card ===================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

/* ==== Status badge ============================================ */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.status-badge::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.status-badge.running  { color: var(--success); background: var(--success-bg); }
.status-badge.stopped  { color: var(--text-muted); background: var(--neutral-bg); }
.status-badge.offline  { color: var(--danger);  background: var(--danger-bg);  }
.status-badge.due_soon { color: var(--warning); background: var(--warning-bg); }
.status-badge.overdue  { color: var(--danger);  background: var(--danger-bg); }
.status-badge.ok       { color: var(--success); background: var(--success-bg); }

/* Pulse animation for running */
@keyframes pulse {
  0%,100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.status-badge.running::before { animation: pulse 1.5s ease-in-out infinite; }

/* ==== Loading state ============================================= */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--ecg-blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==== Toast ==================================================== */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--ecg-navy);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  animation: slideUp 0.25s ease-out;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
