/* app.css — Progent-branded dashboard + login styles for Vault Backup Manager.
 *
 * Colour palette derived from www.progent.com (extracted from production CSS):
 *   --pg-blue:       #011DC9  (primary deep royal blue — header, primary buttons)
 *   --pg-blue-dark:  #0015A0  (hover/pressed shade)
 *   --pg-blue-light: #456EA4  (steel blue — secondary accents, links)
 *   --pg-slate:      #4a4f62  (dark blue-gray — sub-headers, secondary buttons)
 *   --pg-gold:       #ffcc33  (Progent golden yellow — accent highlights)
 *
 * Health indicators use WCAG-AA-compliant dark green/red/amber on white.
 * No third-party CSS (D2/E2). Functions under CSP connect-src 'self'.
 */

/* ====================================================================== */
/* Design tokens                                                          */
/* ====================================================================== */

:root {
  /* Progent brand colours (reference www.progent.com) */
  --pg-blue: #011DC9;
  --pg-blue-dark: #0015A0;
  --pg-blue-light: #456EA4;
  --pg-slate: #4a4f62;
  --pg-slate-light: #5a5f72;
  --pg-gold: #ffcc33;

  /* Health indicators (WCAG AA on white) */
  --health-good: #2e7d32;
  --health-fail: #940a1a;
  --health-amber: #b07000;

  /* Neutrals */
  --pg-text: #333333;
  --pg-text-muted: #666666;
  --pg-border: #dddddd;
  --pg-bg: #f5f6f8;
  --pg-surface: #ffffff;
  --pg-row-hover: #eef1f6;

  /* Focus ring */
  --pg-focus: #011DC9;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  /* Spacing */
  --header-height: 3.75rem;
}

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

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

body {
  font-family: var(--font-sans);
  margin: 0;
  padding: 0;
  background: var(--pg-bg);
  color: var(--pg-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ====================================================================== */
/* Accessibility                                                          */
/* ====================================================================== */

/* Focus-visible outline on all interactive elements (WCAG 2.4.7). */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--pg-focus);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Screen-reader-only utility class. */
.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;
}

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

/* ====================================================================== */
/* Header / navigation (dashboard shell)                                  */
/* ====================================================================== */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2rem;
  height: var(--header-height);
  background: linear-gradient(135deg, var(--pg-blue) 0%, var(--pg-blue-dark) 100%);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  position: sticky;
  top: 0;
  z-index: 50;
}

header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #fff;
}

header h1::before {
  content: "\25C8";
  margin-right: 0.5rem;
  color: var(--pg-gold);
  font-size: 1.1rem;
}

header nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

header nav a {
  color: rgba(255, 255, 255, 0.85);
  margin-left: 1.25rem;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.35rem 0.6rem;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}

header nav a:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

header nav a:focus-visible {
  outline-offset: 0;
}

/* ====================================================================== */
/* Main content area                                                      */
/* ====================================================================== */

main {
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

.grid-status {
  color: var(--pg-text-muted);
  font-size: 0.95rem;
  padding: 0.5rem 0;
}

/* ====================================================================== */
/* Server grid                                                            */
/* ====================================================================== */

.server-grid {
  width: 100%;
  border-collapse: collapse;
  background: var(--pg-surface);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
}

.server-grid th,
.server-grid td {
  text-align: left;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--pg-border);
}

.server-grid th {
  background: var(--pg-slate);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #fff;
}

.server-grid tbody tr:hover {
  background: var(--pg-row-hover);
}

.server-grid td.col-health {
  text-align: center;
  font-size: 1.25rem;
}

.health-good {
  color: var(--health-good);
}

.health-fail {
  color: var(--health-fail);
}

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

.col-count,
.col-size {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  color: var(--pg-text-muted);
  padding: 2rem 0;
}

/* ====================================================================== */
/* Buttons                                                                */
/* ====================================================================== */

.btn-primary {
  display: inline-block;
  background: var(--pg-blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: var(--pg-blue-dark);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: var(--pg-slate);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:hover {
  background: var(--pg-slate-light);
}

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ====================================================================== */
/* Server-name button (opens detail panel)                                */
/* ====================================================================== */

.server-name-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 600;
  color: var(--pg-blue);
  text-align: left;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--pg-blue-light);
  text-underline-offset: 2px;
}

.server-name-btn:hover,
.server-name-btn:focus {
  color: var(--pg-blue-dark);
  text-decoration-color: var(--pg-blue-dark);
}

/* ====================================================================== */
/* In-page overlays (detail panel + log panel) — D1 no navigation         */
/* ====================================================================== */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(1, 29, 201, 0.25);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay[hidden] {
  display: none;
}

.overlay-panel {
  background: var(--pg-surface);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  max-width: 95vw;
  overflow: hidden;
}

/* 80%-viewport detail panel (Requirement #6 / Session 6). */
.detail-panel {
  width: 80vw;
  height: 80vh;
}

.log-panel {
  width: 70vw;
  height: 70vh;
  z-index: 110;
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1.2rem;
  border-bottom: 1px solid var(--pg-border);
  background: var(--pg-slate);
  color: #fff;
  flex-shrink: 0;
}

.overlay-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
}

.overlay-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.overlay-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  padding: 0 0.3rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.overlay-close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
}

/* Override btn-secondary inside coloured overlay-header for contrast. */
.overlay-header .btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.overlay-header .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.28);
}

.overlay-body {
  padding: 1.2rem;
  overflow: auto;
  flex: 1 1 auto;
}

/* ====================================================================== */
/* Backup grid (inside the detail panel)                                  */
/* ====================================================================== */

.backup-grid,
.log-grid {
  width: 100%;
  border-collapse: collapse;
  background: var(--pg-surface);
}

.backup-grid th,
.backup-grid td,
.log-grid th,
.log-grid td {
  text-align: left;
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--pg-border);
  font-size: 0.9rem;
}

.backup-grid th,
.log-grid th {
  background: #eef1f6;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--pg-slate);
  position: sticky;
  top: 0;
}

.backup-grid tbody tr:hover,
.log-grid tbody tr:hover {
  background: var(--pg-row-hover);
}

.col-seq,
.col-vhd {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.col-pct,
.col-size {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.col-log {
  width: 2.5rem;
  text-align: center;
}

/* Status badges — distinct colour per status (C5 vocabulary). */
.status-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-verified-good {
  background: #e3f2e3;
  color: var(--health-good);
}

.status-pending {
  background: #fff4e0;
  color: var(--health-amber);
}

.status-rejected {
  background: #fde3e3;
  color: var(--health-fail);
}

.status-quarantined {
  background: #fbe0fb;
  color: #8e24aa;
}

.status-superseded {
  background: #e8e8e8;
  color: #555;
}

.status-stale-deleted {
  background: #e0e0e0;
  color: #888;
  text-decoration: line-through;
}

/* Rejected / quarantined rows: visibly flagged with a left border. */
.backup-row.status-rejected,
.backup-row.status-quarantined {
  border-left: 4px solid var(--health-fail);
}

.backup-row.status-rejected .col-reason,
.backup-row.status-quarantined .col-reason {
  color: var(--health-fail);
  font-weight: 600;
}

/* Stale-deleted rows shown distinctly (muted + italic). */
.backup-row.status-stale-deleted {
  color: #999;
  font-style: italic;
}

/* Stale verified-good: amber accent on the row. */
.backup-row.is-stale:not(.status-stale-deleted) {
  background: #fff8e1;
}

.backup-row.is-stale:not(.status-stale-deleted):hover {
  background: #fff3c4;
}

.status-badge.is-stale {
  background: #fff3c4;
  color: var(--health-amber);
}

/* Per-row log icon button. */
.log-icon-btn {
  background: none;
  border: 1px solid var(--pg-border);
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s;
}

.log-icon-btn:hover {
  background: var(--pg-row-hover);
  border-color: #bbb;
}

/* ====================================================================== */
/* Log panel                                                               */
/* ====================================================================== */

.log-row .col-message {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.level-badge {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 9px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
}

.level-info {
  background: #e3f0fd;
  color: #1565c0;
}

.level-ok {
  background: #e3f2e3;
  color: var(--health-good);
}

.level-warn {
  background: #fff4e0;
  color: var(--health-amber);
}

.level-err {
  background: #fde3e3;
  color: var(--health-fail);
}

/* ====================================================================== */
/* "Logs" header button + live-log panel (Session 7 SSE)                  */
/* ====================================================================== */

.header-btn {
  margin-left: 1.25rem;
}

/* 80%-viewport live-log panel (Session 7). */
.live-log-panel {
  width: 80vw;
  height: 80vh;
  z-index: 120;
}

.live-log-list {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
}

.live-log-entry {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.15rem 0;
  border-bottom: 1px solid #eee;
}

.live-log-entry .live-log-ts {
  color: var(--pg-text-muted);
  white-space: nowrap;
  flex: 0 0 auto;
}

.live-log-entry .live-log-event {
  font-weight: 600;
  white-space: nowrap;
  flex: 0 0 auto;
  min-width: 5rem;
}

.live-log-entry .live-log-message {
  flex: 1 1 auto;
  word-break: break-word;
}

/* Level-coloured left border on live-log entries. */
.live-log-entry.level-err {
  border-left: 3px solid var(--health-fail);
  padding-left: 0.4rem;
}

.live-log-entry.level-warn {
  border-left: 3px solid var(--health-amber);
  padding-left: 0.4rem;
}

.live-log-entry.level-ok {
  border-left: 3px solid var(--health-good);
  padding-left: 0.4rem;
}

.live-log-entry.level-info {
  border-left: 3px solid #1565c0;
  padding-left: 0.4rem;
}

/* ====================================================================== */
/* Login page (standalone — does NOT extend base.html)                    */
/* ====================================================================== */

.login-page {
  margin: 0;
  padding: 0;
  background: var(--pg-bg);
  color: var(--pg-text);
  min-height: 100vh;
}

.login-container {
  display: flex;
  min-height: 100vh;
}

/* Hero section — deep blue gradient, white text, feature bullets. */
.login-hero {
  flex: 1 1 55%;
  background: linear-gradient(135deg, var(--pg-blue) 0%, var(--pg-blue-dark) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 2.5rem;
}

.login-hero-content {
  max-width: 32rem;
}

.login-hero-content h1 {
  margin: 0 0 0.75rem 0;
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
}

.login-hero-content h1::before {
  content: "\25C8";
  margin-right: 0.6rem;
  color: var(--pg-gold);
  font-size: 1.8rem;
}

.login-hero-subtitle {
  font-size: 1.1rem;
  color: rgba(255, 255, 255, 0.9);
  margin: 0 0 2rem 0;
  line-height: 1.5;
}

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

.login-features li {
  padding: 0.6rem 0;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.login-features li::before {
  content: "\2713";
  color: var(--pg-gold);
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}

/* Form section — white card, password field, sign-in button. */
.login-form-section {
  flex: 1 1 45%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 24rem;
  background: var(--pg-surface);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.login-card h2 {
  margin: 0 0 1.5rem 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--pg-blue);
}

.login-error {
  background: #fde3e3;
  color: var(--health-fail);
  border: 1px solid #f5c6c6;
  border-radius: 6px;
  padding: 0.7rem 1rem;
  margin: 0 0 1.2rem 0;
  font-size: 0.9rem;
  font-weight: 500;
}

.form-field {
  margin-bottom: 1.2rem;
}

.form-field label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--pg-text);
}

.form-field input {
  width: 100%;
  padding: 0.65rem 0.8rem;
  font-size: 1rem;
  font-family: var(--font-sans);
  border: 2px solid var(--pg-border);
  border-radius: 6px;
  color: var(--pg-text);
  background: var(--pg-surface);
  transition: border-color 0.15s;
}

.form-field input:focus {
  border-color: var(--pg-blue);
  outline: none;
}

.form-field input:focus-visible {
  outline: 3px solid var(--pg-focus);
  outline-offset: 1px;
}

.login-card .btn-primary {
  width: 100%;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

.login-footer {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--pg-text-muted);
}

.login-footer strong {
  color: var(--pg-slate);
}

/* ====================================================================== */
/* Responsive — narrow viewports                                          */
/* ====================================================================== */

@media (max-width: 768px) {
  /* Header: reduce padding, smaller title. */
  header {
    padding: 0 1rem;
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-height);
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  header h1 {
    font-size: 1.1rem;
  }

  header nav {
    flex-wrap: wrap;
    gap: 0.1rem;
  }

  header nav a {
    margin-left: 0.5rem;
    font-size: 0.85rem;
  }

  /* Main: reduce padding. */
  main {
    padding: 1rem;
  }

  /* Grid: allow horizontal scroll on narrow screens. */
  .server-grid {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .server-grid thead,
  .server-grid tbody,
  .server-grid tr {
    display: table;
    width: 100%;
    table-layout: fixed;
  }

  /* Overlays: cap to viewport with small margin. */
  .detail-panel,
  .log-panel,
  .live-log-panel {
    width: 95vw;
    height: 88vh;
  }

  /* Login: stack vertically — hero on top, form below. */
  .login-container {
    flex-direction: column;
  }

  .login-hero {
    flex: 0 0 auto;
    padding: 2rem 1.5rem;
    text-align: center;
  }

  .login-hero-content {
    max-width: none;
  }

  .login-hero-content h1 {
    font-size: 1.6rem;
  }

  .login-hero-subtitle {
    font-size: 1rem;
    margin-bottom: 1rem;
  }

  .login-features {
    display: none;
  }

  .login-form-section {
    flex: 1 1 auto;
    padding: 1.5rem 1rem;
  }
}

@media (max-width: 480px) {
  header h1 {
    font-size: 1rem;
  }

  .login-card {
    padding: 1.75rem 1.25rem;
  }

  .login-card h2 {
    font-size: 1.25rem;
  }

  .overlay-body {
    padding: 0.8rem;
  }

  .backup-grid th,
  .backup-grid td,
  .log-grid th,
  .log-grid td {
    padding: 0.4rem 0.5rem;
    font-size: 0.82rem;
  }
}
