/* ═══════════════════════════════════════
   TikTok Ads SaaS - Stylesheet
   Dark theme · TikTok brand colors
   ═══════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;0,9..40,800;0,9..40,900&display=swap');

:root {
    --bg-deep:     #080b10;
    --bg-base:     #0d1117;
    --bg-surface:  #161b22;
    --bg-elevated: #1c2333;
    --border:      #21262d;
    --border-hover:#30363d;
    --text-primary:#e6edf3;
    --text-muted:  #848e9c;
    --text-dim:    #484f58;
    --accent:      #fe2c55;
    --accent-glow: rgba(254,44,85,0.15);
    --cyan:        #25f4ee;
    --green:       #0ecb81;
    --yellow:      #f0b90b;
    --red:         #f6465d;
    --blue:        #3b82f6;
    --purple:      #8b5cf6;
    --radius:      12px;
    --radius-sm:   8px;
    --radius-xs:   6px;
    --shadow:      0 8px 32px rgba(0,0,0,0.3);
    --shadow-lg:   0 24px 80px rgba(0,0,0,0.5);
}

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

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

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

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }

/* ── Layout ── */
.app-layout {
    display: flex;
    height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: 260px;
    background: var(--bg-deep);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-logo {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--cyan));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 18px;
}

.sidebar-logo-text h1 {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.sidebar-logo-text span {
    font-size: 10px;
    color: var(--text-dim);
    font-weight: 700;
    letter-spacing: 1.5px;
}

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

.sidebar-section {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-dim);
    letter-spacing: 1.2px;
    padding: 12px 16px 6px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.15s;
    border-left: 3px solid transparent;
    text-align: left;
}

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

.sidebar-item.active {
    background: var(--accent-glow);
    color: var(--accent);
    font-weight: 600;
    border-left-color: var(--accent);
}

.sidebar-item .badge {
    margin-left: auto;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

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

.sidebar-footer label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-dim);
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.sidebar-footer select {
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    outline: none;
}

.btn-connect-bc {
    width: 100%;
    margin-top: 8px;
    padding: 8px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px dashed var(--border-hover);
    color: var(--text-muted);
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-connect-bc:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Main Content ── */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
}

.page-header h2 {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

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

.page-header-actions {
    display: flex;
    gap: 10px;
}

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

.stat-card {
    background: var(--bg-surface);
    border-radius: 14px;
    padding: 20px 22px;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, border-color 0.2s;
}

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

.stat-card .glow {
    position: absolute;
    top: -15px;
    right: -15px;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    opacity: 0.08;
}

.stat-card .label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.stat-card .value {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -1px;
}

/* ── Table ── */
.table-container {
    background: var(--bg-surface);
    border-radius: 14px;
    border: 1px solid var(--border);
    overflow: hidden;
}

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

.table-header h3 {
    font-size: 15px;
    font-weight: 700;
}

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

table thead tr {
    border-bottom: 1px solid var(--border);
}

table th {
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-dim);
    text-align: left;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

table td {
    padding: 12px 16px;
    font-size: 13px;
}

table tbody tr {
    border-bottom: 1px solid rgba(33,38,45,0.4);
    transition: background 0.15s;
}

table tbody tr:hover {
    background: rgba(255,255,255,0.015);
}

/* ── Status Badge ── */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-xs);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.status-badge .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #e0264c; transform: translateY(-1px); }

.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-ghost { background: transparent; color: var(--text-muted); padding: 8px 12px; font-size: 13px; }
.btn-ghost:hover { color: var(--text-primary); }

.btn-success { background: var(--green); color: var(--bg-deep); }

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

.btn-icon {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: inline-flex;
    transition: color 0.15s;
}

.btn-icon:hover { color: var(--text-primary); }
.btn-icon.danger:hover { color: var(--red); }

/* ── Code ── */
code {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-base);
    padding: 3px 8px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

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

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

.modal {
    background: var(--bg-surface);
    border-radius: 16px;
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow: auto;
    border: 1px solid var(--border-hover);
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.25s ease;
}

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

.modal-header h3 {
    font-size: 17px;
    font-weight: 700;
}

.modal-body { padding: 24px; }

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

/* ── Forms ── */
.form-group {
    margin-bottom: 16px;
}

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

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

.form-control:focus { border-color: var(--accent); }

.form-control::placeholder { color: var(--text-dim); }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-hint {
    padding: 14px 16px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 13px;
    line-height: 1.6;
}

.form-hint.accent { background: var(--accent-glow); border: 1px solid rgba(254,44,85,0.2); color: #f8c4cf; }
.form-hint.blue { background: rgba(59,130,246,0.07); border: 1px solid rgba(59,130,246,0.2); color: #93c5fd; }
.form-hint.purple { background: rgba(139,92,246,0.07); border: 1px solid rgba(139,92,246,0.2); color: #c4b5fd; }

.form-hint strong { display: block; margin-bottom: 4px; }
.form-hint strong.accent { color: var(--accent); }
.form-hint strong.blue { color: var(--blue); }
.form-hint strong.purple { color: var(--purple); }

/* ── Range Slider ── */
input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    margin-top: 4px;
}

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 4px;
}

.range-labels .current {
    color: var(--accent);
    font-weight: 800;
    font-size: 20px;
}

/* ── Preview Box ── */
.preview-box {
    padding: 12px 16px;
    background: var(--bg-base);
    border-radius: 10px;
    border: 1px solid var(--border);
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.8;
}

.preview-box strong { color: var(--text-primary); }
.preview-box .highlight { color: var(--accent); font-weight: 700; }
.preview-box .code { color: var(--green); font-family: monospace; }

/* ── Progress ── */
.progress-container {
    text-align: center;
    padding: 20px 0;
}

.progress-ring {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 20px;
}

.progress-ring svg circle { transition: stroke-dasharray 0.4s ease; }

.progress-ring .percentage {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 800;
    color: var(--accent);
}

.loading-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse 1.2s ease infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ── BC Cards ── */
.bc-card {
    background: var(--bg-base);
    border-radius: 14px;
    padding: 24px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 16px;
}

.bc-card:hover { border-color: var(--border-hover); transform: translateY(-1px); }
.bc-card.active { background: var(--bg-surface); border-color: var(--accent); }

.bc-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.bc-card-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bc-card-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.bc-card.active .bc-card-icon { background: var(--accent-glow); color: var(--accent); }
.bc-card:not(.active) .bc-card-icon { background: var(--bg-elevated); color: var(--text-muted); }

.bc-card h4 { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.bc-card code { font-size: 10px; }

.bc-card-meta {
    display: flex;
    gap: 24px;
    margin-top: 16px;
    font-size: 12px;
    color: var(--text-muted);
}

.bc-card-meta strong { color: var(--text-primary); font-size: 18px; font-weight: 700; }

.bc-active-label {
    font-size: 11px;
    color: var(--accent);
    font-weight: 600;
}

/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-surface);
    border-radius: 14px;
    border: 1px solid var(--border);
}

.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.empty-state p { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }
.empty-state .actions { display: flex; gap: 12px; justify-content: center; }

/* ── Settings / API ── */
.endpoint-list {
    display: grid;
    gap: 10px;
}

.endpoint-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-base);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.endpoint-method {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    font-family: monospace;
}

.endpoint-method.post { background: rgba(14,203,129,0.12); color: var(--green); }
.endpoint-method.get { background: rgba(59,130,246,0.12); color: var(--blue); }

.endpoint-path { font-size: 12px; flex: 1; font-family: monospace; }
.endpoint-desc { font-size: 11px; color: var(--text-muted); }

.token-box {
    padding: 12px 16px;
    background: var(--bg-base);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-family: monospace;
    font-size: 13px;
    color: var(--text-muted);
    word-break: break-all;
    line-height: 1.6;
}

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

.api-limit-card {
    text-align: center;
    padding: 16px;
    background: var(--bg-base);
    border-radius: 10px;
}

.api-limit-card .num { font-size: 28px; font-weight: 800; }
.api-limit-card .desc { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Section Card ── */
.section-card {
    background: var(--bg-surface);
    border-radius: 14px;
    border: 1px solid var(--border);
    padding: 24px;
    margin-bottom: 20px;
}

.section-card h3 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-card h3 .dot { font-size: 14px; }

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    background: var(--green);
    color: var(--bg-deep);
    padding: 14px 22px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 8px 32px rgba(14,203,129,0.35);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideUp 0.3s ease;
    transition: opacity 0.3s;
}

.toast.error { background: var(--red); color: #fff; }

.toast.hiding { opacity: 0; transform: translateY(10px); }

/* ── Animations ── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 0.3; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.2); } }

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

@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { padding: 16px; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; gap: 16px; align-items: flex-start; }
}
