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

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-2: #222536;
    --border: #2a2d3a;
    --text: #e2e8f0;
    --muted: #64748b;
    --accent: #6366f1;
    --green: #22c55e;
    --yellow: #eab308;
    --red: #ef4444;
    --orange: #f97316;
}

body { background: var(--bg); color: var(--text); font-family: system-ui, sans-serif; font-size: 14px; line-height: 1.6; }

/* ── Nav ─────────────────────────────────────────────────────────────────── */
.navbar { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.nav-brand { font-weight: 700; font-size: 1.1rem; color: var(--accent); text-decoration: none; }
.nav-links a { color: var(--muted); text-decoration: none; margin-left: 1.5rem; transition: color 0.15s; }
.nav-links a:hover { color: var(--text); }

.container { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header { margin-bottom: 1.5rem; }
.page-title  { font-size: 1.5rem; font-weight: 700; }
.page-sub    { color: var(--muted); font-size: 0.85rem; }

/* ── Summary bar ─────────────────────────────────────────────────────────── */
.summary-bar {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.summary-item  { display: flex; align-items: baseline; gap: 0.3rem; }
.summary-count { font-size: 1.25rem; font-weight: 700; }
.summary-count.healthy  { color: var(--green); }
.summary-count.degraded { color: var(--yellow); }
.summary-count.down     { color: var(--red); }
.summary-label   { color: var(--muted); font-size: 0.8rem; }
.summary-divider { width: 1px; height: 1.25rem; background: var(--border); }
.summary-refresh { color: var(--muted); font-size: 0.8rem; margin-left: auto; }

/* ── App card grid ───────────────────────────────────────────────────────── */
.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.app-card {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem 1.1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, transform 0.1s;
    cursor: pointer;
}
.app-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.app-card.status-down     { border-left: 3px solid var(--red); }
.app-card.status-degraded { border-left: 3px solid var(--yellow); }
.app-card.status-healthy  { border-left: 3px solid var(--green); }
.app-card.status-unknown  { border-left: 3px solid var(--muted); }

.card-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.card-name   { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-slug   { color: var(--muted); font-size: 0.75rem; font-family: monospace; margin-top: -0.5rem; }

/* ── Metric bars ─────────────────────────────────────────────────────────── */
.card-metrics { display: flex; flex-direction: column; gap: 0.4rem; }
.metric       { display: grid; grid-template-columns: 2.5rem 3rem 1fr; align-items: center; gap: 0.4rem; }
.metric-label { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; }
.metric-value { font-size: 0.8rem; font-weight: 600; text-align: right; }
.metric-bar   { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.metric-fill  { height: 100%; border-radius: 2px; transition: width 0.4s; }
.fill-green  { background: var(--green); }
.fill-yellow { background: var(--yellow); }
.fill-red    { background: var(--red); }

/* ── Card footer stats ───────────────────────────────────────────────────── */
.card-footer { display: flex; justify-content: space-between; padding-top: 0.5rem; border-top: 1px solid var(--border); }
.card-stat   { display: flex; flex-direction: column; align-items: center; }
.stat-value  { font-size: 0.9rem; font-weight: 600; }
.stat-label  { color: var(--muted); font-size: 0.7rem; }
.stat-error .stat-value { color: var(--red); }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state  { text-align: center; padding: 4rem 2rem; color: var(--muted); }
.empty-title  { font-size: 1.1rem; font-weight: 600; color: var(--text); margin-bottom: 0.5rem; }
.empty-sub    { margin-bottom: 1.5rem; }
.empty-code   { display: inline-block; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.25rem; font-size: 0.8rem; color: var(--text); white-space: pre; }

/* ── Status badges ───────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 9999px; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.badge-healthy  { background: #14532d; color: var(--green); }
.badge-degraded { background: #713f12; color: var(--yellow); }
.badge-down     { background: #7f1d1d; color: var(--red); }
.badge-unknown  { background: #1e293b; color: var(--muted); }

/* ── Log level colours ───────────────────────────────────────────────────── */
.level-DEBUG    { color: var(--muted); }
.level-INFO     { color: var(--text); }
.level-WARNING  { color: var(--yellow); }
.level-ERROR    { color: var(--red); }
.level-CRITICAL { color: var(--red); font-weight: 700; }

/* ── Detail page (Phase 4) ───────────────────────────────────────────────── */
.detail-layout  { display: grid; grid-template-columns: 1fr 300px; gap: 1.5rem; }
.panel          { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1.1rem; }
.panel-title    { font-weight: 600; margin-bottom: 0.75rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }

.log-table      { width: 100%; border-collapse: collapse; }
.log-table th   { text-align: left; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); }
.log-table td   { padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 0.82rem; }
.log-table tr:last-child td { border-bottom: none; }
.log-table tr:hover td { background: var(--surface-2); }
.log-ts         { color: var(--muted); white-space: nowrap; font-family: monospace; font-size: 0.75rem; }
.log-source     { color: var(--muted); font-family: monospace; font-size: 0.75rem; }
.log-msg        { word-break: break-word; max-width: 520px; }

.filter-bar     { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-btn     { padding: 0.25rem 0.75rem; border-radius: 9999px; border: 1px solid var(--border); background: transparent; color: var(--muted); font-size: 0.8rem; cursor: pointer; transition: all 0.15s; }
.filter-btn:hover, .filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.health-list    { display: flex; flex-direction: column; gap: 0.4rem; }
.health-row     { display: flex; align-items: center; justify-content: space-between; padding: 0.35rem 0; border-bottom: 1px solid var(--border); font-size: 0.8rem; }
.health-row:last-child { border-bottom: none; }
.health-ts      { color: var(--muted); font-size: 0.72rem; font-family: monospace; }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }

.login-card {
    width: 100%;
    max-width: 380px;
    padding: 2.25rem 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.login-brand { color: var(--accent); font-weight: 700; font-size: 1.05rem; margin-bottom: 1.75rem; letter-spacing: 0.01em; }
.login-title { font-size: 1.35rem; font-weight: 700; margin-bottom: 1.5rem; }

.login-error {
    background: rgba(127, 29, 29, 0.5);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 6px;
    padding: 0.65rem 0.85rem;
    font-size: 0.84rem;
    line-height: 1.5;
    margin-bottom: 1.25rem;
}

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

.login-field { display: flex; flex-direction: column; gap: 0.35rem; }
.login-field label { font-size: 0.8rem; color: var(--muted); font-weight: 500; letter-spacing: 0.02em; }

.login-field input {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.8rem;
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.login-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15); }
.login-field input:disabled { opacity: 0.45; cursor: not-allowed; }

.login-btn {
    margin-top: 0.25rem;
    padding: 0.65rem;
    background: var(--accent);
    border: none;
    border-radius: 6px;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
}
.login-btn:hover:not(:disabled) { opacity: 0.88; transform: translateY(-1px); }
.login-btn:active:not(:disabled) { transform: translateY(0); }
.login-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Portal home ─────────────────────────────────────────────────────────── */

/* Hero — breaks out of .container padding to go edge-to-edge */
.portal-hero {
    position: relative;
    margin: -2rem -1.5rem 2.5rem;
    padding: 4rem 1.5rem 3.5rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
}
/* Radial glow behind title */
.portal-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse 90% 60% at 50% -5%, rgba(99,102,241,0.18) 0%, transparent 70%);
    pointer-events: none;
}
/* Dot grid overlay */
.portal-hero::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(circle, rgba(99,102,241,0.12) 1px, transparent 1px);
    background-size: 28px 28px;
    pointer-events: none;
}

.portal-hero-inner {
    position: relative;
    z-index: 1;
    max-width: 660px;
    margin: 0 auto;
}

.portal-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.85rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.28);
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #fca5a5;
    margin-bottom: 1.5rem;
}
.portal-eyebrow-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--red);
    box-shadow: 0 0 5px var(--red);
    animation: pulse-dot 1.5s ease-in-out infinite;
}

.portal-hero-title {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: -0.025em;
    color: var(--text);
    margin-bottom: 1rem;
}
.portal-hero-accent {
    background: linear-gradient(135deg, #818cf8 0%, #6366f1 40%, #a78bfa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.portal-hero-sub {
    font-size: 0.87rem;
    color: var(--muted);
    line-height: 1.75;
    max-width: 520px;
    margin: 0 auto 2rem;
}

.portal-hero-meta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.portal-user-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9999px;
    font-size: 0.78rem;
    color: var(--muted);
}
.portal-user-badge strong { color: var(--text); font-weight: 600; }
.portal-user-badge svg   { color: var(--accent); flex-shrink: 0; }

.portal-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem 0.85rem;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.22);
    border-radius: 9999px;
    font-size: 0.78rem;
    color: var(--green);
    font-weight: 500;
}
.portal-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.3; }
}

/* Tools section header */
.portal-tools-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.portal-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
}
.portal-tool-count {
    font-size: 0.7rem;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9999px;
    padding: 0.1rem 0.6rem;
}

/* Card grid */
.portal-nav-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

/* Card */
.portal-nav-card {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    overflow: hidden;
    transition: border-color 0.22s ease, transform 0.22s ease, box-shadow 0.22s ease;
}

/* Shimmer gradient overlay — fades in on hover */
.portal-nav-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(99,102,241,0.09) 0%, rgba(167,139,250,0.04) 50%, transparent 70%);
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
    border-radius: inherit;
}

/* Top accent bar — slides in from left on hover */
.portal-nav-card::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, #6366f1 0%, #a78bfa 60%, #818cf8 100%);
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 0.3s ease;
    border-radius: 12px 12px 0 0;
}

.portal-nav-card:hover {
    border-color: rgba(99,102,241,0.5);
    transform: translateY(-3px);
    box-shadow: 0 10px 32px rgba(99,102,241,0.14), 0 2px 8px rgba(0,0,0,0.25);
}
.portal-nav-card:hover::before { opacity: 1; }
.portal-nav-card:hover::after  { transform: scaleX(1); }

/* Card top row: icon + arrow */
.portal-nav-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.1rem;
}

.portal-nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    background: rgba(99,102,241,0.1);
    border: 1px solid rgba(99,102,241,0.22);
    border-radius: 10px;
    color: var(--accent);
    transition: background 0.22s, border-color 0.22s, box-shadow 0.22s;
}
.portal-nav-card:hover .portal-nav-icon {
    background: rgba(99,102,241,0.18);
    border-color: rgba(99,102,241,0.45);
    box-shadow: 0 0 14px rgba(99,102,241,0.2);
}

.portal-nav-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    color: var(--muted);
    transition: color 0.22s, background 0.22s, transform 0.22s;
}
.portal-nav-card:hover .portal-nav-arrow {
    color: var(--accent);
    background: rgba(99,102,241,0.1);
    transform: translate(2px, -2px);
}

/* Card text */
.portal-nav-title {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
    color: var(--text);
    margin-bottom: 0.4rem;
}
.portal-nav-desc {
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.65;
    flex: 1;
    margin-bottom: 1.25rem;
}

/* Card footer */
.portal-nav-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.portal-nav-tag {
    font-family: monospace;
    font-size: 0.69rem;
    color: var(--muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.15rem 0.45rem;
    letter-spacing: 0.03em;
}
.portal-nav-launch {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    transition: color 0.22s;
}
.portal-nav-card:hover .portal-nav-launch { color: var(--accent); }

@media (max-width: 768px) {
    .detail-layout { grid-template-columns: 1fr; }
    .app-grid      { grid-template-columns: 1fr; }
    .login-card    { margin: 1rem; }
    .portal-hero   { margin: -2rem -1rem 2rem; padding: 3rem 1rem 2.5rem; }
    .portal-nav-grid  { grid-template-columns: 1fr; }
    .portal-hero-meta { flex-direction: column; }
}
