/* Google Fonts: Inter (thin, clean, modern) and JetBrains Mono */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* Refined oceanic slate grey design system (#1D2528 / #273136) */
:root {
    --bg-primary: #1d2528;       /* Oceanic slate dark grey */
    --bg-secondary: #273136;     /* Slate grey card surface */
    --bg-card: #273136;          /* Card container */
    --bg-card-hover: #2e383d;    /* Slate hover state */
    --bg-elevated: #333d42;      /* Raised modal / dropdown */
    --bg-input: #181e21;         /* Deep slate input background */
    
    --border-color: #333d42;     /* Slate border */
    --border-subtle: #2a3439;    /* Subtle structural divider */
    --border-focus: #4b636d;     /* Focused element border */
    
    --text-primary: #e0e6e8;     /* Soft slate white */
    --text-secondary: #90a4ae;   /* Slate muted grey */
    --text-muted: #6c777a;       /* Slate gutter grey (#6C777A) */
    
    --accent-blue: #80cbc4;      /* Soft teal/cyan accent */
    --accent-indigo: #90a4ae;    /* Slate accent */
    --accent-purple: #b39ddb;    /* Soft lavender accent */
    --accent-green: #81c784;     /* Soft sage green */
    --accent-red: #e57373;       /* Soft red */
    --accent-amber: #ffb74d;     /* Soft amber */
    
    --gradient-primary: linear-gradient(180deg, #333d42 0%, #273136 100%);
    --gradient-card: none;
    
    --radius-sm: 5px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.35);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-weight: 400;
    letter-spacing: -0.011em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-size: 14.5px;
    line-height: 1.6;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-weight: 500;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

/* Header & Navbar */
.navbar {
    background-color: rgba(29, 37, 40, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 50;
    padding: 0.75rem 1.5rem;
}

.navbar-inner {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-weight: 500;
    font-size: 1.1rem;
    color: var(--text-primary);
    text-decoration: none;
    flex-shrink: 0;
    letter-spacing: -0.02em;
}

.brand-badge {
    background: #333d42;
    border: 1px solid #3e4c52;
    color: #e0e6e8;
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    box-shadow: none;
    white-space: nowrap;
}

.brand-text {
    white-space: nowrap;
    letter-spacing: -0.015em;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-user-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.nav-user-meta strong {
    color: var(--text-primary);
}

.nav-user-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.nav-link:hover {
    color: var(--text-primary);
    background-color: rgba(255,255,255,0.06);
}

.nav-link.danger {
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.1);
}

.nav-link.danger:hover {
    background-color: rgba(239, 68, 68, 0.2);
    color: #f87171;
}

/* Container */
.container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    flex: 1;
}

/* Header Actions */
.page-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

/* KPI / Stat cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stat-title {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Cards & Panels */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.2rem;
    font-weight: 600;
}

/* Table styles */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    background-color: #222b2f;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.88rem;
    vertical-align: middle;
}

tr:hover td {
    background-color: var(--bg-card-hover);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.55rem;
    border-radius: 9999px;
    font-size: 0.72rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-success {
    background: rgba(129, 199, 132, 0.15);
    color: #a5d6a7;
    border: 1px solid rgba(129, 199, 132, 0.3);
}

.badge-danger {
    background: rgba(229, 115, 115, 0.15);
    color: #ef9a9a;
    border: 1px solid rgba(229, 115, 115, 0.3);
}

.badge-warning {
    background: rgba(255, 183, 77, 0.15);
    color: #ffe082;
    border: 1px solid rgba(255, 183, 77, 0.3);
}

.badge-info {
    background: rgba(128, 203, 196, 0.15);
    color: #b2dfdb;
    border: 1px solid rgba(128, 203, 196, 0.3);
}

.badge-purple {
    background: rgba(179, 157, 219, 0.18);
    color: #d1c4e9;
    border: 1px solid rgba(179, 157, 219, 0.35);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-primary {
    background: #e0e6e8;
    color: #1d2528;
    font-weight: 500;
    border: 1px solid #e0e6e8;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.btn-primary:hover {
    background: #ffffff;
    border-color: #ffffff;
    color: #1d2528;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn-secondary {
    background-color: #273136;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: #2e383d;
    border-color: #455359;
    color: #ffffff;
}

.btn-danger {
    background-color: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.btn-danger:hover {
    background-color: #ef4444;
    color: #fff;
}

.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.78rem;
}

.btn-block {
    width: 100%;
}

/* Forms */
.form-group {
    margin-bottom: 1.1rem;
}

.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.form-control {
    width: 100%;
    padding: 0.55rem 0.8rem;
    font-size: 0.88rem;
    border-radius: var(--radius-sm);
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.05);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Collapsible advanced section */
.advanced-accordion {
    margin: 1rem 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: #222b2f;
    overflow: hidden;
}

.advanced-accordion summary {
    padding: 0.65rem 0.9rem;
    font-size: 0.825rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    font-weight: 500;
    outline: none;
    transition: background 0.2s, color 0.2s;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.advanced-accordion summary::-webkit-details-marker {
    display: none;
}

.advanced-accordion summary::before {
    content: '▶';
    font-size: 0.65rem;
    transition: transform 0.2s ease;
    color: var(--text-muted);
}

.advanced-accordion[open] summary::before {
    transform: rotate(90deg);
}

.advanced-accordion summary:hover {
    color: var(--text-primary);
    background: #273136;
}

.advanced-accordion[open] summary {
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.advanced-accordion-body {
    padding: 1rem 0.9rem 0.5rem 0.9rem;
}

/* Modals */
.modal-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(20, 26, 29, 0.8);
    backdrop-filter: blur(4px);
    z-index: 100;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.modal-backdrop.active {
    display: flex;
}

.modal-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 580px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

/* Auth Cards (Login pages) */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: radial-gradient(circle at 50% 20%, #273136 0%, #1d2528 100%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.auth-header {
    text-align: center;
    margin-bottom: 1.75rem;
}

.auth-title {
    font-size: 1.4rem;
    font-weight: 600;
    margin-top: 0.5rem;
    letter-spacing: -0.02em;
}

/* Alert boxes */
.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.alert-danger {
    background: rgba(229, 115, 115, 0.15);
    border: 1px solid rgba(229, 115, 115, 0.3);
    color: #ef9a9a;
}

.alert-success {
    background: rgba(129, 199, 132, 0.15);
    border: 1px solid rgba(129, 199, 132, 0.3);
    color: #a5d6a7;
}

.alert-warning {
    background: rgba(255, 183, 77, 0.15);
    border: 1px solid rgba(255, 183, 77, 0.3);
    color: #ffe082;
}

/* Toasts */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.85rem 1.2rem;
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
    min-width: 260px;
    max-width: 380px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: toastIn 0.25s ease-out;
}

@keyframes toastIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.toast.success { border-left: 4px solid var(--accent-green); }
.toast.error { border-left: 4px solid var(--accent-red); }
.toast.info { border-left: 4px solid var(--accent-blue); }

/* Code / Token copy chip */
.token-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: #181e21;
    border: 1px solid var(--border-color);
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-sm);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-primary);
    cursor: pointer;
    user-select: all;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.token-chip:hover {
    border-color: #4b636d;
}

/* Code box and inline code matching theme */
code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    padding: 0.15rem 0.35rem;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
}

.code-box,
pre {
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--text-primary);
    overflow-x: auto;
}

.quickstart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

/* Utility classes */
.mobile-only {
    display: none !important;
}

.desktop-only {
    display: table-cell;
}

.table-actions {
    display: flex;
    gap: 0.4rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.modal-footer-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    gap: 0.75rem;
}

/* Responsive Overhaul */
@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: inline-flex !important;
    }

    .container {
        padding: 1rem 0.75rem;
    }

    /* Navbar Stacking */
    .navbar {
        padding: 0.65rem 0.85rem;
    }

    .navbar-inner {
        flex-direction: column;
        align-items: stretch;
        gap: 0.55rem;
    }

    .nav-brand {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        font-size: 1.05rem;
    }

    .nav-user {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        padding-top: 0.45rem;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        gap: 0.5rem;
    }

    .nav-user-meta {
        font-size: 0.8rem;
    }

    .nav-user-actions {
        display: flex;
        align-items: center;
        gap: 0.35rem;
    }

    .nav-link {
        padding: 0.3rem 0.6rem;
        font-size: 0.8rem;
    }

    /* Page Header */
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.85rem;
        margin-bottom: 1.25rem;
    }

    .page-title {
        font-size: 1.35rem;
        line-height: 1.25;
    }

    .page-subtitle {
        font-size: 0.82rem;
    }

    .page-header .btn {
        width: 100%;
        justify-content: center;
        padding: 0.65rem 1rem;
    }

    /* Stats Grid: 2x2 compact mobile layout */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.65rem;
        margin-bottom: 1.25rem;
    }

    .stat-card {
        padding: 0.8rem 0.85rem;
        gap: 0.25rem;
        border-radius: var(--radius-sm);
    }

    .stat-title {
        font-size: 0.7rem;
        font-weight: 600;
        letter-spacing: 0.03em;
    }

    .stat-value {
        font-size: 1.45rem;
        line-height: 1.15;
    }

    .stat-desc {
        font-size: 0.7rem;
    }

    /* Cards & Header */
    .card {
        padding: 1rem;
        border-radius: var(--radius-md);
        margin-bottom: 1.25rem;
    }

    .card-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        padding-bottom: 0.75rem;
        margin-bottom: 0.85rem;
    }

    .card-header .form-control {
        width: 100% !important;
        max-width: 100%;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    /* Transform Table into Mobile Cards */
    .table-responsive {
        overflow-x: visible;
    }

    .responsive-card-table thead {
        display: none;
    }

    .responsive-card-table,
    .responsive-card-table tbody,
    .responsive-card-table tr,
    .responsive-card-table td {
        display: block;
        width: 100%;
    }

    .responsive-card-table tbody {
        display: flex;
        flex-direction: column;
        gap: 0.85rem;
    }

    .responsive-card-table tr {
        background: #273136;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        padding: 0.85rem 1rem;
        box-shadow: var(--shadow-sm);
        display: flex;
        flex-direction: column;
        gap: 0.45rem;
    }

    .responsive-card-table tr:hover td {
        background: transparent;
    }

    .responsive-card-table td {
        padding: 0.35rem 0;
        border: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.5rem;
        font-size: 0.85rem;
    }

    .responsive-card-table td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.72rem;
        color: var(--text-secondary);
        text-transform: uppercase;
        letter-spacing: 0.04em;
        flex-shrink: 0;
    }

    .responsive-card-table td.cell-id {
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 0.5rem;
        margin-bottom: 0.2rem;
    }

    .responsive-card-table td.cell-id::before {
        display: none;
    }

    .responsive-card-table td.cell-id .cell-id-wrapper {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
    }

    .responsive-card-table td.cell-enterprise {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .responsive-card-table td.cell-enterprise::before {
        margin-bottom: 0.1rem;
    }

    .responsive-card-table td.cell-actions {
        border-bottom: none;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        padding-top: 0.6rem;
        margin-top: 0.2rem;
    }

    .responsive-card-table td.cell-actions::before {
        display: none;
    }

    .responsive-card-table .table-actions {
        display: flex;
        gap: 0.5rem;
        width: 100%;
    }

    .responsive-card-table .table-actions .btn {
        flex: 1;
        justify-content: center;
        padding: 0.5rem;
        font-size: 0.82rem;
    }

    .responsive-card-table td[colspan] {
        display: block;
        text-align: center;
        border: none;
        padding: 2rem 1rem;
    }

    .responsive-card-table td[colspan]::before {
        display: none;
    }

    .token-chip {
        max-width: 190px;
    }

    /* Modal Mobile */
    .modal-backdrop {
        padding: 0.5rem;
    }

    .modal-box {
        padding: 1.15rem;
        max-height: 94vh;
        width: 100%;
        border-radius: var(--radius-md);
    }

    .modal-actions {
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .modal-actions .btn {
        width: 100%;
        justify-content: center;
    }

    .modal-footer-flex {
        flex-direction: column-reverse;
        align-items: stretch;
        gap: 0.75rem;
    }

    .modal-footer-flex > button,
    .modal-footer-flex > div,
    .modal-footer-flex > div > button {
        width: 100%;
        justify-content: center;
    }

    .modal-footer-flex > div {
        display: flex;
        flex-direction: column-reverse;
        gap: 0.5rem;
    }
}

@media (max-width: 420px) {
    .nav-brand {
        font-size: 0.95rem;
    }

    .brand-badge {
        padding: 0.2rem 0.5rem;
        font-size: 0.7rem;
    }

    .nav-user-name {
        max-width: 85px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: inline-block;
        vertical-align: bottom;
    }

    .token-chip {
        max-width: 150px;
    }
}

