:root {
    --bg: #fafaf9;
    --surface: #ffffff;
    --surface-2: #f5f5f4;
    --border: #e7e5e4;
    --border-strong: #d6d3d1;
    --text: #1c1917;
    --text-muted: #78716c;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-soft: #eef2ff;
    --success: #10b981;
    --success-soft: #ecfdf5;
    --warning: #f59e0b;
    --warning-soft: #fef3c7;
    --danger:  #ef4444;
    --danger-soft: #fef2f2;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow:    0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.10), 0 4px 6px rgba(0, 0, 0, 0.05);
    --radius: 10px;
    --radius-sm: 6px;
    --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

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

/* ─── App layout ─────────────────────────────────────────── */
.app {
    display: grid;
    grid-template-columns: 240px 1fr;
    height: 100vh;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 20px;
    font-weight: 600;
    font-size: 15px;
}

.brand-mark {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
}
.login-mark { width: 36px; height: 36px; border-radius: 9px; }

.nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    font-size: 13.5px;
    transition: background 0.12s ease;
    border: none;
    background: transparent;
    text-align: left;
    width: 100%;
}
.nav-item:hover  { background: var(--surface-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-hover); font-weight: 500; }

.nav-icon {
    width: 16px; height: 16px;
    flex-shrink: 0;
    opacity: 0.85;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.nav-icon svg { width: 100%; height: 100%; }

.sidebar-footer {
    padding: 12px 10px 4px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: space-between;
}

.icon-btn {
    width: 28px; height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

.muted { color: var(--text-muted); font-size: 12px; }
.small { font-size: 12px; }

.dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
    vertical-align: middle;
    margin-right: 4px;
}
.dot.ok  { background: var(--success); }
.dot.bad { background: var(--danger); }

.content {
    overflow-y: auto;
    padding: 32px 40px;
}

/* ─── Login ─────────────────────────────────────────────── */
.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 16px;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 32px;
    width: 100%;
    max-width: 420px;
}
.login-card h1 {
    margin: 12px 0 4px;
    font-size: 22px;
}
.login-card p { margin: 0 0 18px; }
.login-card label {
    display: block;
    margin-bottom: 14px;
    font-size: 13px;
    color: var(--text-muted);
}
.login-card label input {
    margin-top: 6px;
    width: 100%;
}
.login-card button { width: 100%; padding: 10px; margin-top: 8px; }

/* ─── Headers ───────────────────────────────────────────── */
.page-header { margin-bottom: 24px; }
.page-header h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.page-header p  { margin: 0; color: var(--text-muted); font-size: 13.5px; }

/* ─── Cards / grids ─────────────────────────────────────── */
.grid { display: grid; gap: 16px; }
@media (min-width: 1100px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-title { margin: 0; font-size: 13.5px; font-weight: 600; }
.card-body  { padding: 16px; }

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}
.field label { font-size: 12.5px; font-weight: 500; color: var(--text-muted); }

/* ─── Inputs ────────────────────────────────────────────── */
textarea, input, select {
    font-family: var(--font);
    font-size: 13px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    outline: none;
    transition: border-color 0.12s, box-shadow 0.12s;
    width: 100%;
}
textarea {
    resize: vertical;
    min-height: 240px;
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.55;
}
textarea:focus, input:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

/* ─── Buttons ───────────────────────────────────────────── */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, transform 0.05s;
    font-family: var(--font);
    white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-warn  { background: var(--warning); border-color: var(--warning); color: white; }
.btn-warn:hover  { background: #d97706; border-color: #d97706; }

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

.link-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 14px;
}
.link-btn:hover { background: var(--surface-2); color: var(--danger); }

/* ─── Output / mono ─────────────────────────────────────── */
.output {
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.6;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text);
    min-height: 220px;
    max-height: 600px;
    overflow-y: auto;
}

/* ─── Chips / meta ──────────────────────────────────────── */
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 11.5px;
    color: var(--text-muted);
}
.chip strong { color: var(--text); font-weight: 500; }
.chip-ok  { background: var(--success-soft); border-color: #d1fae5; color: #047857; }
.chip-off { background: var(--surface-2); }

.chip-state-stopped { background: var(--surface-2); color: var(--text-muted); }
.chip-state-running { background: var(--success-soft); color: #047857; border-color: #d1fae5; }
.chip-state-error   { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }

/* ─── Tables ────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table th,
.data-table td {
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table th {
    font-weight: 500;
    color: var(--text-muted);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--surface-2);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr.mail-replied { opacity: 0.7; }

/* ─── Modals ────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(28, 25, 23, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 90;
    padding: 16px;
    backdrop-filter: blur(2px);
}
.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 22px;
    width: 100%;
    max-width: 440px;
}
.modal-wide { max-width: 720px; }
.modal h2 { margin: 0 0 14px; font-size: 17px; }
.modal label {
    display: block;
    margin-bottom: 12px;
    font-size: 12.5px;
    color: var(--text-muted);
}
.modal label input,
.modal label select { margin-top: 6px; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.form-grid label.full { grid-column: 1 / -1; }
@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
}

/* ─── Misc ──────────────────────────────────────────────── */
.empty {
    color: var(--text-muted);
    font-style: italic;
    padding: 18px 16px;
    text-align: center;
}
.error {
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 12.5px;
    margin-bottom: 12px;
}

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--text);
    color: white;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.15s, transform 0.15s;
    pointer-events: none;
    z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast[data-kind="error"] { background: var(--danger); }

code {
    font-family: var(--mono);
    font-size: 12px;
    background: var(--surface-2);
    padding: 1px 5px;
    border-radius: 4px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
