/* Agile Solutions Cloud, control panel.
 *
 * Palette and typography are taken from the main agileitsolution.com site so
 * the platform reads as one product rather than a bolted-on admin tool.
 *
 * Fonts are loaded locally with a system fallback stack: the panel must render
 * correctly with no external network access, since a strict CSP and offline
 * operation are both expected.
 */

:root {
    /* Brand, from the marketing site */
    --violet: #8b5cf6;
    --violet-2: #a78bfa;
    --violet-3: #c4b5fd;
    --indigo: #6366f1;
    --cyan: #22d3ee;
    --cyan-2: #67e8f9;
    --pink: #f472b6;
    --rose: #fb7185;
    --green: #34d399;
    --amber: #fbbf24;

    /* Surfaces */
    --bg: #0a0a1f;
    --bg-2: #0e0f29;
    --bg-3: #121438;
    --surface: rgba(255, 255, 255, 0.04);
    --surface-2: rgba(255, 255, 255, 0.07);
    --surface-3: rgba(255, 255, 255, 0.10);
    --stroke: rgba(255, 255, 255, 0.08);
    --stroke-2: rgba(255, 255, 255, 0.14);
    --stroke-brand: rgba(139, 92, 246, 0.35);

    /* Text */
    --text: #f5f4ff;
    --text-2: #c8c9e8;
    --text-3: #8b8eba;

    /* Status colours, used consistently across badges, dots and charts */
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #fb7185;
    --info: #22d3ee;
    --idle: #8b8eba;

    --radius: 14px;
    --radius-sm: 9px;
    --sidebar-w: 248px;

    --font-display: 'Space Grotesk', 'Plus Jakarta Sans', -apple-system,
        BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-body: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont,
        'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', ui-monospace, Menlo, Consolas, monospace;

    --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    background:
        radial-gradient(1100px 700px at 12% -8%, rgba(139, 92, 246, 0.14), transparent 60%),
        radial-gradient(900px 600px at 92% 0%, rgba(34, 211, 238, 0.10), transparent 55%),
        var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; letter-spacing: -0.01em; }
a { color: var(--violet-2); text-decoration: none; }
a:hover { color: var(--violet-3); }

/* --- Layout ------------------------------------------------------------ */

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

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--bg-2), var(--bg));
    border-right: 1px solid var(--stroke);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    padding: 22px 20px 18px;
    border-bottom: 1px solid var(--stroke);
}

.brand-mark {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 700;
    background: linear-gradient(120deg, var(--violet-2), var(--cyan));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.brand-sub {
    font-size: 11px;
    color: var(--text-3);
    letter-spacing: 0.09em;
    text-transform: uppercase;
    margin-top: 3px;
}

.nav { padding: 12px 10px; flex: 1; overflow-y: auto; }

.nav-section {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.11em;
    color: var(--text-3);
    padding: 14px 12px 6px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    border: 1px solid transparent;
    user-select: none;
}

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

.nav-item.active {
    background: linear-gradient(90deg, rgba(139, 92, 246, 0.20), rgba(139, 92, 246, 0.05));
    border-color: var(--stroke-brand);
    color: #fff;
}

.nav-item .icon { width: 17px; text-align: center; opacity: 0.9; flex-shrink: 0; }
.nav-item .count {
    margin-left: auto;
    font-size: 11px;
    background: var(--surface-2);
    border-radius: 20px;
    padding: 1px 8px;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
}

.sidebar-foot { padding: 12px; border-top: 1px solid var(--stroke); }

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 12.5px;
}

.avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--violet), var(--cyan));
    display: grid; place-items: center;
    font-weight: 700; font-size: 12px; color: #0a0a1f;
    flex-shrink: 0;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: 60px;
    border-bottom: 1px solid var(--stroke);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    background: rgba(10, 10, 31, 0.72);
    backdrop-filter: blur(14px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar h1 { font-size: 17px; }
.topbar .spacer { flex: 1; }

.content { padding: 24px; flex: 1; }

/* --- Cards and grids --------------------------------------------------- */

.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 1180px) {
    .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
    .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
    .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: -100%; z-index: 100; transition: left var(--transition); }
    .sidebar.open { left: 0; }
}

.card {
    background: linear-gradient(160deg, var(--surface-2), var(--surface));
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    padding: 18px;
}

.card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.card-head h3 { font-size: 14.5px; }
.card-head .spacer { flex: 1; }

/* Stat tiles. The value is the hero; label and delta are supporting. */
.stat .label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-3);
    font-weight: 600;
}
.stat .value {
    font-family: var(--font-display);
    font-size: 27px;
    font-weight: 700;
    margin-top: 6px;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.stat .sub { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.stat.accent-violet .value { color: var(--violet-2); }
.stat.accent-cyan .value { color: var(--cyan-2); }
.stat.accent-green .value { color: var(--ok); }
.stat.accent-amber .value { color: var(--warn); }
.stat.accent-rose .value { color: var(--danger); }

/* --- Tables ------------------------------------------------------------ */

.table-wrap { overflow-x: auto; border-radius: var(--radius); }

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

thead th {
    text-align: left;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-3);
    font-weight: 600;
    padding: 9px 12px;
    border-bottom: 1px solid var(--stroke);
    white-space: nowrap;
}

tbody td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--stroke);
    vertical-align: middle;
}

tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface); }
tbody tr:last-child td { border-bottom: none; }

.mono { font-family: var(--font-mono); font-size: 12px; }
.dim { color: var(--text-3); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

/* --- Badges and status ------------------------------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

.badge.running, .badge.active, .badge.paid, .badge.available, .badge.succeeded {
    background: rgba(52, 211, 153, 0.12); color: var(--ok); border-color: rgba(52, 211, 153, 0.28);
}
.badge.stopped, .badge.cancelled, .badge.draft, .badge.expired {
    background: rgba(139, 142, 186, 0.12); color: var(--idle); border-color: rgba(139, 142, 186, 0.25);
}
.badge.suspended, .badge.past_due, .badge.delinquent {
    background: rgba(251, 191, 36, 0.12); color: var(--warn); border-color: rgba(251, 191, 36, 0.30);
}
.badge.failed, .badge.uncollectible, .badge.offline {
    background: rgba(251, 113, 133, 0.12); color: var(--danger); border-color: rgba(251, 113, 133, 0.30);
}
.badge.provisioning, .badge.requested, .badge.queued, .badge.trialing, .badge.open, .badge.draining {
    background: rgba(34, 211, 238, 0.12); color: var(--info); border-color: rgba(34, 211, 238, 0.28);
}
.badge.archived, .badge.deleted, .badge.void {
    background: rgba(139, 142, 186, 0.08); color: var(--text-3); border-color: var(--stroke);
}

/* Pulse on states that are actively changing, so the operator can see work
 * in flight without re-reading the table. */
.badge.provisioning .dot, .badge.queued .dot, .badge.running .dot {
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* --- Buttons ----------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--stroke-2);
    background: var(--surface-2);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--stroke-brand); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary {
    background: linear-gradient(120deg, var(--violet), var(--indigo));
    border-color: transparent;
    color: #fff;
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.12); }

.btn.danger { color: var(--danger); border-color: rgba(251, 113, 133, 0.35); background: rgba(251, 113, 133, 0.08); }
.btn.danger:hover:not(:disabled) { background: rgba(251, 113, 133, 0.16); }

.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.icon-only { padding: 6px 9px; }

.btn-row { display: flex; gap: 7px; flex-wrap: wrap; }

/* --- Forms ------------------------------------------------------------- */

label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }

input, select, textarea {
    width: 100%;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--stroke-2);
    background: rgba(0, 0, 0, 0.28);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 13.5px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--violet);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.16);
}

input::placeholder { color: var(--text-3); }
.field { margin-bottom: 14px; }
.field-hint { font-size: 11.5px; color: var(--text-3); margin-top: 4px; }
.field-error { font-size: 11.5px; color: var(--danger); margin-top: 4px; }

/* --- Modal ------------------------------------------------------------- */

.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(4, 4, 14, 0.72);
    backdrop-filter: blur(4px);
    display: grid; place-items: center;
    z-index: 200;
    padding: 20px;
}

.modal {
    background: linear-gradient(160deg, var(--bg-3), var(--bg-2));
    border: 1px solid var(--stroke-2);
    border-radius: var(--radius);
    width: 100%;
    max-width: 520px;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--stroke); display: flex; align-items: center; }
.modal-head h3 { font-size: 15.5px; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--stroke); display: flex; gap: 9px; justify-content: flex-end; }

/* --- Login ------------------------------------------------------------- */

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 20px; }

.login-card {
    width: 100%;
    max-width: 400px;
    background: linear-gradient(160deg, var(--surface-2), var(--surface));
    border: 1px solid var(--stroke-2);
    border-radius: 18px;
    padding: 34px 30px;
    box-shadow: var(--shadow);
}

.login-card .brand-mark { font-size: 22px; }
.login-card .brand-sub { margin-bottom: 26px; }

/* --- Meters ------------------------------------------------------------ */

.meter {
    height: 7px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 20px;
    overflow: hidden;
    margin-top: 7px;
}

.meter-fill {
    height: 100%;
    border-radius: 20px;
    background: linear-gradient(90deg, var(--violet), var(--cyan));
    transition: width 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

.meter-fill.warn { background: linear-gradient(90deg, var(--amber), var(--rose)); }
.meter-fill.danger { background: linear-gradient(90deg, var(--rose), #ef4444); }

/* --- Misc -------------------------------------------------------------- */

.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 9px; }

.toast {
    background: var(--bg-3);
    border: 1px solid var(--stroke-2);
    border-left: 3px solid var(--violet);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: 13px;
    box-shadow: var(--shadow);
    max-width: 380px;
    animation: slide-in 220ms cubic-bezier(0.4, 0, 0.2, 1);
}

.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }

@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.empty { text-align: center; padding: 46px 20px; color: var(--text-3); }
.empty .icon { font-size: 30px; opacity: 0.45; margin-bottom: 10px; }

.spinner {
    width: 15px; height: 15px;
    border: 2px solid var(--stroke-2);
    border-top-color: var(--violet-2);
    border-radius: 50%;
    animation: spin 700ms linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--stroke); margin-bottom: 18px; }
.tab {
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-3);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color var(--transition), border-color var(--transition);
}
.tab:hover { color: var(--text-2); }
.tab.active { color: var(--violet-2); border-bottom-color: var(--violet); }

.filter-bar { display: flex; gap: 9px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-bar input, .filter-bar select { width: auto; min-width: 170px; }

code.inline {
    font-family: var(--font-mono);
    font-size: 11.5px;
    background: rgba(0, 0, 0, 0.3);
    padding: 1px 6px;
    border-radius: 5px;
    border: 1px solid var(--stroke);
}

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--text-3); font-weight: 500; }
.kv dd { margin: 0; }

/* Screen-reader-only text, for icon-only controls that still need names. */
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 2px solid var(--violet-2); outline-offset: 2px; }
