/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --bg-input: #0f172a;
    --border: #334155;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --success: #10b981;
    --danger: #ef4444;
    --danger-hover: #f87171;
    --warning: #f59e0b;
    --radius: 8px;
    --sidebar-w: 240px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

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

/* === Sidebar === */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

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

.logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-hover);
}

.nav-links {
    list-style: none;
    padding: 1rem 0;
    flex: 1;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: var(--text-muted);
    transition: all 0.15s;
    text-decoration: none;
}

.nav-links a:hover, .nav-links a.active {
    background: var(--bg-hover);
    color: var(--text);
}

.nav-links a.active {
    border-right: 3px solid var(--primary);
}

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

.logout-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
}
.logout-link:hover { color: var(--danger); text-decoration: none; }

/* === Main Content === */
.content {
    margin-left: var(--sidebar-w);
    padding: 2rem;
    max-width: 1200px;
}

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.stat-card .label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

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

.stat-card .value.primary { color: var(--primary-hover); }
.stat-card .value.success { color: var(--success); }
.stat-card .value.warning { color: var(--warning); }

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

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.375rem;
}

input[type="text"], input[type="url"], input[type="password"], input[type="date"],
input[type="datetime-local"], input[type="number"], textarea, select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

textarea { resize: vertical; min-height: 100px; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    font-family: inherit;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); text-decoration: none; }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; }

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

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

th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}

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

/* === Alerts === */
.alert {
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-success { background: rgba(16, 185, 129, 0.1); border: 1px solid var(--success); color: var(--success); }
.alert-error { background: rgba(239, 68, 68, 0.1); border: 1px solid var(--danger); color: var(--danger); }
.alert-info { background: rgba(99, 102, 241, 0.1); border: 1px solid var(--primary); color: var(--primary-hover); }

/* === Badges === */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-active { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.badge-inactive { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* === Pagination === */
.pagination {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    margin-top: 1rem;
}

.page-btn {
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.875rem;
    text-decoration: none;
    border: 1px solid var(--border);
}

.page-btn:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-dots { color: var(--text-muted); padding: 0 0.5rem; }

/* === Short URL display === */
.short-url {
    font-family: 'SF Mono', 'Consolas', 'Liberation Mono', monospace;
    background: var(--bg);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--primary-hover);
    cursor: pointer;
    border: 1px solid var(--border);
}

.short-url:hover { border-color: var(--primary); text-decoration: none; }

.copy-toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--success);
    color: #fff;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 9999;
}

.copy-toast.show { opacity: 1; }

/* === Inline form row === */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* === Modal === */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

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

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 90%;
    max-width: 500px;
}

.modal h2 { margin-bottom: 1rem; }

/* === Map container === */
#map {
    height: 400px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

/* === Chart containers === */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.chart-container {
    position: relative;
    height: 250px;
}

/* === Login page === */
.login-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 2rem;
}

.login-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.login-box .subtitle {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.login-box .btn { width: 100%; justify-content: center; }

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar {
        position: static;
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
    }
    .sidebar-header { padding: 0.75rem 1rem; border-bottom: none; border-right: 1px solid var(--border); }
    .nav-links { display: flex; padding: 0; }
    .nav-links a { padding: 0.75rem 1rem; white-space: nowrap; }
    .nav-links a.active { border-right: none; border-bottom: 3px solid var(--primary); }
    .sidebar-footer { padding: 0.75rem 1rem; border-top: none; border-left: 1px solid var(--border); }
    .content { margin-left: 0; padding: 1rem; }
    .form-row { grid-template-columns: 1fr; }
    .chart-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* === Actions row === */
.actions { display: flex; gap: 0.5rem; }

/* === Empty state === */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state svg {
    margin-bottom: 1rem;
    opacity: 0.4;
}

.empty-state p {
    font-size: 1rem;
    margin-bottom: 1rem;
}

/* === Top list === */
.top-list {
    list-style: none;
}

.top-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--border);
}

.top-list li:last-child { border-bottom: none; }

.top-list .count {
    font-weight: 600;
    color: var(--primary-hover);
    font-size: 0.9rem;
}

/* === Link target (truncated) === */
.target-url {
    color: var(--text-muted);
    font-size: 0.8rem;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

/* === Date filter row === */
.filter-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.filter-row .form-group { margin-bottom: 0; }

/* === Code editor style textarea === */
textarea.code {
    font-family: 'SF Mono', 'Consolas', 'Liberation Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    tab-size: 4;
    min-height: 200px;
}

/* === Recent clicks table === */
.flag { margin-right: 0.25rem; }
