/* ─── Design Tokens ────────────────────────────────────────────────────────── */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a2e;
    --bg-card-hover: #1f1f35;
    --bg-elevated: #22223a;
    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);

    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-muted: #55556a;

    --accent: #6c5ce7;
    --accent-hover: #7d6ff0;
    --accent-glow: rgba(108, 92, 231, 0.25);
    --success: #00d68f;
    --success-bg: rgba(0, 214, 143, 0.1);
    --warning: #ffaa00;
    --warning-bg: rgba(255, 170, 0, 0.1);
    --danger: #ff6b6b;
    --danger-bg: rgba(255, 107, 107, 0.1);
    --info: #4dabf7;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.5);

    --sidebar-width: 260px;
    --header-height: 64px;

    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 16px;
    color: white;
    box-shadow: 0 0 20px var(--accent-glow);
}

.logo-text {
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
}

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

.nav-item.active {
    background: var(--accent-glow);
    color: var(--accent-hover);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(0, 214, 143, 0.5);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ─── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(12px);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.health-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    background: var(--bg-card);
    padding: 6px 14px;
    border-radius: 100px;
    border: 1px solid var(--border);
}

.health-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background var(--transition);
}

.health-indicator.ok .health-dot { background: var(--success); box-shadow: 0 0 8px rgba(0, 214, 143, 0.5); }
.health-indicator.error .health-dot { background: var(--danger); }

/* ─── Pages ────────────────────────────────────────────────────────────────── */
.page {
    display: none;
    padding: 28px 32px;
    animation: fadeIn 0.3s ease;
}

.page.active { display: block; }

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

/* ─── Stats Grid ───────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all var(--transition);
}

.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.plans-icon { background: rgba(108, 92, 231, 0.15); color: var(--accent); }
.providers-icon { background: rgba(0, 214, 143, 0.12); color: var(--success); }
.api-icon { background: rgba(77, 171, 247, 0.12); color: var(--info); }
.status-icon { background: rgba(255, 170, 0, 0.12); color: var(--warning); }

.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 28px; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.stat-label { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* ─── Section Headers ──────────────────────────────────────────────────────── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ─── Providers ────────────────────────────────────────────────────────────── */
.providers-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}

.provider-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.provider-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.provider-logo {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 800;
    color: white;
    margin-bottom: 14px;
}

.omise-bg { background: linear-gradient(135deg, #1a3c6d, #2d6bcf); }
.apple-bg { background: linear-gradient(135deg, #1a1a1a, #333); }
.google-bg { background: linear-gradient(135deg, #4285f4, #34a853); }

.provider-info h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.provider-info p { font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; }

.provider-endpoints { display: flex; gap: 6px; flex-wrap: wrap; }

.endpoint-badge {
    font-size: 11px;
    padding: 3px 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 100px;
    color: var(--text-muted);
}

.provider-status {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 100px;
    background: var(--warning-bg);
    color: var(--warning);
}

.provider-status.connected {
    background: var(--success-bg);
    color: var(--success);
}

/* ─── Plans Table ──────────────────────────────────────────────────────────── */
.page-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 16px;
}

.plans-table-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.plans-table {
    width: 100%;
    border-collapse: collapse;
}

.plans-table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
}

.plans-table td {
    padding: 14px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.plans-table tbody tr {
    transition: background var(--transition);
}

.plans-table tbody tr:hover {
    background: var(--bg-card-hover);
}

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

.plans-table code {
    font-size: 12px;
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 4px;
    color: var(--info);
}

.plans-table .plan-code {
    font-weight: 600;
    color: var(--accent-hover);
}

.plans-table .price { font-variant-numeric: tabular-nums; }

/* ─── Plans Preview ────────────────────────────────────────────────────────── */
.plans-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.plan-preview-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px;
    transition: all var(--transition);
}

.plan-preview-card:hover {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
}

.plan-preview-card h4 { font-size: 16px; font-weight: 600; }
.plan-preview-card .plan-code-tag {
    font-size: 11px;
    background: var(--accent-glow);
    color: var(--accent-hover);
    padding: 2px 8px;
    border-radius: 100px;
    display: inline-block;
    margin-bottom: 8px;
}
.plan-preview-card .plan-price {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -1px;
    margin-top: 4px;
}
.plan-preview-card .plan-price span {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 400;
}

/* ─── Billing Endpoint List ────────────────────────────────────────────────── */
.billing-grid { max-width: 800px; }

.billing-section h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
}

.endpoint-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.endpoint-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.endpoint-item:hover {
    border-color: var(--border-hover);
    background: var(--bg-card-hover);
}

.endpoint-item code {
    font-size: 13px;
    color: var(--text-primary);
    flex: 1;
}

.endpoint-desc {
    font-size: 12px;
    color: var(--text-muted);
}

.method {
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    min-width: 40px;
    text-align: center;
    flex-shrink: 0;
}

.method.get { background: rgba(0, 214, 143, 0.15); color: var(--success); }
.method.post { background: rgba(77, 171, 247, 0.15); color: var(--info); }
.method.delete { background: rgba(255, 107, 107, 0.15); color: var(--danger); }

/* ─── Settings ─────────────────────────────────────────────────────────────── */
.settings-grid {
    display: grid;
    gap: 16px;
    max-width: 600px;
}

.settings-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
}

.settings-card h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.setting-row label {
    font-size: 13px;
    color: var(--text-secondary);
}

.setting-row code {
    font-size: 12px;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 10px;
    border-radius: 4px;
    color: var(--info);
}

.setting-value { font-size: 13px; }

.setting-row.hint {
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.setting-row.hint p {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 0 16px var(--accent-glow);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 0 24px var(--accent-glow);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
}

.btn-sm { padding: 6px 14px; font-size: 13px; }

.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(255, 107, 107, 0.2); }
.btn-danger:hover { background: rgba(255, 107, 107, 0.2); }

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-icon:hover { background: rgba(255, 255, 255, 0.06); color: var(--text-primary); border-color: var(--border); }
.btn-icon.danger:hover { color: var(--danger); background: var(--danger-bg); }

/* ─── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 480px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 18px; font-weight: 700; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

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

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    padding: 24px;
}

.form-group.full { grid-column: 1 / -1; }

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    transition: all var(--transition);
    outline: none;
}

.form-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder { color: var(--text-muted); }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

/* ─── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    gap: 12px;
    color: var(--text-muted);
    font-size: 14px;
}

.empty-state.small { padding: 32px; }

/* ─── Toast ────────────────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    box-shadow: var(--shadow-md);
    animation: slideInRight 0.3s ease;
    min-width: 240px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }

@keyframes slideInRight {
    from { transform: translateX(100px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .providers-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .stats-grid { grid-template-columns: 1fr; }
    .header { padding: 0 16px; }
    .page { padding: 20px 16px; }
}
