/* ═══════════════════════════════════════════════════════════
   Kopia Fleet Console — Main Stylesheet
   Aesthetic: Industrial precision / mission-critical dark
   Fonts: Syne (display) + Space Mono (data/mono)
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg:        #090c10;
  --bg-2:      #0d1117;
  --bg-3:      #161b22;
  --bg-4:      #21262d;
  --border:    #30363d;
  --border-2:  #444c56;
  --text:      #e6edf3;
  --text-2:    #8b949e;
  --text-3:    #6e7681;
  --accent:    #1f6feb;
  --accent-2:  #388bfd;
  --accent-glow: rgba(31,111,235,0.25);

  --healthy:   #3fb950;
  --healthy-bg: rgba(63,185,80,0.12);
  --warning:   #d29922;
  --warning-bg: rgba(210,153,34,0.12);
  --failed:    #f85149;
  --failed-bg: rgba(248,81,73,0.12);
  --stale:     #e3b341;
  --stale-bg:  rgba(227,179,65,0.12);
  --running:   #58a6ff;
  --unknown:   #8b949e;

  --sidebar-w: 220px;
  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 1px 3px rgba(0,0,0,0.4), 0 4px 16px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);

  --font-ui:   'Syne', system-ui, sans-serif;
  --font-mono: 'Space Mono', monospace;
}

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

html { height: 100%; }

body {
  height: 100%;
  font-family: var(--font-ui);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }


/* ═══ LOGIN ════════════════════════════════════════════════════════════════ */

.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  background: var(--bg);
}

.login-bg {
  position: absolute; inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.login-bg-grid {
  position: absolute; inset: -20%;
  background-image:
    linear-gradient(rgba(31,111,235,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31,111,235,0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  transform: perspective(600px) rotateX(20deg);
  transform-origin: center 80%;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 50%, black 0%, transparent 100%);
}

.login-panel {
  position: relative; z-index: 1;
  width: 100%; max-width: 400px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-lg), 0 0 80px rgba(31,111,235,0.08);
}

.login-logo {
  display: flex; justify-content: center;
  margin-bottom: 1.25rem;
}

.login-title {
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: -0.02em;
  color: var(--text);
}

.login-sub {
  font-size: .8rem;
  color: var(--text-3);
  text-align: center;
  margin-top: .25rem;
  margin-bottom: 2rem;
  font-family: var(--font-mono);
}

.login-form { display: flex; flex-direction: column; gap: 1rem; }

.login-error {
  background: var(--failed-bg);
  border: 1px solid rgba(248,81,73,0.35);
  border-radius: var(--radius);
  color: var(--failed);
  padding: .6rem .8rem;
  font-size: .82rem;
  font-family: var(--font-mono);
}


/* ═══ LAYOUT ════════════════════════════════════════════════════════════════ */

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .25rem 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: .5rem;
}

.brand-name {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: .1em;
  color: var(--text);
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 .5rem;
}

.nav-section--bottom {
  margin-top: auto;
  padding-top: .5rem;
  border-top: 1px solid var(--border);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem .75rem;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--text-2);
  font-family: var(--font-ui);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background .15s, color .15s;
}

.nav-item svg {
  width: 16px; height: 16px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}

.nav-item:hover { background: var(--bg-4); color: var(--text); }
.nav-item.active { background: var(--accent-glow); color: var(--accent-2); }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem .75rem;
  margin-top: .25rem;
}

.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.user-info { display: flex; flex-direction: column; min-width: 0; }

.user-name {
  font-size: .8rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.user-logout {
  font-size: .7rem;
  color: var(--text-3);
  background: none; border: none;
  cursor: pointer; padding: 0;
  font-family: var(--font-ui);
  text-align: left;
}
.user-logout:hover { color: var(--failed); }

.main-content {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
}

.view {
  display: none;
  padding: 1.75rem 2rem;
  max-width: 1400px;
  animation: fadeIn .2s ease;
}
.view.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--text);
}

.page-sub {
  font-size: .75rem;
  color: var(--text-3);
  font-family: var(--font-mono);
  margin-top: .2rem;
  display: block;
}

.header-actions { display: flex; gap: .5rem; align-items: center; }


/* ═══ STATS GRID ═══════════════════════════════════════════════════════════ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.1rem .9rem;
  position: relative;
  overflow: hidden;
  transition: border-color .2s;
}

.stat-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--border-2);
}
.stat-card--healthy::before  { background: var(--healthy); }
.stat-card--warning::before  { background: var(--warning); }
.stat-card--failed::before   { background: var(--failed); }
.stat-card--stale::before    { background: var(--stale); }

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -.04em;
  font-family: var(--font-mono);
  line-height: 1;
  color: var(--text);
}

.stat-label {
  font-size: .7rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 700;
  margin-top: .35rem;
}

.stat-indicator {
  position: absolute; right: 1rem; top: 1rem;
  width: 8px; height: 8px; border-radius: 50%;
}
.stat-indicator.healthy { background: var(--healthy); box-shadow: 0 0 6px var(--healthy); }
.stat-indicator.warning { background: var(--warning); box-shadow: 0 0 6px var(--warning); }
.stat-indicator.failed  { background: var(--failed);  box-shadow: 0 0 6px var(--failed);  }
.stat-indicator.stale   { background: var(--stale);   box-shadow: 0 0 6px var(--stale);   }


/* ═══ CARDS & SECTIONS ═════════════════════════════════════════════════════ */

.section-card {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-size: .9rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
}

.subsection-title {
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: .75rem;
}

.section-desc {
  font-size: .82rem;
  color: var(--text-2);
  margin-bottom: 1rem;
  line-height: 1.6;
}


/* ═══ TABLE ════════════════════════════════════════════════════════════════ */

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}

.data-table th {
  padding: .6rem 1rem;
  text-align: left;
  font-size: .67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-3);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background .1s; }
.data-table tbody tr:hover td { background: var(--bg-4); }
.data-table tbody tr.clickable { cursor: pointer; }

.empty-row {
  text-align: center;
  color: var(--text-3);
  padding: 2.5rem !important;
  font-family: var(--font-mono);
  font-size: .8rem;
}

.mono { font-family: var(--font-mono); }
.muted { color: var(--text-2); }
.text-sm { font-size: .78rem; }


/* ═══ BADGES ════════════════════════════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  border-radius: 4px;
  padding: .18rem .45rem;
  font-size: .68rem;
  font-weight: 700;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}
.badge::before {
  content: '';
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
}

.badge-healthy { background: var(--healthy-bg); color: var(--healthy); }
.badge-healthy::before { background: var(--healthy); }
.badge-warning  { background: var(--warning-bg);  color: var(--warning); }
.badge-warning::before  { background: var(--warning); }
.badge-failed   { background: var(--failed-bg);   color: var(--failed); }
.badge-failed::before   { background: var(--failed); }
.badge-stale    { background: var(--stale-bg);    color: var(--stale); }
.badge-stale::before    { background: var(--stale); }
.badge-running  { background: rgba(88,166,255,.12); color: var(--running); }
.badge-running::before  { background: var(--running); animation: pulse 1.5s infinite; }
.badge-unknown  { background: rgba(139,148,158,.1); color: var(--unknown); }
.badge-unknown::before  { background: var(--unknown); }

@keyframes pulse {
  0%, 100% { opacity: 1; } 50% { opacity: .3; }
}


/* ═══ BUTTONS ════════════════════════════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: var(--font-ui);
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn svg {
  width: 14px; height: 14px;
  stroke: currentColor; fill: none;
  stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-4); color: var(--text); border-color: var(--border-2); }

.btn-danger {
  background: var(--failed-bg);
  color: var(--failed);
  border-color: rgba(248,81,73,0.3);
}
.btn-danger:hover { background: rgba(248,81,73,0.25); }

.btn-sm { padding: .35rem .7rem; font-size: .75rem; }
.btn-full { width: 100%; justify-content: center; padding: .7rem; }


/* ═══ FORMS ════════════════════════════════════════════════════════════════ */

.field-group { display: flex; flex-direction: column; gap: .4rem; }

.field-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-2);
}

.field-input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .6rem .8rem;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: .85rem;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}

.field-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field-input::placeholder { color: var(--text-3); }

.totp-input {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  letter-spacing: .3em;
  text-align: center;
}

.search-input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .4rem .7rem;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: .82rem;
  width: 220px;
}
.search-input:focus { outline: none; border-color: var(--accent); }

.form-stack { display: flex; flex-direction: column; gap: .9rem; padding: 1.25rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

.form-msg {
  font-size: .78rem;
  font-family: var(--font-mono);
  padding: .5rem .7rem;
  border-radius: var(--radius);
}
.form-msg.success { background: var(--healthy-bg); color: var(--healthy); }
.form-msg.error   { background: var(--failed-bg);  color: var(--failed);  }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .82rem;
  color: var(--text-2);
  cursor: pointer;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}


/* ═══ AGENT CARDS ═══════════════════════════════════════════════════════════ */

.agent-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  padding: 1.25rem;
}

.agent-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
  position: relative;
  overflow: hidden;
}

.agent-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.agent-card.health-healthy::before  { background: var(--healthy); }
.agent-card.health-warning::before  { background: var(--warning); }
.agent-card.health-failed::before   { background: var(--failed);  }
.agent-card.health-stale::before    { background: var(--stale);   }
.agent-card.health-unknown::before  { background: var(--border-2); }

.agent-card:hover { border-color: var(--border-2); transform: translateY(-2px); }

.agent-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: .6rem; }
.agent-card-name { font-weight: 700; font-size: .9rem; color: var(--text); }
.agent-card-customer { font-size: .75rem; color: var(--text-3); margin-top: .1rem; }
.agent-card-meta { font-size: .72rem; color: var(--text-3); font-family: var(--font-mono); margin-top: .5rem; }
.agent-card-meta span { display: block; margin-top: .15rem; }


/* ═══ MODAL ════════════════════════════════════════════════════════════════ */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(9,12,16,.85);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
}

.modal-panel {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 1000px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .25s cubic-bezier(.16,1,.3,1);
}

@keyframes slideUp { from { opacity: 0; transform: translateY(24px) scale(.97); } to { opacity: 1; transform: none; } }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 1rem; font-weight: 800; color: var(--text); }
.modal-sub   { font-size: .75rem; color: var(--text-3); font-family: var(--font-mono); display: block; margin-top: .2rem; }

.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-3); padding: .25rem;
  border-radius: var(--radius);
  display: flex;
}
.modal-close:hover { color: var(--text); background: var(--bg-4); }
.modal-close svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2.5; stroke-linecap: round; }

.modal-body { padding: 1.5rem; }
.modal-meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .75rem;
  margin-bottom: 1.5rem;
}

.meta-item { }
.meta-item-label { font-size: .65rem; text-transform: uppercase; letter-spacing: .09em; color: var(--text-3); font-weight: 700; }
.meta-item-value { font-size: .82rem; color: var(--text); font-family: var(--font-mono); margin-top: .15rem; }


/* ═══ TREND CHART ═══════════════════════════════════════════════════════════ */

.trend-section { margin-bottom: 1.5rem; }

.trend-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 60px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem .6rem;
}

.trend-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  height: 100%;
  justify-content: flex-end;
}

.trend-bar {
  width: 100%;
  border-radius: 2px;
  min-height: 2px;
  transition: opacity .15s;
}
.trend-bar:hover { opacity: .7; }
.trend-bar.success { background: var(--healthy); }
.trend-bar.failed  { background: var(--failed); }
.trend-empty { color: var(--text-3); font-size: .78rem; font-family: var(--font-mono); margin: auto; }


/* ═══ SETTINGS ════════════════════════════════════════════════════════════ */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1.25rem;
  align-items: start;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .75rem;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: .3rem .65rem;
  border-radius: 999px;
}
.status-pill--green { background: var(--healthy-bg); color: var(--healthy); }
.status-pill--muted { background: var(--bg-4); color: var(--text-3); }

.qr-wrap { display: flex; justify-content: center; margin: 1rem 0; }
.qr-img {
  width: 160px; height: 160px;
  border-radius: var(--radius);
  border: 4px solid white;
}

.secret-label {
  font-size: .75rem;
  color: var(--text-2);
  text-align: center;
  margin-bottom: 1rem;
}
.secret-label code {
  font-family: var(--font-mono);
  color: var(--accent-2);
  font-size: .8rem;
}

.user-list { display: flex; flex-direction: column; gap: .5rem; padding: 0 1.25rem; }
.user-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem .75rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.user-list-name { font-weight: 700; font-size: .82rem; }
.user-list-meta { font-size: .72rem; color: var(--text-3); font-family: var(--font-mono); }

#userMgmtCard .form-stack { padding-top: 0; }


/* ═══ TOAST ════════════════════════════════════════════════════════════════ */

.toast-container {
  position: fixed;
  bottom: 1.5rem; right: 1.5rem;
  z-index: 9999;
  display: flex; flex-direction: column; gap: .5rem;
}

.toast {
  background: var(--bg-4);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: .65rem 1rem;
  font-size: .8rem;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toastIn .2s ease;
  max-width: 320px;
}
.toast.success { border-color: rgba(63,185,80,.4); }
.toast.error   { border-color: rgba(248,81,73,.4); color: var(--failed); }

@keyframes toastIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

.empty-state {
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: .82rem;
  padding: 3rem;
  text-align: center;
}


/* ═══ RESPONSIVE ════════════════════════════════════════════════════════════ */

@media (max-width: 900px) {
  :root { --sidebar-w: 60px; }
  .brand-name, .nav-item span, .user-info { display: none; }
  .nav-item { justify-content: center; padding: .55rem; }
  .sidebar-brand { justify-content: center; padding: .25rem .5rem 1.25rem; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .view { padding: 1rem; }
  .settings-grid { grid-template-columns: 1fr; }
}
