:root {
    --bg: #f4f6f9;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --danger: #dc2626;
    --success: #16a34a;
    --border: #e5e7eb;
    --nav-bg: #0f172a;
    --nav-bg-2: #1e293b;
    --nav-text: #cbd5e1;
    --nav-active: #ffffff;
    --nav-hover: #1e293b;
    --radius: 12px;
    --shadow: 0 1px 4px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 30px rgba(15,23,42,0.10);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}
main, .app-main { flex: 1 0 auto; }
img { max-width: 100%; }

/* =========================================================
   HEADER / TOPBAR
========================================================= */
.topbar {
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 60px;
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: 0 1px 6px rgba(15,23,42,0.06);
}
.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}
.topbar-brand {
    font-size: 17px;
    font-weight: 800;
    color: var(--text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 9px;
    letter-spacing: -0.2px;
}
.topbar-brand .brand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), #60a5fa);
    font-size: 15px;
}
.topbar-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}
.topbar-nav a {
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    padding: 8px 13px;
    border-radius: 7px;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.topbar-nav a:hover { background: #f1f5f9; color: var(--text); }
.topbar-nav a.active { background: var(--primary); color: #fff; }
.topbar-nav .nav-divider { width: 1px; height: 22px; background: var(--border); margin: 0 8px; }
.topbar-nav a.nav-logout { color: var(--danger); }
.topbar-nav a.nav-logout:hover { background: #fef2f2; color: #b91c1c; }
.topbar-user {
    color: var(--muted);
    font-size: 12px;
    padding: 0 6px;
    white-space: nowrap;
}

/* Hamburger (hidden on desktop) */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: #f8fafc;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
}
.nav-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    margin: 0 auto;
    background: var(--text);
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}
.nav-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.open span:nth-child(2) { opacity: 0; }
.nav-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.45);
    z-index: 150;
}
.nav-backdrop.show { display: block; }

/* =========================================================
   LAYOUT
========================================================= */
.container { max-width: 1100px; margin: 28px auto; padding: 0 20px; width: 100%; }
.page-title { font-size: 20px; font-weight: 700; margin: 0 0 20px; color: var(--text); }

/* ---- CARDS ---- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}
.card-title { font-size: 15px; font-weight: 700; margin: 0; }

/* ---- STATS ROW ---- */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}
.stat-label { font-size: 11px; text-transform: uppercase; color: var(--muted); font-weight: 700; letter-spacing: .5px; margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 800; color: var(--text); line-height: 1; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---- BUTTONS ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.05s;
    white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: #eef1f5; color: var(--text); }
.btn-secondary:hover { background: #dde2e8; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 6px; }

/* ---- FORMS ---- */
input[type=text], input[type=url], input[type=password], input[type=search],
input[type=date], input[type=datetime-local], textarea, select {
    width: 100%;
    padding: 10px 13px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    margin-top: 5px;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #fff;
    color: var(--text);
    font-family: inherit;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
label { font-size: 13px; font-weight: 600; color: var(--text); }
.field { margin-bottom: 18px; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 5px; }

/* ---- TABLE ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 480px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f9fafb; }

/* ---- BADGES ---- */
.badge { padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; display: inline-block; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #fee2e2; color: var(--danger); }
.badge-bot { background: #e0e7ff; color: #4338ca; }
.badge-expired { background: #fef3c7; color: #92400e; }

/* ---- FLASH ---- */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-size: 13px; font-weight: 500; }
.flash-success { background: #dcfce7; color: #166534; border-left: 3px solid #16a34a; }
.flash-error { background: #fee2e2; color: #991b1b; border-left: 3px solid var(--danger); }

/* ---- MISC ---- */
.muted { color: var(--muted); font-size: 13px; }
.short-link-box { display: flex; gap: 8px; align-items: center; background: var(--primary-light); padding: 12px; border-radius: 9px; flex-wrap: wrap; }
.short-link-box input { background: #fff; margin: 0; flex: 1 1 200px; }
a.row-action { font-size: 12px; font-weight: 600; margin-right: 10px; text-decoration: none; color: var(--primary); }
a.row-action.danger { color: var(--danger); }
a.row-action:hover { text-decoration: underline; }
.empty-state { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty-state .empty-icon { font-size: 38px; margin-bottom: 10px; }

/* ---- LOGIN PAGE ---- */
.login-wrap {
    flex: 1;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #eef2ff 0%, #f4f6f9 60%);
    padding: 20px;
}
.login-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 38px 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 16px 45px rgba(15,23,42,0.10);
}
.login-logo {
    width: 52px; height: 52px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), #60a5fa);
    font-size: 24px;
    margin-bottom: 16px;
}
.login-title { font-size: 21px; font-weight: 800; margin: 0 0 4px; }
.login-sub { font-size: 13px; color: var(--muted); margin: 0 0 24px; }

/* =========================================================
   FOOTER
========================================================= */
.site-footer {
    margin-top: auto;
    background: #ffffff;
    border-top: 1px solid var(--border);
    color: var(--muted);
    padding: 26px 20px;
    font-size: 12.5px;
}
.footer-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.footer-brand { color: var(--text); font-weight: 700; display: flex; align-items: center; gap: 6px; }
.footer-links { display: flex; gap: 16px; flex-wrap: wrap; }
.footer-links a { color: var(--muted); text-decoration: none; }
.footer-links a:hover { color: var(--primary); }
.footer-copy { width: 100%; text-align: center; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); color: #94a3b8; }

/* =========================================================
   PUBLIC LANDING PAGE
========================================================= */
.public-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #eef2ff 0%, #f4f6f9 60%);
    padding: 32px 20px;
}
.public-box {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 48px 36px;
    max-width: 460px;
    width: 100%;
    text-align: center;
    box-shadow: 0 16px 50px rgba(15,23,42,0.10);
}
.public-logo {
    width: 64px; height: 64px;
    margin: 0 auto 16px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary), #60a5fa);
    font-size: 30px;
}
.public-brand { font-size: 11px; font-weight: 700; letter-spacing: 3px; text-transform: uppercase; color: var(--primary); margin-bottom: 12px; }
.public-box h1 { font-size: 22px; font-weight: 800; color: #0f172a; margin: 0 0 12px; }
.public-box p { color: #6b7280; font-size: 14px; line-height: 1.75; margin: 0 0 10px; }
.public-note { font-size: 12px; color: #9ca3af; margin-top: 22px; }
.public-admin-link {
    display: inline-block; margin-top: 26px; font-size: 12px; font-weight: 600;
    color: var(--primary); text-decoration: none; padding: 8px 16px;
    border: 1px solid var(--border); border-radius: 8px; transition: background 0.15s;
}
.public-admin-link:hover { background: var(--primary-light); }

/* ---- COPY ICON BUTTON ---- */
.copy-icon-btn {
    border: 1px solid var(--border);
    background: #f8fafc;
    border-radius: 6px;
    width: 24px;
    height: 24px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
}
.copy-icon-btn:hover { background: var(--primary-light); border-color: var(--primary); }

.copy-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.copy-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }


.period-tabs { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:0; }
.period-tab {
    padding:7px 14px; border-radius:7px; font-size:13px; font-weight:600;
    text-decoration:none; color:var(--muted); background:#f1f5f9;
    border:1.5px solid transparent; transition:all 0.15s;
}
.period-tab:hover { background:#e2e8f0; color:var(--text); }
.period-tab.active { background:var(--primary); color:#fff; border-color:var(--primary); }

.custom-range {
    display:flex; gap:8px; align-items:center; flex-wrap:wrap;
    padding:14px 16px; background:#f8fafc; border-radius:9px;
    border:1px solid var(--border); margin-top:12px;
}
.custom-range input[type=date] { width:auto; margin:0; }
.custom-range label { font-size:12px; font-weight:600; color:var(--muted); white-space:nowrap; }

.chart-wrap { position:relative; height:260px; width:100%; }

.stat-card .stat-value.big { font-size:36px; }
.stat-card.highlight { border-left:3px solid var(--primary); }

.bot-badge { display:inline-flex; align-items:center; gap:5px; background:#f0f4ff; color:#4338ca; font-size:12px; font-weight:600; padding:4px 10px; border-radius:20px; }

.donut-wrap { display:flex; align-items:center; gap:24px; flex-wrap:wrap; }
.donut-chart { width:100px; height:100px; flex-shrink:0; }
.donut-legend { display:flex; flex-direction:column; gap:8px; }
.legend-item { display:flex; align-items:center; gap:8px; font-size:13px; }
.legend-dot { width:10px; height:10px; border-radius:50%; flex-shrink:0; }

/* =========================================================
   RESPONSIVE — MOBILE
========================================================= */
@media (max-width: 860px) {
    .topbar { padding: 0 16px; }
    .nav-toggle { display: flex; }

    .topbar-nav {
        position: fixed;
        top: 60px;
        right: 0;
        height: calc(100vh - 60px);
        width: min(78vw, 300px);
        background: #ffffff;
        border-left: 1px solid var(--border);
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
        padding: 16px;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        z-index: 200;
        box-shadow: -8px 0 30px rgba(15,23,42,0.15);
        overflow-y: auto;
    }
    .topbar-nav.open { transform: translateX(0); }
    .topbar-nav a { width: 100%; padding: 12px 14px; font-size: 14px; }
    .topbar-nav .nav-divider { width: 100%; height: 1px; margin: 8px 0; }
    .topbar-user { padding: 10px 14px 2px; order: -1; }

    .container { margin: 18px auto; padding: 0 14px; }
    .card { padding: 16px; border-radius: 10px; }
    .stats-row { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
    .stat-value { font-size: 22px; }
    .stat-value.big { font-size: 26px; }

    .login-card, .public-box { padding: 30px 22px; border-radius: 16px; }

    .footer-inner { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
    table { min-width: 0; font-size: 12.5px; }
    th, td { padding: 9px 7px; }
    .btn { padding: 9px 14px; font-size: 12.5px; }
    .donut-wrap { flex-direction: column; align-items: flex-start; }
}
