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

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a2e;
    --bg-input: #16162a;
    --border: #2a2a4a;
    --border-focus: #6c5ce7;
    --text-primary: #e8e8f0;
    --text-secondary: #8888a8;
    --text-muted: #555570;
    --accent: #6c5ce7;
    --accent-hover: #7d6ff0;
    --accent-glow: rgba(108, 92, 231, 0.3);
    --success: #00d2a0;
    --danger: #ff6b6b;
    --warning: #ffd166;
    --chart-1: #6c5ce7;
    --chart-2: #00d2a0;
    --chart-3: #ffd166;
    --chart-4: #ff6b6b;
    --chart-5: #54a0ff;
    --chart-6: #ff9ff3;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
}

/* --- Navbar --- */
.navbar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

.nav-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.logo-icon {
    font-size: 1.4rem;
}

.nav-links {
    display: flex;
    gap: 8px;
}

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition);
}

.nav-link:hover {
    color: var(--text-primary);
    background: rgba(108, 92, 231, 0.1);
}

.nav-link.active {
    color: var(--accent);
    background: rgba(108, 92, 231, 0.15);
}

/* --- Main content --- */
.main-content {
    flex: 1;
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 24px;
    width: 100%;
}

/* --- Footer --- */
.footer {
    border-top: 1px solid var(--border);
    padding: 20px 24px;
    text-align: center;
}

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

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
}

.card-header {
    margin-bottom: 20px;
}

.card-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-header p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 4px;
}

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

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

.form-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color var(--transition);
    outline: none;
}

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

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

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

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 20px var(--accent-glow);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.8rem;
    border-radius: 6px;
}

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

.btn-ghost:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

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

.btn-danger:hover {
    background: rgba(255, 107, 107, 0.1);
}

.btn-full {
    width: 100%;
}

/* --- Hero / Landing --- */
.hero {
    text-align: center;
    padding: 60px 0 40px;
}

.hero h1 {
    font-size: 2.8rem;
    font-weight: 800;
    letter-spacing: -1.5px;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    color: var(--text-secondary);
    font-size: 1.1rem;
    max-width: 500px;
    margin: 0 auto;
}

.shorten-form {
    max-width: 640px;
    margin: 32px auto 0;
}

.url-input-group {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.url-input-group .form-input {
    flex: 1;
    padding: 14px 18px;
    font-size: 1rem;
}

.url-input-group .btn {
    padding: 14px 28px;
    white-space: nowrap;
}

.options-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    margin-bottom: 12px;
    user-select: none;
}

.options-toggle:hover {
    color: var(--text-primary);
}

.options-panel {
    display: none;
    margin-bottom: 16px;
}

.options-panel.open {
    display: block;
}

/* --- Result box --- */
.result-box {
    display: none;
    margin-top: 24px;
    padding: 20px;
    background: rgba(108, 92, 231, 0.08);
    border: 1px solid rgba(108, 92, 231, 0.25);
    border-radius: var(--radius);
    text-align: center;
}

.result-box.visible {
    display: block;
    animation: slideUp 0.3s ease;
}

.result-url {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent);
    word-break: break-all;
    margin-bottom: 12px;
}

.result-url a {
    color: inherit;
    text-decoration: none;
}

.result-url a:hover {
    text-decoration: underline;
}

.result-original {
    color: var(--text-muted);
    font-size: 0.8rem;
    word-break: break-all;
    margin-bottom: 16px;
}

.copy-btn {
    min-width: 120px;
}

.copy-btn.copied {
    background: var(--success);
}

/* --- Table --- */
.table-wrap {
    overflow-x: auto;
}

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

th {
    text-align: left;
    padding: 10px 14px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 12px 14px;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(42, 42, 74, 0.5);
    vertical-align: middle;
}

tr:hover td {
    background: rgba(108, 92, 231, 0.04);
}

.url-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.code-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.code-link:hover {
    text-decoration: underline;
}

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-active {
    background: rgba(0, 210, 160, 0.15);
    color: var(--success);
}

.badge-expired {
    background: rgba(255, 209, 102, 0.15);
    color: var(--warning);
}

.badge-inactive {
    background: rgba(255, 107, 107, 0.15);
    color: var(--danger);
}

.badge-custom {
    background: rgba(108, 92, 231, 0.15);
    color: var(--accent);
    margin-left: 6px;
}

.clicks-count {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.table-actions {
    display: flex;
    gap: 6px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

/* --- Analytics dashboard --- */
.analytics-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
}

.analytics-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.analytics-header .code-badge {
    font-family: 'SF Mono', 'Fira Code', monospace;
    background: rgba(108, 92, 231, 0.15);
    color: var(--accent);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
}

.analytics-meta {
    color: var(--text-secondary);
    font-size: 0.85rem;
    word-break: break-all;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

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

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.chart-card.full-width {
    grid-column: 1 / -1;
}

.chart-card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.chart-container {
    position: relative;
    width: 100%;
    height: 220px;
}

.chart-container.tall {
    height: 280px;
}

/* Bar chart (CSS-only) */
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 100%;
    padding-top: 20px;
}

.bar-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.bar {
    width: 100%;
    max-width: 40px;
    border-radius: 4px 4px 0 0;
    background: var(--accent);
    min-height: 2px;
    transition: height 0.5s ease;
    position: relative;
}

.bar:hover {
    background: var(--accent-hover);
}

.bar-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.bar-value {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* Horizontal bar chart */
.h-bar-chart {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
    justify-content: center;
}

.h-bar-row {
    display: grid;
    grid-template-columns: 100px 1fr 50px;
    align-items: center;
    gap: 12px;
}

.h-bar-name {
    font-size: 0.82rem;
    color: var(--text-secondary);
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.h-bar-track {
    height: 20px;
    background: rgba(108, 92, 231, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.h-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.h-bar-count {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* Donut / pie legend */
.pie-container {
    display: flex;
    align-items: center;
    gap: 24px;
    height: 100%;
}

.pie-svg {
    flex-shrink: 0;
}

.pie-legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-label {
    color: var(--text-secondary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.legend-value {
    color: var(--text-primary);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* --- API key prompt --- */
.api-key-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 24px;
}

.api-key-bar label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    font-weight: 500;
}

.api-key-bar .form-input {
    flex: 1;
    padding: 8px 12px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.82rem;
}

/* --- Animations --- */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: slideUp 0.3s ease;
}

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

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    animation: slideUp 0.3s ease;
    box-shadow: var(--shadow);
}

.toast-success {
    background: rgba(0, 210, 160, 0.15);
    border: 1px solid rgba(0, 210, 160, 0.3);
    color: var(--success);
}

.toast-error {
    background: rgba(255, 107, 107, 0.15);
    border: 1px solid rgba(255, 107, 107, 0.3);
    color: var(--danger);
}

/* --- Loading spinner --- */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .hero h1 { font-size: 2rem; }
    .url-input-group { flex-direction: column; }
    .form-row { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .analytics-header { flex-direction: column; align-items: flex-start; }
    .h-bar-row { grid-template-columns: 80px 1fr 40px; }
    .pie-container { flex-direction: column; }
}

@media (max-width: 480px) {
    .nav-container { padding: 0 16px; }
    .main-content { padding: 24px 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .hero h1 { font-size: 1.6rem; }
}
