/* Dashboard theme */
:root {
    --sidebar-bg: #0f172a;
    --sidebar-active: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-hover: #e2e8f0;
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    /* Never allow the page itself to scroll sideways. */
    overflow-x: hidden;
    max-width: 100%;
}

body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* App shell */
.app-shell {
    display: block;
}

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

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

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1040;
    flex: 0 0 260px;
}

.brand {
    padding: 1.5rem;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand i {
    color: var(--primary);
    font-size: 1.6rem;
}

.sidebar .nav {
    padding: 1rem 0;
    gap: 0.25rem;
}

.sidebar .nav-link {
    color: var(--sidebar-text);
    padding: 0.85rem 1.5rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-radius: 0;
    border-left: 3px solid transparent;
    transition: all .15s ease;
}

.sidebar .nav-link:hover,
.sidebar .nav-link:focus {
    color: var(--sidebar-hover);
    background: rgba(255,255,255,0.04);
    border-left-color: rgba(255,255,255,0.2);
}

.sidebar .nav-link.active {
    color: #fff;
    background: var(--sidebar-active);
    border-left-color: var(--primary);
}

.sidebar .nav-link i {
    font-size: 1.1rem;
    width: 1.25rem;
    text-align: center;
}

.sidebar-footer {
    margin-top: auto;
    padding: 1rem 1.5rem;
    color: var(--sidebar-text);
    font-size: .75rem;
    border-top: 1px solid rgba(255,255,255,0.06);
}

/* Main content */
.main-content {
    margin-left: 260px;
    /* Hard-cap the width so wide tables can never widen the page. */
    width: calc(100% - 260px);
    max-width: calc(100% - 260px);
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
}

.topbar {
    min-height: 70px;
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 2rem;
    position: sticky;
    top: 0;
    z-index: 1020;
    flex-wrap: wrap;
}

.page-title {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.02em;
}

.topbar-actions {
    display: flex;
    gap: 0.5rem;
}

.content-area {
    padding: 2rem;
    flex: 1;
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
}

/* Anything inside the content area must not exceed its column. */
.content-area > * {
    max-width: 100%;
    min-width: 0;
}

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

.page-header h1,
.page-header h2,
.page-header h3 {
    font-weight: 700;
    letter-spacing: -0.03em;
    margin: 0;
}

.count-badge {
    font-size: .85rem;
    font-weight: 500;
    color: var(--muted);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 50rem;
    padding: .35rem .85rem;
}

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

.stat-card {
    background: var(--card-bg);
    border-radius: 1rem;
    padding: 1.4rem 1.5rem;
    box-shadow: 0 4px 24px rgba(15,23,42,.04);
    border-left: 4px solid var(--primary);
}

.stat-label {
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin-bottom: .35rem;
}

.stat-value {
    font-size: 1.9rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

/* Cards */
.card {
    background: var(--card-bg);
    border: none;
    border-radius: 1rem;
    box-shadow: 0 4px 24px rgba(15,23,42,.04);
    margin-bottom: 1.5rem;
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 1.25rem 1.5rem;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-body {
    padding: 1.5rem;
}

.card-title {
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* Buttons */
.btn {
    border-radius: .5rem;
    font-weight: 500;
    padding: .55rem 1rem;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: #fff;
}

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}

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

.btn-sm {
    padding: .35rem .65rem;
    font-size: .875rem;
}

.btn-outline-success {
    color: var(--success);
    border-color: var(--success);
}

.btn-outline-success:hover,
.btn-outline-success:focus {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}

/* Icon-only action buttons in tables */
.col-actions .btn {
    padding: .35rem .55rem;
    line-height: 1;
}

.col-actions .btn i {
    font-size: .95rem;
}

/* Tables — scroll horizontally inside the card, not the page */
.card > .table-responsive {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    border-bottom-left-radius: 1rem;
    border-bottom-right-radius: 1rem;
    -webkit-overflow-scrolling: touch;
}

.table-responsive {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.table-responsive::-webkit-scrollbar {
    height: 10px;
}

.table-responsive::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 50rem;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.table {
    margin-bottom: 0;
    color: var(--text);
    font-size: .875rem;
}

.table thead th {
    background: #f1f5f9;
    color: #475569;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: none;
    padding: .9rem 1rem;
    white-space: nowrap;
}

/* Compact country traffic columns */
.table td.country-col,
.table th.country-col {
    text-align: right;
    min-width: 60px;
    padding: .9rem .7rem;
}

.table th.country-col {
    text-align: center;
}

.table td.total-col,
.table th.total-col {
    text-align: right;
    padding: .9rem .7rem;
}

.table tbody td {
    padding: .9rem 1.25rem;
    vertical-align: middle;
    border-color: var(--border);
}

/* Keep wide free-text columns from stretching the table */
.cell-clamp {
    display: block;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cell-wrap {
    display: block;
    max-width: 220px;
    white-space: normal;
    font-size: .85rem;
    color: var(--muted);
}

.col-actions {
    white-space: nowrap;
}

.table-hover tbody tr:hover {
    background: #f8fafc;
}

.table a {
    font-weight: 500;
}

/* Forms */
.form-control,
.form-select {
    border-radius: .5rem;
    border-color: var(--border);
    padding: .65rem .85rem;
    font-size: .95rem;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 .2rem rgba(99,102,241,.15);
}

.form-label {
    font-weight: 500;
    color: #475569;
    font-size: .9rem;
}

/* Badges */
.badge-soft {
    background: #e0e7ff;
    color: var(--primary);
    padding: .35em .75em;
    border-radius: .375rem;
    font-weight: 500;
    font-size: .8rem;
}

/* Status badges */
.badge-status {
    display: inline-block;
    padding: .3em .7em;
    border-radius: .375rem;
    font-size: .78rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-success {
    background: #d1fae5;
    color: #047857;
}

.badge-warning {
    background: #fef3c7;
    color: #b45309;
}

.badge-danger {
    background: #fee2e2;
    color: #b91c1c;
}

.progress {
    background: #e2e8f0;
    border-radius: 50rem;
    overflow: hidden;
}

.progress-bar {
    background: var(--primary);
    transition: width .4s ease;
}

/* Alerts */
.alert {
    border-radius: .75rem;
    border: none;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

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

.empty-state i {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: #cbd5e1;
}

/* Responsive: collapse sidebar to an icon rail */
@media (max-width: 991.98px) {
    .sidebar {
        width: 72px;
        flex: 0 0 72px;
    }
    .brand {
        justify-content: center;
        padding: 1.5rem .5rem;
    }
    .brand span,
    .sidebar .nav-link span,
    .sidebar-footer {
        display: none;
    }
    .sidebar .nav-link {
        justify-content: center;
        padding: .9rem .5rem;
    }
    .main-content {
        margin-left: 72px;
        width: calc(100% - 72px);
        max-width: calc(100% - 72px);
    }
    .topbar,
    .content-area {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }
}
