:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-hover: #30363d;
    --border: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #484f58;
    --accent: #58a6ff;
    --accent-dim: #1f6feb;
    --green: #3fb950;
    --red: #f85149;
    --yellow: #d2991d;
    --orange: #db6d28;
    --radius: 6px;
    --transition: 150ms ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    font-size: 14px;
    overflow: hidden;
    height: 100vh;
}

.app {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.nav-menu {
    flex: 1;
    padding: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    margin-bottom: 2px;
    font-size: 13px;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-dim);
    color: #fff;
}

.nav-icon {
    font-size: 10px;
    width: 16px;
    text-align: center;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 14px;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.stat-card .stat-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
}

.stat-card .stat-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.chart-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.chart-container canvas {
    max-height: 200px;
}

.table-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th {
    text-align: left;
    padding: 10px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
}

table td {
    padding: 10px 16px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

table tr:last-child td {
    border-bottom: none;
}

table tr:hover td {
    background: var(--bg-hover);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-running {
    background: rgba(63, 185, 80, 0.15);
    color: var(--green);
}

.badge-stopped {
    background: rgba(248, 81, 73, 0.15);
    color: var(--red);
}

.badge-unknown {
    background: rgba(139, 148, 158, 0.15);
    color: var(--text-secondary);
}

.badge-valid {
    background: rgba(63, 185, 80, 0.15);
    color: var(--green);
}

.badge-expiring {
    background: rgba(210, 153, 29, 0.15);
    color: var(--yellow);
}

.badge-expired {
    background: rgba(248, 81, 73, 0.15);
    color: var(--red);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
    text-decoration: none;
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-primary {
    background: var(--accent-dim);
    border-color: var(--accent-dim);
    color: #fff;
}

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

.btn-danger {
    background: rgba(248, 81, 73, 0.15);
    border-color: var(--red);
    color: var(--red);
}

.btn-danger:hover {
    background: rgba(248, 81, 73, 0.25);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-group {
    display: flex;
    gap: 6px;
}

.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.file-browser {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.file-path {
    padding: 10px 16px;
    font-size: 13px;
    font-family: "SF Mono", "Fira Code", monospace;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}

.file-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
}

.file-entry:hover {
    background: var(--bg-hover);
}

.file-entry:last-child {
    border-bottom: none;
}

.file-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.file-name .icon {
    color: var(--text-muted);
    font-size: 14px;
}

.file-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 16px;
}

.log-viewer {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 12px;
    line-height: 1.6;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    color: var(--text-secondary);
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}

.alert-info {
    background: rgba(88, 166, 255, 0.1);
    border: 1px solid rgba(88, 166, 255, 0.2);
    color: var(--accent);
}

.alert-warning {
    background: rgba(210, 153, 29, 0.1);
    border: 1px solid rgba(210, 153, 29, 0.2);
    color: var(--yellow);
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }
    .sidebar-header h2,
    .nav-item span:not(.nav-icon),
    .sidebar-footer {
        display: none;
    }
    .nav-item {
        justify-content: center;
        padding: 10px;
    }
    .main-content {
        padding: 16px;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* ---- Login overlay ---- */
.login-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(13, 17, 23, 0.92);
    backdrop-filter: blur(4px);
    z-index: 1000;
}

.login-card {
    width: 320px;
    max-width: calc(100vw - 32px);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 24px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.login-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 4px;
}

.login-sub {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 20px;
}

.login-field {
    display: block;
    margin-bottom: 14px;
}

.login-field span {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.login-field span em {
    color: var(--text-muted);
    font-style: normal;
}

.login-field input {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition);
}

.login-field input:focus {
    border-color: var(--accent);
}

.login-error {
    font-size: 12px;
    color: var(--red);
    min-height: 16px;
    margin-bottom: 8px;
}

.login-submit {
    width: 100%;
    justify-content: center;
    padding: 9px 14px;
}

.login-submit:disabled {
    opacity: 0.6;
    cursor: default;
}

/* ---- User bar in sidebar footer ---- */
.user-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.user-bar .user-name {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}