/* ─────────────────────────────────────────────────────────────────────────── */
/* AligneerManager — stylesheet                                                 */
/* ─────────────────────────────────────────────────────────────────────────── */

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

:root {
    --bg:         #f4f6f9;
    --surface:    #ffffff;
    --border:     #e2e8f0;
    --text:       #1a202c;
    --text-muted: #718096;
    --primary:    #3b82f6;
    --primary-h:  #2563eb;
    --danger:     #ef4444;
    --danger-h:   #dc2626;
    --success:    #22c55e;
    --warning:    #f59e0b;
    --radius:     8px;
    --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    /* Plan badge colors */
    --plan-demo:    #fef9c3; --plan-demo-t:    #92400e;
    --plan-dev:     #f1f5f9; --plan-dev-t:     #475569;
    --plan-solo:    #dbeafe; --plan-solo-t:    #1e40af;
    --plan-starter: #f5f3ff; --plan-starter-t: #5b21b6;
    --plan-prod:    #dcfce7; --plan-prod-t:    #166534;
    --plan-custom:  #fce7f3; --plan-custom-t:  #9d174d;
    --shadow-md:  0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
}

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

/* ── Header ────────────────────────────────────────────────────────────────── */
.app-header {
    display: flex; align-items: center; gap: 1.5rem;
    padding: .75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky; top: 0; z-index: 100;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1rem; }
.brand-icon { font-size: 1.2rem; }
.main-nav { display: flex; gap: 1rem; margin-right: auto; }
.nav-link { color: var(--text-muted); font-weight: 500; padding: .25rem .5rem; border-radius: 4px; }
.nav-link:hover, .nav-link.active { color: var(--primary); background: #eff6ff; }
.header-right { display: flex; align-items: center; gap: 1rem; }
.username { color: var(--text-muted); font-size: .85rem; }
.btn-logout { color: var(--danger); font-size: .85rem; }

/* ── Main ──────────────────────────────────────────────────────────────────── */
.main-content { max-width: 1600px; margin: 0 auto; padding: 2rem 2.5rem; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .45rem .9rem; border-radius: var(--radius);
    font-size: .85rem; font-weight: 500; cursor: pointer;
    border: 1px solid transparent; transition: background .15s, opacity .15s;
    white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--primary);  color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-h); }
.btn-secondary { background: var(--surface);  color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger    { background: var(--danger);   color: #fff; }
.btn-danger:hover { background: var(--danger-h); }
.btn-sm        { padding: .3rem .65rem; font-size: .8rem; }
.btn-full      { width: 100%; justify-content: center; }
.btn-icon      { padding: .3rem .5rem; font-size: .9rem; }

/* ── Tabs ──────────────────────────────────────────────────────────────────── */
.tabs {
    display: flex; gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.5rem;
}
.tab-btn {
    padding: .65rem 1.25rem;
    background: none; border: none; cursor: pointer;
    font-size: .9rem; font-weight: 500; color: var(--text-muted);
    border-bottom: 2px solid transparent; margin-bottom: -2px;
    transition: color .15s, border-color .15s;
}
.tab-btn:hover  { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Section header ────────────────────────────────────────────────────────── */
.section-header {
    display: flex; align-items: center; gap: .75rem;
    margin-bottom: 1rem;
}
.section-header h2 { font-size: 1rem; font-weight: 600; margin-right: auto; }

/* ── Table ─────────────────────────────────────────────────────────────────── */
.data-table {
    width: 100%; border-collapse: collapse;
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
}
.data-table th {
    padding: .65rem 1rem; text-align: left;
    font-size: .75rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: .04em; color: var(--text-muted);
    background: var(--bg); border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8faff; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block; padding: .2rem .6rem;
    border-radius: 999px; font-size: .75rem; font-weight: 600;
    line-height: 1.4;
}
.badge-running   { background: #dcfce7; color: #166534; }
.badge-stopped   { background: #f1f5f9; color: #475569; }
.badge-exited    { background: #fef2f2; color: #991b1b; }
.badge-unknown   { background: #fefce8; color: #92400e; }
.badge-healthy   { background: #dcfce7; color: #166534; }
.badge-unhealthy { background: #fef2f2; color: #991b1b; }
.badge-starting  { background: #fefce8; color: #92400e; }
.badge-none      { background: #f1f5f9; color: #64748b; }
.badge-model-demo    { background: #fef9c3; color: #854d0e; }
.badge-model-preprod { background: #dbeafe; color: #1e40af; }
.badge-model-prod    { background: #dcfce7; color: #166534; }
.badge-node          { background: #f0f4ff; color: #3730a3; font-size: .7rem; }

/* ── Actions row ───────────────────────────────────────────────────────────── */
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert {
    padding: .65rem 1rem; border-radius: var(--radius);
    font-size: .875rem; border: 1px solid transparent;
}
.alert-error   { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.alert-info    { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.alert-warning { background: #fefce8; color: #854d0e; border-color: #fde68a; }
.hidden { display: none !important; }

/* ── Loading ───────────────────────────────────────────────────────────────── */
.loading { padding: 2rem; text-align: center; color: var(--text-muted); }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: .35rem; font-size: .875rem; }
.form-group input,
.form-group textarea,
.form-group select {
    width: 100%; padding: .5rem .75rem;
    border: 1px solid var(--border); border-radius: var(--radius);
    font-size: .9rem; transition: border-color .15s;
    background: var(--surface);
}
.form-group input:focus,
.form-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px #bfdbfe44; }
.form-hint { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; display: block; }
.text-danger  { color: #991b1b; }
.text-success { color: #166534; }
.text-small   { font-size: .8rem; }

/* ── Input with inline button ──────────────────────────────────────────────── */
.input-with-btn { display: flex; gap: .5rem; align-items: center; }
.input-with-btn input { flex: 1; }

/* ── Details modal grid ────────────────────────────────────────────────────── */
.details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.details-grid h4 { font-size: .85rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .75rem; }
@media (max-width: 640px) { .details-grid { grid-template-columns: 1fr; } }

/* ── btn-warning ────────────────────────────────────────────────────────────── */
.btn-warning { background: #f59e0b; color: #fff; border: 1px solid #d97706; }
.btn-warning:hover { background: #d97706; }

.settings-form { max-width: 600px; background: var(--surface); padding: 1.5rem; border-radius: var(--radius); box-shadow: var(--shadow); }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-overlay { position: fixed; inset: 0; z-index: 199; background: rgba(0,0,0,.4); }
.modal-box {
    position: relative; z-index: 201;
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow-md); width: 100%; max-width: 520px;
    max-height: 90vh; display: flex; flex-direction: column;
}
.modal-wide { max-width: 860px; }
.modal-header { display: flex; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1rem; font-weight: 600; flex: 1; }
.modal-close { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--text-muted); padding: .25rem; }
.modal-body { padding: 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer { padding: .875rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .75rem; align-items: center; }

/* ── Log output ────────────────────────────────────────────────────────────── */
.log-output {
    background: #0f172a; color: #94a3b8;
    font-family: 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
    font-size: .78rem; line-height: 1.6;
    padding: 1rem; border-radius: var(--radius);
    overflow-x: auto; white-space: pre-wrap; word-break: break-all;
    max-height: 500px; overflow-y: auto;
}

/* ── Auth pages ────────────────────────────────────────────────────────────── */
.page-auth { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card {
    width: 100%; max-width: 380px;
    background: var(--surface); border-radius: 12px;
    box-shadow: var(--shadow-md); padding: 2rem;
}
.auth-logo { font-size: 2rem; text-align: center; margin-bottom: .5rem; }
.auth-title { font-size: 1.25rem; font-weight: 700; text-align: center; margin-bottom: 1.5rem; }
.auth-subtitle { color: var(--text-muted); font-size: .875rem; text-align: center; margin-bottom: 1.25rem; }
.auth-back { text-align: center; margin-top: 1rem; font-size: .85rem; color: var(--text-muted); }
/* ── Tenant filter ─────────────────────────────────────────────────────────── */
.tenant-filter-wrap { flex: 1; max-width: 360px; }
.tenant-filter-input {
    width: 100%; padding: .45rem .75rem;
    border: 1px solid var(--border); border-radius: var(--radius);
    font-size: .875rem; background: var(--surface);
    transition: border-color .15s;
}
.tenant-filter-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px #bfdbfe44; }

/* ── Pagination ──────────────────────────────────────────────────────────────── */
.pagination {
    display: flex; align-items: center; gap: .35rem;
    margin-top: 1rem; flex-wrap: wrap;
}
.pg-btn {
    min-width: 2.2rem; padding: .3rem .6rem;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); font-size: .82rem; cursor: pointer;
    transition: background .12s, border-color .12s;
}
.pg-btn:hover:not(.pg-disabled):not(.pg-active) { background: var(--bg); border-color: var(--primary); }
.pg-active  { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.pg-disabled { opacity: .4; cursor: not-allowed; }
.pg-ellipsis { padding: .3rem .25rem; color: var(--text-muted); font-size: .85rem; }
.pagination-info { margin-top: .4rem; font-size: .78rem; color: var(--text-muted); }
/* ── Tenant slug link ──────────────────────────────────────────────────────── */
.tenant-slug { font-weight: 600; font-size: .9rem; }
.tenant-url  { font-size: .75rem; color: var(--text-muted); display: block; }

/* ── Text colors ───────────────────────────────────────────────────────────── */
.text-danger { color: var(--danger); }
/* ── Plan modal ──────────────────────────────────────────────────────────────── */
.plan-section { margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.plan-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.section-title { font-size: .82rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 .75rem; }
.delta-btns { display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
.delta-btns input { border: 1px solid var(--border); border-radius: 4px; padding: .28rem .45rem; font-size: .8rem; background: var(--surface); color: var(--text); }
.plan-table td, .plan-table th { vertical-align: middle; }
/* ── VPS stats bar ───────────────────────────────────────────────────────────── */
#vps-stats-bar {
    display: flex; gap: 1.5rem; flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: .75rem 1.25rem;
    margin-bottom: 1.25rem;
}
.vps-stat {
    display: flex; align-items: center; gap: .65rem;
    flex: 1; min-width: 240px;
}
.vps-stat-label {
    font-size: .75rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; color: var(--text-muted);
    min-width: 44px;
}
.vps-stat-bar-wrap {
    flex: 1; height: 8px;
    background: var(--border);
    border-radius: 4px; overflow: hidden;
}
.vps-stat-bar {
    height: 100%; width: 0;
    background: var(--success);
    border-radius: 4px;
    transition: width .5s ease, background .3s;
}
.vps-stat-text { font-size: .8rem; color: var(--text); white-space: nowrap; min-width: 180px; }

/* ── Plan badges ────────────────────────────────────────────────────────────── */
.badge-plan-demo    { background: var(--plan-demo);    color: var(--plan-demo-t); }
.badge-plan-dev     { background: var(--plan-dev);     color: var(--plan-dev-t); }
.badge-plan-solo    { background: var(--plan-solo);    color: var(--plan-solo-t); }
.badge-plan-starter { background: var(--plan-starter); color: var(--plan-starter-t); }
.badge-plan-prod    { background: var(--plan-prod);    color: var(--plan-prod-t); }
.badge-plan-custom  { background: var(--plan-custom);  color: var(--plan-custom-t); }

/* ── Expiration badges ──────────────────────────────────────────────────────── */
.badge-expires-ok       { background: #dcfce7; color: #166534; }
.badge-expires-soon     { background: #fefce8; color: #854d0e; }
.badge-expires-critical { background: #fef2f2; color: #991b1b; }

/* ── Payment status badges ─────────────────────────────────────────────────── */
.badge-paid     { background: #dcfce7; color: #166534; }
.badge-pending  { background: #fefce8; color: #854d0e; }
.badge-failed   { background: #fef2f2; color: #991b1b; }
.badge-refunded { background: #f1f5f9; color: #475569; }

/* ── Provider badges ────────────────────────────────────────────────────────── */
.badge-provider-stripe { background: #ede9fe; color: #4c1d95; }
.badge-provider-paypal { background: #dbeafe; color: #1e40af; }

/* ── KPI grid ───────────────────────────────────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
@media (max-width: 900px)  { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px)  { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem 1.5rem;
    display: flex; flex-direction: column; gap: .25rem;
}
.kpi-card-warning { border-color: #fde68a; background: #fefce8; }
.kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
}
.kpi-label {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
}

/* ── Alert banner (expiring tenants) ────────────────────────────────────────── */
.alert-banner {
    background: #fefce8;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: .875rem 1.25rem;
    margin-bottom: 1.25rem;
    font-size: .875rem;
}
.expiring-list {
    margin: .5rem 0 0 1.25rem;
    list-style: disc;
    font-size: .82rem;
    color: var(--text);
}
.expiring-list li { margin-bottom: .15rem; }

/* ── Filter bar ─────────────────────────────────────────────────────────────── */
.filter-bar {
    display: flex; gap: .75rem; align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.filter-bar input[type="search"],
.filter-bar select {
    padding: .45rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .875rem;
    background: var(--surface);
    transition: border-color .15s;
    min-width: 160px;
}
.filter-bar input[type="search"]:focus,
.filter-bar select:focus { outline: none; border-color: var(--primary); }
.filter-count { font-size: .78rem; color: var(--text-muted); margin-left: auto; }

/* ── API Docs ───────────────────────────────────────────────────────────────── */
.apidocs-grid {
    display: flex; flex-direction: column; gap: 1rem;
}
.apidoc-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.apidoc-card-webhooks { border-color: #c7d2fe; }
.apidoc-header {
    display: flex; align-items: center; gap: .75rem;
    padding: .75rem 1.25rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.method-badge {
    background: var(--primary); color: #fff;
    font-size: .7rem; font-weight: 700;
    padding: .15rem .5rem; border-radius: 4px;
    letter-spacing: .04em;
}
.method-badge-webhook { background: #7c3aed; }
.apidoc-action { font-size: .9rem; font-weight: 600; }
.apidoc-desc   { font-size: .82rem; color: var(--text-muted); }
.apidoc-body   { padding: 1rem 1.25rem; }
.apidoc-params {
    width: 100%; border-collapse: collapse;
    font-size: .82rem; margin-bottom: .75rem;
}
.apidoc-params th {
    text-align: left; padding: .4rem .6rem;
    font-size: .7rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .04em; color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
.apidoc-params td { padding: .35rem .6rem; border-bottom: 1px solid var(--border); }
.apidoc-params tr:last-child td { border-bottom: none; }
.apidoc-example {
    background: #0f172a; color: #94a3b8;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: .78rem; line-height: 1.6;
    padding: .75rem 1rem; border-radius: 6px;
    overflow-x: auto; white-space: pre;
    margin-bottom: .5rem;
}
.apidoc-copy { margin-top: 0; }

/* ── Tenant table — email cell ──────────────────────────────────────────────── */
.tenant-email { font-size: .8rem; color: var(--text-muted); }
