/* Cockpit Ops — mobile-first, dense, lisible */
:root {
    --bg: #0f172a;
    --bg-2: #1e293b;
    --card: #1e293b;
    --card-hover: #334155;
    --text: #f1f5f9;
    --text-dim: #94a3b8;
    --border: #334155;
    --primary: #38bdf8;
    --primary-hover: #0ea5e9;
    --danger: #ef4444;
    --warning: #f97316;
    --success: #22c55e;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --radius: 10px;
    --gap: 12px;
    --pad: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

code {
    background: var(--bg-2);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* Topbar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding-top: max(10px, env(safe-area-inset-top));
}
.topbar-title { display: flex; gap: 8px; align-items: baseline; }
.topbar-title strong { font-size: 1.1rem; color: var(--primary); }
.topbar-sub { color: var(--text-dim); font-size: 0.9rem; }
.topbar-actions { display: flex; gap: 12px; align-items: center; }
.badge-alert {
    background: var(--danger);
    color: #fff;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}
.logout-link { color: var(--text-dim); font-size: 1.2rem; }

/* Content */
.content {
    padding: var(--pad);
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
    max-width: 1100px;
    margin: 0 auto;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.section-head h2 { margin: 0; font-size: 1.15rem; }
.hint, .hint-inline {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin: 8px 0 14px;
}

/* Cards */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--pad);
    margin-bottom: var(--gap);
    box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 4px; font-size: 1rem; }
.card-sub { color: var(--text-dim); font-size: 0.85rem; margin: 0 0 8px; }
.card-meta { color: var(--text-dim); font-size: 0.8rem; margin: 6px 0 0; }
.muted { color: var(--text-dim); }

/* Grids */
.sites-grid, .caches-grid, .business-grid, .seo-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--gap);
}
@media (min-width: 600px) {
    .sites-grid, .caches-grid, .business-grid, .seo-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* Site card */
.site-card-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.site-card-head h3 { flex: 1; }
.external { color: var(--text-dim); font-size: 1.1rem; }
.site-card-body { display: grid; grid-template-columns: auto auto; gap: 6px 14px; }
.metric { display: flex; flex-direction: column; gap: 2px; }
.metric-label { color: var(--text-dim); font-size: 0.75rem; text-transform: uppercase; }
.metric-value { font-weight: 600; }
.metric-wide { grid-column: 1 / -1; }
.title-clip {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    max-width: 100%;
}
.site-card-actions { display: flex; gap: 6px; margin-top: 10px; }
.sparkline-wrap { grid-column: 1 / -1; margin-top: 6px; color: var(--primary); }

/* Badges */
.badge {
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.badge-green { background: var(--success); }
.badge-orange { background: var(--warning); }
.badge-red { background: var(--danger); }
.badge-grey { background: var(--text-dim); }

/* Buttons */
.btn-primary, .btn-ghost, .btn-danger, .btn-link {
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: 500;
    font-family: inherit;
    transition: background 0.1s;
}
.btn-primary {
    background: var(--primary);
    color: var(--bg);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-link { background: none; color: var(--primary); padding: 2px 6px; }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; }

/* Cache buttons */
.cache-buttons { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.cache-buttons .btn-primary { flex: 1; min-width: 90px; }

/* Results */
.results-stack { margin-bottom: 14px; }
.result-row {
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 6px;
    border-left: 3px solid var(--text-dim);
    background: var(--bg-2);
    font-size: 0.88rem;
    animation: slideIn 0.2s ease-out;
}
.result-ok { border-left-color: var(--success); }
.result-fail { border-left-color: var(--danger); }
.result-detail { color: var(--text-dim); font-size: 0.8rem; margin-top: 3px; }
.ms { color: var(--text-dim); font-size: 0.78rem; }
@keyframes slideIn {
    from { transform: translateY(-6px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Status */
.status-ok { color: var(--success); }
.status-fail { color: var(--danger); }
.status-partial { color: var(--warning); }

/* Alerts banner */
.alerts-banner {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    padding: var(--pad);
    margin-bottom: var(--gap);
}
.alerts-banner ul { margin: 8px 0 0; padding-left: 16px; list-style: none; }
.alerts-banner li { padding: 4px 0; display: flex; gap: 8px; align-items: center; }
.severity {
    display: inline-block;
    font-size: 0.7rem;
    text-transform: uppercase;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 700;
}
.sev-critical { background: var(--danger); color: #fff; }
.sev-info { background: var(--success); color: #fff; }

/* Business */
.business-card-head { display: flex; justify-content: space-between; align-items: center; }
.biz-stats { display: flex; gap: 14px; flex-wrap: wrap; margin: 8px 0 14px; }
.biz-block {
    display: flex;
    flex-direction: column;
    padding: 6px 10px;
    background: rgba(56, 189, 248, 0.08);
    border-radius: 6px;
    text-decoration: none;
    color: var(--text);
    min-width: 80px;
}
a.biz-block:hover { background: rgba(56, 189, 248, 0.15); }
.biz-block.muted { background: transparent; }
.biz-num { font-size: 1.5rem; font-weight: 700; color: var(--primary); line-height: 1.1; }
.biz-block.muted .biz-num { color: var(--text-dim); }
.biz-label { color: var(--text-dim); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.3px; }
.small { font-size: 0.82rem; }

/* Lead section */
.lead-section, .comments-section { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.lead-section h4, .comments-section h4 {
    font-size: 0.78rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin: 0 0 8px;
    font-weight: 600;
}
.lead-list { list-style: none; padding: 0; margin: 0; }
.lead-row { border-bottom: 1px solid var(--border); padding: 6px 0; }
.lead-row:last-child { border-bottom: 0; }
.lead-summary { display: flex; flex-direction: column; gap: 2px; }
.lead-toggle {
    background: none; border: none; color: var(--text); cursor: pointer;
    padding: 0; text-align: left; font-size: 0.9rem; font-family: inherit;
    display: flex; align-items: center; gap: 6px; width: 100%;
}
.lead-toggle:hover { color: var(--primary); }
.lead-toggle .caret { display: inline-block; transition: transform 0.15s; font-size: 0.7rem; }
.lead-toggle.expanded .caret { transform: rotate(90deg); }
.external { color: var(--text-dim); font-size: 0.85rem; }
.lead-meta { color: var(--text-dim); font-size: 0.72rem; padding-left: 14px; }
.lead-detail { padding-left: 14px; }
.lead-detail-content {
    margin-top: 8px;
    padding: 8px 10px;
    background: var(--bg);
    border-radius: 4px;
    border-left: 3px solid var(--primary);
}
.lead-fields { margin: 0; }
.lead-fields dt {
    font-size: 0.7rem;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-top: 6px;
}
.lead-fields dd { margin: 0 0 4px; font-size: 0.88rem; word-break: break-word; }
.lead-detail-meta { color: var(--text-dim); font-size: 0.7rem; margin: 8px 0 0; }
.lead-error, .lead-empty { color: var(--text-dim); font-size: 0.85rem; padding: 6px; }

/* Comment list */
.comment-list { list-style: none; padding: 0; margin: 0; }
.comment-row {
    padding: 10px;
    background: var(--bg);
    border-radius: 6px;
    margin-bottom: 8px;
    border-left: 3px solid var(--warning);
}
.comment-head { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; margin-bottom: 4px; }
.comment-head strong { font-size: 0.92rem; }
.comment-meta { color: var(--text-dim); font-size: 0.72rem; }
.comment-body {
    margin: 4px 0 8px;
    font-size: 0.86rem;
    color: var(--text);
    line-height: 1.4;
    word-break: break-word;
}
.comment-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-success {
    background: var(--success); color: #fff;
    border: none; border-radius: 6px; padding: 5px 10px;
    cursor: pointer; font-family: inherit; font-size: 0.82rem; font-weight: 500;
}
.btn-success:hover { background: #16a34a; }
.btn-warning {
    background: var(--warning); color: #fff;
    border: none; border-radius: 6px; padding: 5px 10px;
    cursor: pointer; font-family: inherit; font-size: 0.82rem; font-weight: 500;
}
.btn-warning:hover { background: #ea580c; }
.comment-success {
    border-left-color: var(--success);
    color: var(--success);
    font-size: 0.85rem;
    background: rgba(34, 197, 94, 0.08);
}
.comment-error {
    border-left-color: var(--danger);
    color: var(--danger);
    font-size: 0.85rem;
    background: rgba(239, 68, 68, 0.08);
}

/* SEO */
.kw-list { list-style: decimal; padding-left: 18px; margin: 8px 0; }
.kw-list li { padding: 4px 0; font-size: 0.9rem; display: flex; gap: 10px; align-items: baseline; }
.kw-query { flex: 1; }
.kw-pos { font-weight: 700; color: var(--primary); }
.kw-clicks { color: var(--text-dim); font-size: 0.78rem; }
.php-errors { margin-top: 10px; font-size: 0.85rem; }
.err-line {
    background: var(--bg);
    border-left: 3px solid var(--danger);
    padding: 6px 8px;
    margin: 4px 0;
    font-size: 0.75rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Bottom navigation */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    display: flex;
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 10;
}
.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0;
    color: var(--text-dim);
    text-decoration: none;
}
.nav-item.active { color: var(--primary); }
.nav-icon { font-size: 1.3rem; }
.nav-label { font-size: 0.7rem; margin-top: 2px; }

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-backdrop.hidden { display: none; }
.modal-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 22px;
    max-width: 380px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.modal-title { margin: 0 0 8px; font-size: 1.05rem; font-weight: 600; }
.modal-detail { margin: 0 0 18px; color: var(--text-dim); font-size: 0.9rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* Toast */
.toast {
    position: fixed;
    bottom: 80px; left: 50%;
    transform: translateX(-50%);
    background: var(--bg-2);
    border: 1px solid var(--border);
    padding: 10px 18px;
    border-radius: 22px;
    font-size: 0.9rem;
    z-index: 50;
    box-shadow: var(--shadow);
    animation: toastIn 0.2s;
}
.toast.hidden { display: none; }
@keyframes toastIn {
    from { transform: translate(-50%, 10px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-card {
    background: var(--card);
    padding: 30px;
    border-radius: var(--radius);
    max-width: 360px;
    width: 100%;
    border: 1px solid var(--border);
}
.login-card h1 { margin: 0 0 4px; color: var(--primary); }
.login-card .subtitle { color: var(--text-dim); margin: 0 0 22px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 0.85rem; color: var(--text-dim); }
.login-card input {
    display: block;
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    margin-top: 4px;
}
.login-card button { width: 100%; padding: 12px; font-size: 1rem; }
.alert-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--danger);
    color: #fecaca;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 14px;
    font-size: 0.88rem;
}

/* Tables */
.actions-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; margin-top: 10px; }
.actions-table th, .actions-table td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}
.actions-table th { color: var(--text-dim); text-transform: uppercase; font-size: 0.7rem; }
.actions-history { margin-top: 22px; font-size: 0.85rem; }
.actions-history summary { cursor: pointer; color: var(--text-dim); }

/* htmx loading */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
.htmx-request.htmx-indicator { display: inline; }

/* Empty state */
.empty { text-align: center; padding: 30px 20px; color: var(--text-dim); }
