/* ── Dashboard — full-width layout with sidebar ─────────────────── */

:root {
    --green: #10b981;
    --green-dark: #059669;
    --green-light: #ecfdf5;
    --text: #1e293b;
    --text-muted: #64748b;
    --bg: #f8fafc;
    --white: #ffffff;
    --border: #e2e8f0;
    --sidebar-w: 250px;
    --radius: 10px;
}

.dash-body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Sidebar ────────────────────────────────────────────────────── */

.dash-sidebar {
    width: var(--sidebar-w);
    background: #0f172a;
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 30;
    overflow-y: auto;
}

.dash-logo {
    display: block;
    padding: 20px 20px 16px;
    font-size: 18px;
    font-weight: 700;
    color: var(--green);
    text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,.06);
}

.dash-nav {
    flex: 1;
    padding: 12px 0;
}

.dash-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    font-size: 14px;
    font-weight: 500;
    color: #94a3b8;
    text-decoration: none;
    transition: background .15s, color .15s;
    border-left: 3px solid transparent;
}

.dash-nav-item:hover {
    background: rgba(255,255,255,.04);
    color: #e2e8f0;
}

.dash-nav-item.active {
    background: rgba(16,185,129,.18);
    color: #34d399 !important;
    border-left-color: #10b981;
    font-weight: 600;
}

.dash-nav-sub.active {
    background: rgba(16,185,129,.12);
    color: #34d399 !important;
}

.dash-nav-sub {
    padding-left: 36px;
    font-size: 13px;
}

/* ── Collapsible sites group ───────────────────────────────────── */

.dash-nav-group { margin: 2px 0; }

.dash-nav-group summary {
    list-style: none;
    display: flex; align-items: center; gap: 10px;
    padding: 9px 20px; font-size: 14px; font-weight: 500;
    color: #94a3b8; border-left: 3px solid transparent;
    transition: background .15s, color .15s;
}

.dash-nav-group summary:hover { background: rgba(255,255,255,.04); color: #e2e8f0; }

.dash-nav-group summary::-webkit-details-marker { display: none; }

.dash-nav-arrow {
    margin-left: auto; font-size: 8px;
    transition: transform .2s;
}

.dash-nav-group[open] .dash-nav-arrow { transform: rotate(90deg); }

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

.dash-sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.06);
}

/* Language switcher in sidebar: open upward */
.dash-sidebar-footer .lang-options {
    top: auto !important;
    bottom: 100% !important;
    margin-top: 0 !important;
    margin-bottom: 4px !important;
    right: auto !important;
    left: 0 !important;
}

.dash-user {
    font-size: 13px;
    font-weight: 600;
    color: #e2e8f0;
    margin-bottom: 4px;
}

.dash-logout {
    font-size: 12px;
    color: #94a3b8;
    text-decoration: none;
}

.dash-logout:hover { color: #f87171; }

/* ── Mobile bottom nav ──────────────────────────────────────────── */

.dash-bottom-nav {
    display: none;
    position: fixed; bottom: 0; left: 0; right: 0; height: 56px;
    background: #fff; border-top: 1px solid var(--border);
    justify-content: space-around; align-items: center;
    z-index: 50; padding-bottom: env(safe-area-inset-bottom);
}

.dash-bottom-nav-item {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 10px; font-weight: 500; color: var(--text-muted);
    text-decoration: none; padding: 4px 8px;
}

.dash-bottom-nav-item span { font-size: 18px; }
.dash-bottom-nav-item.active { color: var(--green); }

/* ── Main content area ──────────────────────────────────────────── */

.dash-main {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 32px 36px;
    max-width: 1200px;
    width: calc(100% - var(--sidebar-w));
}

/* ── Page header ────────────────────────────────────────────────── */

.dash-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 16px;
}

.dash-page-header h1 {
    font-size: 26px;
    font-weight: 800;
    margin: 0 0 4px;
    letter-spacing: -.3px;
}

.dash-page-header p {
    font-size: 14px;
    color: var(--text-muted);
    margin: 0;
}

.dash-page-header code {
    font-size: 12px;
    background: #e2e8f0;
    padding: 2px 6px;
    border-radius: 4px;
}

/* ── Stats row ──────────────────────────────────────────────────── */

.dash-stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}

.dash-stat-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.dash-stat-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -.5px;
}

.dash-stat-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-top: 4px;
}

/* ── Section header ─────────────────────────────────────────────── */

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

.dash-section-header h2 {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
}

/* ── Sites grid ─────────────────────────────────────────────────── */

.dash-sites-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 16px;
}

.dash-site-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    transition: border-color .15s, box-shadow .15s;
    /* Anchor for .dash-site-stretch */
    position: relative;
}

.dash-site-card:hover {
    border-color: var(--green);
    box-shadow: 0 4px 16px rgba(0,0,0,.04);
}

/* Whole-card click target: the site opens from anywhere on the card, not
   just the small "Manage" button. Longhand offsets, not `inset` — older
   Android webviews still ship in the field. */
.dash-site-stretch {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
    border-radius: var(--radius);
}

/* Interactive children that must win over the stretched link (Copy,
   View Portal) — without this they would sit UNDER it and never receive
   the click. */
.dash-raise {
    position: relative;
    z-index: 2;
}

.dash-site-card-body {
    padding: 20px;
    flex: 1;
}

.dash-site-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.dash-site-card-top h3 {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
}

.dash-site-card-top h3 a {
    color: var(--text);
    text-decoration: none;
}

.dash-site-card-top h3 a:hover { color: var(--green); }

.dash-site-url-row {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    background: #f1f5f9;
    border-radius: 6px;
    margin-bottom: 10px;
}

.dash-site-url-row code {
    font-size: 11px;
    font-family: "SF Mono", "Cascadia Code", "Fira Code", Menlo, monospace;
    word-break: break-all;
    flex: 1;
}

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

.dash-site-meta code {
    font-size: 11px;
    background: #e2e8f0;
    padding: 1px 5px;
    border-radius: 3px;
}

.dash-site-card-foot {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

/* ── Panels ─────────────────────────────────────────────────────── */

.dash-panel {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}

.dash-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.dash-panel-header h2 {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
}

.dash-panel-desc {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0 0 16px;
}

/* ── Buttons ────────────────────────────────────────────────────── */

.dash-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: background .15s, border-color .15s;
    font-family: inherit;
    border: none;
    font-size: 14px;
    padding: 10px 20px;
    text-decoration: none;
}

.dash-btn-sm { font-size: 12px; padding: 6px 12px; }

.dash-btn-primary {
    background: var(--green);
    color: #fff;
}
.dash-btn-primary:hover { background: var(--green-dark); }

.dash-btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.dash-btn-ghost:hover {
    background: #f1f5f9;
    color: var(--text);
}

.dash-btn-danger {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}
.dash-btn-danger:hover {
    background: #dc2626;
    color: #fff;
}

/* ── Table ──────────────────────────────────────────────────────── */

.dash-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.dash-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
    color: var(--text-muted);
    padding: 10px 12px;
    border-bottom: 2px solid var(--border);
}

.dash-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

.dash-table code {
    font-size: 12px;
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 3px;
}

.dash-table tbody tr:hover { background: #f8fafc; }

/* ── Inputs ─────────────────────────────────────────────────────── */

.dash-input {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    outline: none;
    font-family: inherit;
    transition: border-color .15s;
    background: var(--white);
}

.dash-input:focus { border-color: var(--green); }

.dash-input-sm {
    font-size: 12px;
    padding: 6px 8px;
    border-radius: 6px;
}

/* ── Modal ──────────────────────────────────────────────────────── */

.dash-modal {
    position: fixed;
    inset: 0;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.dash-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15,23,42,.6);
}

.dash-modal-content {
    position: relative;
    background: var(--white);
    border-radius: 14px;
    padding: 28px;
    width: 90%;
    max-width: 440px;
    max-height: 90vh;
    overflow-y: auto;
}

.dash-modal-content h3 {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 4px;
}

.dash-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* ── Vue cloak ──────────────────────────────────────────────────── */

[v-cloak] { display: none !important; }

/* ── Empty state ────────────────────────────────────────────────── */

.dash-empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
    background: var(--white);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.dash-empty p {
    font-size: 14px;
    margin: 0;
}

/* ── Pagination ─────────────────────────────────────────────────── */

.dash-pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 12px; margin-top: 16px; padding: 8px 0;
}

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

/* ── Responsive ─────────────────────────────────────────────────── */

@media (max-width: 900px) {
    .dash-sidebar {
        width: 60px;
    }
    .dash-sidebar .dash-logo,
    .dash-sidebar .dash-nav-item span:not(.dash-nav-icon),
    .dash-sidebar .dash-sidebar-footer { display: none; }
    .dash-sidebar .dash-nav-icon { margin: 0 auto; }
    .dash-sidebar .dash-nav-item {
        justify-content: center;
        padding: 12px 0;
        font-size: 18px;
    }
    .dash-sidebar .dash-nav-sub { padding-left: 0; }
    :root { --sidebar-w: 60px; }

    .dash-stats-row { grid-template-columns: repeat(2, 1fr); }
    .dash-sites-grid { grid-template-columns: 1fr; }

    /* Mid-size screens: tables scroll horizontally instead of overflowing */
    .dash-table { display: block; overflow-x: auto; white-space: nowrap; }
    .dash-main code, .dash-site-url-row code {
        word-break: break-all; overflow-wrap: anywhere;
    }
}

@media (max-width: 600px) {
    .dash-sidebar { display: none; }
    .dash-bottom-nav { display: flex; }
    .dash-main { margin-left: 0; width: 100%; padding: 16px 12px 80px; }
    :root { --sidebar-w: 0px; }
    .dash-stats-row { grid-template-columns: 1fr 1fr; gap: 8px; }
    .dash-stat-card { padding: 14px; }
    .dash-stat-value { font-size: 22px; }
    .dash-page-header { flex-direction: column; gap: 8px; }
    .dash-page-header h1 { font-size: 20px; }
    .dash-page-header code { font-size: 10px; word-break: break-all; }

    /* Table → stacked cards on mobile: every value on its own line with
       the field name as a label line above it (from td data-label). */
    .dash-table, .dash-table thead, .dash-table tbody, .dash-table tfoot,
    .dash-table tr, .dash-table th, .dash-table td {
        display: block;
    }
    .dash-table thead { display: none; }
    .dash-table tr {
        background: #fff; border: 1px solid var(--border);
        border-radius: 8px; margin-bottom: 10px; padding: 12px;
    }
    .dash-table td {
        border: none; padding: 6px 0;
        font-size: 13px;
        min-width: 0;
    }
    .dash-table td + td { border-top: 1px solid #f1f5f9; }
    .dash-table td::before {
        content: attr(data-label);
        display: block;
        font-size: 10px; font-weight: 600; color: var(--text-muted);
        text-transform: uppercase; letter-spacing: .3px;
        margin-bottom: 2px;
    }
    /* Button-only cells (and no-label cells): no label line, buttons in a row */
    .dash-table td[data-label=""]::before,
    .dash-table td[data-label="Action"]::before { display: none; }
    .dash-table td[data-label="Action"] {
        display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
        border-top: none; padding-top: 8px;
    }
    /* Long values must wrap, never overflow */
    .dash-table td, .dash-table td code, .dash-table td div {
        word-break: break-all; overflow-wrap: anywhere; min-width: 0;
    }
    .dash-table td code { font-size: 12px; }
    .dash-btn-sm { padding: 4px 8px; font-size: 11px; }

    .dash-panel-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .dash-page-header > span { width: 100%; }
    .dash-site-url-row { flex-direction: column; align-items: flex-start; gap: 6px; }
    .dash-site-url-row code { word-break: break-all; }
    .dash-modal-content { width: 94%; padding: 18px 14px; }

    /* iOS zooms into any input whose font-size is < 16px — keep 16px on
       mobile so tapping a field never forces a zoom-in */
    .dash-input, .dash-input-sm { font-size: 16px; }

    /* Plan editor — one field per line: the field NAME on the left and
       its input right beside it (no stacked layout on mobile) */
    .plan-editor { overflow: hidden; }
    .plan-row { grid-template-columns: 1fr; gap: 6px; padding: 10px 10px; }
    .plan-row-header { display: none; }
    .plan-row span {
        display: flex; flex-direction: row; align-items: center; gap: 8px;
    }
    .plan-row span::before {
        content: attr(data-label);
        flex: 0 0 92px;           /* label column — field name */
        font-size: 10px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: .3px;
        color: var(--text-muted);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .plan-row span input { flex: 1; width: 100%; min-width: 0; }
    .plan-row span:last-child { justify-content: flex-end; gap: 6px; }
    .plan-row span:last-child::before { display: none; }

    /* Sites grid single column */
    .dash-sites-grid { grid-template-columns: 1fr; }

    .dash-panel { padding: 16px; }
    .dash-pagination { flex-wrap: wrap; gap: 8px; }
}

/* Loader spinner (clients report) */
.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border, #e2e8f0);
    border-top-color: #10b981;
    border-radius: 50%;
    margin: 0 auto;
    animation: dash-spin .8s linear infinite;
}
@keyframes dash-spin {
    to { transform: rotate(360deg); }
}

/* Data usage bar chart */
.data-bar-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 3px 0;
}
.data-bar-label {
    width: 160px;
    flex-shrink: 0;
    font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;
    font-size: 12px;
    color: var(--text-muted, #64748b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.data-bar-track {
    flex: 1;
    background: #f1f5f9;
    border-radius: 4px;
    height: 16px;
    overflow: hidden;
}
.data-bar-fill {
    height: 100%;
    background: #10b981;
    border-radius: 4px;
    transition: width .25s ease, opacity .15s;
}
.data-bar-hovered { opacity: .65; }
.data-bar-value {
    width: 70px;
    flex-shrink: 0;
    text-align: right;
    font-size: 12px;
    font-weight: 600;
    color: var(--text, #1e293b);
}
.data-bar-tip {
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-muted, #64748b);
    border-top: 1px solid var(--border, #e2e8f0);
    padding-top: 8px;
}
@media (max-width: 640px) {
    /* Mobile: label + value on the first line, the bar gets the FULL
       width below — no more crushed 100px bars. */
    .data-bar-row { flex-wrap: wrap; padding: 6px 0; }
    .data-bar-label { width: auto; flex: 1; min-width: 0; }
    .data-bar-value { width: auto; }
    .data-bar-track { flex-basis: 100%; order: 3; height: 14px; }
}

/* Cumulative usage curve (period section) */
.cum-chart {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 160px;
    padding: 8px 4px 2px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border, #e2e8f0);
    margin-bottom: 10px;
}
.cum-col {
    flex: 1;
    min-width: 6px;
    height: 100%;
    display: flex;
    align-items: flex-end;
    cursor: pointer;
}
.cum-bar {
    width: 100%;
    background: linear-gradient(180deg, #10b981 0%, #6ee7b7 100%);
    border-radius: 2px 2px 0 0;
    transition: opacity .15s;
}
.cum-col:hover .cum-bar { opacity: .65; }
