/* PCM — Portrait 1080p Optimized */
:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-nav: #141620;
    --bg-input: #22263a;
    --border: #2a2e3f;
    --text: #e4e6f0;
    --text-muted: #8b8fa3;
    --accent: #6c5ce7;
    --accent-hover: #7c6ff7;
    --green: #00b894;
    --yellow: #fdcb6e;
    --red: #e17055;
    --blue: #74b9ff;
    --purple: #a29bfe;
    --radius: 8px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow-x: hidden;
}

/* ── Top Nav ─────────────────────────────────────────── */
.topnav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-nav);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    z-index: 100;
    gap: 12px;
}

.topnav .logo {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.topnav .logo-icon { font-size: 22px; }
.topnav .logo h1 { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; white-space: nowrap; }

.topnav .nav-links {
    display: flex;
    list-style: none;
    gap: 2px;
    flex: 1;
    justify-content: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.topnav .nav-links::-webkit-scrollbar { display: none; }

.topnav .nav-links li {
    padding: 8px 14px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    white-space: nowrap;
    transition: all 0.15s;
    flex-shrink: 0;
}

.topnav .nav-links li:hover {
    background: rgba(108, 92, 231, 0.12);
    color: var(--text);
}

.topnav .nav-links li.active {
    color: var(--accent);
    background: rgba(108, 92, 231, 0.15);
    font-weight: 600;
}

.topnav .ws-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.ws-dot.on { background: var(--green); }
.ws-dot.off { background: var(--red); }

/* ── Main Content ────────────────────────────────────── */
.content {
    padding: 72px 16px 24px;
    max-width: 1080px;
    margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 16px;
}

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

/* ── Stat Cards ──────────────────────────────────────── */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 12px;
    text-align: center;
}

.stat-card.green { border-left: 3px solid var(--green); }
.stat-card.yellow { border-left: 3px solid var(--yellow); }
.stat-card.red { border-left: 3px solid var(--red); }
.stat-card.blue { border-left: 3px solid var(--blue); }
.stat-card.purple { border-left: 3px solid var(--purple); }

.stat-number {
    font-size: 26px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 2px;
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

/* ── Cards ───────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
}

.card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
}

/* ── Enrich Input ────────────────────────────────────── */
.enrich-input {
    display: flex;
    gap: 8px;
}

.enrich-input input {
    flex: 1;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    min-width: 0;
}

.enrich-input input:focus {
    outline: none;
    border-color: var(--accent);
}

.enrich-result {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-input);
    border-radius: var(--radius);
    font-size: 12px;
    white-space: pre-wrap;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    max-height: 50vh;
    overflow-y: auto;
    border: 1px solid var(--border);
    line-height: 1.6;
}

.enrich-result.hidden { display: none; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn.primary { background: var(--accent); color: white; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { border-color: var(--accent); }
.btn.danger { background: var(--red); color: white; }
.btn.small { padding: 6px 12px; font-size: 11px; }

/* ── Project Grid ────────────────────────────────────── */
.project-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.project-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
}

.project-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.project-card h4 { font-size: 14px; font-weight: 600; }
.project-card p { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }

.project-status {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    flex-shrink: 0;
}

.status-stable { background: rgba(0,184,148,0.15); color: var(--green); }
.status-in_progress { background: rgba(253,203,110,0.15); color: var(--yellow); }
.status-broken { background: rgba(225,112,85,0.15); color: var(--red); }
.status-archived { background: rgba(139,143,163,0.15); color: var(--text-muted); }

.project-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.tag {
    font-size: 10px;
    padding: 2px 6px;
    background: var(--bg-input);
    border-radius: 4px;
    color: var(--text-muted);
}

.project-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

/* ── Rules List ──────────────────────────────────────── */
.rule-list { display: flex; flex-direction: column; gap: 8px; }

.rule-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
}

.rule-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.rule-info h4 { font-size: 13px; font-weight: 600; }
.rule-info p { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.rule-trigger {
    font-family: monospace;
    font-size: 11px;
    padding: 2px 6px;
    background: var(--bg-input);
    border-radius: 4px;
    color: var(--accent);
}

.rule-actions { display: flex; gap: 6px; }

/* ── Log List ────────────────────────────────────────── */
.log-list { display: flex; flex-direction: column; gap: 6px; }

.log-entry {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    font-size: 12px;
}

.log-entry .log-time { font-size: 10px; color: var(--text-muted); margin-bottom: 3px; }
.log-entry .log-request { font-weight: 500; margin-bottom: 3px; }

.log-entry .log-enriched {
    font-family: monospace;
    font-size: 11px;
    color: var(--text-muted);
    white-space: pre-wrap;
    max-height: 60px;
    overflow: hidden;
}

/* ── Timeline ────────────────────────────────────────── */
.timeline { position: relative; padding-left: 20px; }

.timeline::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    margin-bottom: 12px;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -17px;
    top: 14px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

.timeline-item .time { font-size: 10px; color: var(--text-muted); margin-bottom: 3px; }

/* ── Modal ───────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 200;
}

.modal.hidden { display: none; }

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 1080px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 20px 16px;
    animation: slideUp 0.2s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h3 { font-size: 16px; }

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
}

/* ── Form ────────────────────────────────────────────── */
.form-group { margin-bottom: 12px; }

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-muted);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* ── Toast ───────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
}

.toast {
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 500;
    animation: toastIn 0.25s ease;
    max-width: 90vw;
    text-align: center;
}

.toast.success { background: var(--green); color: white; }
.toast.error { background: var(--red); color: white; }
.toast.info { background: var(--blue); color: white; }

@keyframes toastIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ── Activity ────────────────────────────────────────── */
.activity-list { font-size: 12px; }
.activity-item {
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    gap: 8px;
}
.activity-item:last-child { border: none; }
.muted { color: var(--text-muted); }

/* ── Utility ─────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Terminal ────────────────────────────────────────── */
.terminal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.terminal-header h2 { margin: 0; font-size: 18px; }
.terminal-status {
    font-size: 13px;
    color: var(--text-muted);
    padding: 4px 10px;
    border-radius: 12px;
    background: var(--card-bg);
}
.terminal-status.connected { color: #4ade80; }
.terminal-status.error { color: #f87171; }

/* Connection form */
.terminal-connect {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}
.terminal-connect-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    width: 100%;
    max-width: 480px;
}
.terminal-connect-card h3 {
    margin: 0 0 4px;
    font-size: 18px;
}
.terminal-connect-card .muted {
    margin: 0 0 20px;
    font-size: 13px;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}
.form-row .form-group {
    margin-bottom: 0;
}
.terminal-connect .btn {
    margin-top: 8px;
    width: 100%;
}

/* Terminal frame */
.terminal-wrapper {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: #000;
}
.terminal-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}
.term-addr {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-muted);
}
.xterm-container {
    flex: 1;
    padding: 8px;
    background: #0f1117;
    overflow: hidden;
}
.xterm-container .xterm {
    height: 100%;
}
