/* Global Variables & Theme */
:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #3b82f6;
    --accent-success: #10b981;
    --accent-purple: #8b5cf6;
    --accent-orange: #f59e0b;
    --accent-red: #ef4444;
    --border-color: #334155;
    --row-hover: #273549;
    --card-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color); color: var(--text-primary);
    padding: 2rem 1.5rem; line-height: 1.5; min-height: 100vh;
}
.container { max-width: 1200px; margin: 0 auto; }
a { color: inherit; }

/* Header & Navigation */
header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 2rem; border-bottom: 1px solid var(--border-color); padding-bottom: 1rem; gap: 1rem;
}
h1 { font-size: 1.75rem; font-weight: 600; }
h1 span { color: var(--accent-color); }
.nav-actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.nav-btn {
    background-color: rgba(255,255,255,.03); color: var(--text-secondary); padding: .5rem .95rem;
    border-radius: 8px; font-size: .85rem; font-weight: 600; text-decoration: none;
    border: 1px solid var(--border-color); transition: all .2s ease; white-space: nowrap; cursor: pointer; font-family: inherit;
}
.nav-btn:hover { background-color: rgba(255,255,255,.08); color: var(--text-primary); border-color: rgba(255,255,255,.15); }
.nav-btn.active { background-color: rgba(59,130,246,.15); color: #60a5fa; border-color: rgba(59,130,246,.3); }
.nav-btn.danger { color: #f87171; border-color: rgba(239,68,68,.3); }
.refresh-btn {
    background-color: var(--accent-color); color: #fff; border: none; padding: .6rem 1.2rem; border-radius: 8px;
    cursor: pointer; font-weight: 600; font-size: .9rem; transition: background-color .2s ease; text-decoration: none;
    display: inline-flex; align-items: center; gap: .5rem; font-family: inherit;
}
.refresh-btn:hover { background-color: #2563eb; }
.refresh-btn.secondary { background: rgba(255,255,255,.06); border: 1px solid var(--border-color); color: var(--text-primary); }
.refresh-btn.secondary:hover { background: rgba(255,255,255,.12); }

/* Filter bar */
.filter-bar {
    display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,.08); padding-bottom: 1rem;
}
.filter-btn {
    background-color: rgba(255,255,255,.05); color: var(--text-secondary); border: 1px solid rgba(255,255,255,.1);
    padding: 6px 14px; border-radius: 20px; text-decoration: none; font-size: .75rem; font-weight: 500;
    transition: all .2s ease; display: inline-flex; align-items: center; justify-content: center; line-height: 1.3; cursor: pointer; font-family: inherit;
}
.filter-btn:hover { background-color: rgba(255,255,255,.1); color: var(--text-primary); }
.filter-btn.active { background-color: #3b82f6; color: #fff; border-color: #3b82f6; font-weight: 600; }
.segmented { display: inline-flex; padding: 3px; border-radius: 20px; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.1); }
.segmented a { padding: 5px 14px; border-radius: 16px; font-size: .75rem; font-weight: 500; color: var(--text-secondary); text-decoration: none; }
.segmented a.active { background: #3b82f6; color: #fff; font-weight: 600; }
.divider-v { width: 1px; height: 22px; background: var(--border-color); margin: 0 .3rem; }
.app-icons-container { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.app-icon-item { position: relative; display: inline-flex; width: 38px; height: 38px; border-radius: 10px; text-decoration: none; transition: all .2s cubic-bezier(.4,0,.2,1); opacity: .75; }
.app-icon-item:hover, .app-icon-item.active { opacity: 1; transform: translateY(-2px) scale(1.06); }
.app-icon-item img { width: 38px; height: 38px; border-radius: 10px; object-fit: cover; background: rgba(255,255,255,.05); border: 1.5px solid rgba(255,255,255,.15); box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.app-icon-item.active img, .app-icon-item.active .app-icon-placeholder { border: 2.5px solid #fff !important; box-shadow: 0 0 0 2px rgba(255,255,255,.35), 0 4px 14px rgba(0,0,0,.6) !important; color: #fff; }
.app-icon-placeholder {
    width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg,#1e293b,#334155);
    border: 1.5px solid rgba(255,255,255,.15); display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .75rem; color: #94a3b8; text-transform: uppercase;
}
.icon-sm { width: 30px; height: 30px; border-radius: 8px; object-fit: cover; vertical-align: middle; }
.icon-sm.ph { display: inline-flex; align-items: center; justify-content: center; background: linear-gradient(135deg,#1e293b,#334155); color: #94a3b8; font-size: .65rem; font-weight: 700; }

/* Cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
.card, .chart-card { background-color: var(--card-bg); border: 1px solid var(--border-color); border-radius: 12px; padding: 1.5rem; box-shadow: var(--card-shadow); }
.stat-card { background-color: var(--card-bg); border: 1px solid var(--border-color); border-radius: 12px; padding: 1.5rem; box-shadow: var(--card-shadow); position: relative; overflow: hidden; }
.stat-card::after { content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; }
.stat-card.blue::after { background: var(--accent-color); } .stat-card.purple::after { background: var(--accent-purple); }
.stat-card.green::after { background: var(--accent-success); } .stat-card.orange::after { background: var(--accent-orange); }
.stat-card.red::after { background: var(--accent-red); }
.stat-title { font-size: .85rem; color: var(--text-secondary); text-transform: uppercase; font-weight: 700; letter-spacing: .05em; margin-bottom: .5rem; }
.stat-value { font-size: 2.25rem; font-weight: 800; letter-spacing: -.03em; }
.stat-list { list-style: none; margin-top: .5rem; }
.stat-item { display: flex; justify-content: space-between; align-items: center; padding: .5rem 0; border-bottom: 1px solid rgba(255,255,255,.05); font-size: .9rem; }
.stat-item:last-child { border-bottom: none; }
.stat-count { font-weight: 600; color: var(--text-secondary); background: rgba(255,255,255,.08); padding: .1rem .5rem; border-radius: 4px; font-size: .8rem; }
.percent-text { color: var(--text-secondary); font-size: .8rem; margin-left: .5rem; }

/* Charts */
.chart-row { display: grid; grid-template-columns: 1fr; gap: 1.5rem; margin-bottom: 2rem; }
.chart-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem; }
.chart-title { font-size: 1.1rem; font-weight: 700; }
.chart-subtitle { font-size: .85rem; font-weight: 400; color: var(--text-secondary); }
.chart-wrap { position: relative; height: 280px; }
.custom-legend { display: flex; gap: 1rem; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: .4rem; font-size: .85rem; font-weight: 600; color: var(--text-secondary); cursor: pointer; user-select: none; transition: opacity .2s; }
.legend-item:hover { color: var(--text-primary); }
.legend-item.hidden { opacity: .35; text-decoration: line-through; }
.legend-color { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend-color.ios { background: #3b82f6; } .legend-color.android { background: #10b981; } .legend-color.other { background: #64748b; }
.analytics-split { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 2rem; }

/* Tables */
.table-container { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 12px; overflow-x: auto; box-shadow: var(--card-shadow); margin-bottom: 1.5rem; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { background: rgba(0,0,0,.2); color: var(--text-secondary); font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; padding: 1rem 1rem; border-bottom: 1px solid var(--border-color); white-space: nowrap; }
td { padding: 1rem; border-bottom: 1px solid var(--border-color); font-size: .95rem; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.log-row:hover { background: var(--row-hover); }
.table-mini { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.table-mini th { text-align: left; padding: .75rem .5rem; font-size: .8rem; text-transform: uppercase; color: var(--text-secondary); border-bottom: 1px solid var(--border-color); background: transparent; }
.table-mini td { padding: .85rem .5rem; font-size: .9rem; border-bottom: 1px solid rgba(255,255,255,.03); }
.table-mini tr:last-child td { border-bottom: none; }
.sub { color: var(--text-secondary); font-size: .8rem; font-family: monospace; }
.muted { color: var(--text-secondary); }
.pos { color: #34d399; font-weight: 600; }

/* Search & forms */
.search-row { display: flex; gap: .75rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.search-input, .form-input, select.form-input {
    width: 100%; padding: .75rem 1rem; background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 8px;
    color: var(--text-primary); font-size: 1rem; outline: none; transition: border-color .2s; font-family: inherit;
}
.search-row .search-input { flex: 1; min-width: 200px; width: auto; }
.search-input:focus, .form-input:focus { border-color: var(--accent-color); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; align-items: end; }
.form-group label { display: block; font-size: .8rem; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .4rem; }
.os-radio { display: flex; gap: 1.2rem; padding: .75rem 0; }
.os-radio label { display: flex; align-items: center; gap: .4rem; text-transform: none; font-size: .95rem; color: var(--text-primary); cursor: pointer; letter-spacing: 0; }

/* Badges */
.ip-badge { font-family: monospace; background: rgba(59,130,246,.15); color: #93c5fd; padding: .2rem .5rem; border-radius: 4px; font-size: .9rem; font-weight: 500; }
.device-badge { background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.1); padding: .25rem .5rem; border-radius: 6px; font-size: .85rem; }
.user-id-badge { font-family: monospace; background: rgba(168,85,247,.15); color: #d8b4fe; padding: .2rem .5rem; border-radius: 4px; font-size: .9rem; font-weight: 600; border: 1px solid rgba(168,85,247,.3); }
.giris-badge { background: rgba(245,158,11,.15); color: #fde047; padding: .2rem .6rem; border-radius: 20px; font-size: .85rem; font-weight: 700; border: 1px solid rgba(245,158,11,.3); display: inline-block; }
.os-badge { padding: .25rem .5rem; border-radius: 6px; font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.os-badge.android { background: rgba(16,185,129,.15); color: #34d399; border: 1px solid rgba(16,185,129,.3); }
.os-badge.ios { background: rgba(59,130,246,.15); color: #60a5fa; border: 1px solid rgba(59,130,246,.3); }
.count-badge { background: rgba(255,255,255,.05); padding: .2rem .5rem; border-radius: 6px; font-size: .85rem; font-weight: 600; border: 1px solid var(--border-color); }
.flag-span { font-size: 1.1rem; margin-right: .4rem; vertical-align: middle; }
.date-span { color: var(--text-secondary); font-size: .85rem; }
.rate-badge { font-weight: 700; padding: .2rem .6rem; border-radius: 20px; font-size: .85rem; background: rgba(16,185,129,.15); color: #34d399; border: 1px solid rgba(16,185,129,.3); }
.rate-badge.low { background: rgba(239,68,68,.12); color: #f87171; border-color: rgba(239,68,68,.3); }
.rate-badge.mid { background: rgba(245,158,11,.15); color: #fcd34d; border-color: rgba(245,158,11,.3); }
.act-btn { background: none; border: none; cursor: pointer; font-size: 1rem; padding: .2rem .4rem; color: var(--text-secondary); font-family: inherit; }
.act-btn:hover { color: #fff; } .act-btn.del:hover { color: #f87171; }
.link-btn { background: none; border: none; color: #60a5fa; cursor: pointer; font-size: .9rem; font-family: inherit; margin-right: .6rem; }
.link-btn.del { color: #f87171; }

/* Visitor card */
.visitor-card { display: flex; flex-direction: column; justify-content: center; gap: .5rem; min-height: 106px; }
.card-row { font-size: .95rem; font-weight: 500; }
.card-row strong { color: var(--accent-success); font-weight: 700; font-size: 1rem; }
.card-row.second-row { color: var(--text-secondary); }
.card-row.second-row strong { color: #fde047; font-family: monospace; }
.log-row.my-ip-row { background: rgba(254,240,138,.08); }
.log-row.my-ip-row td:first-child { border-left: 4px solid #fde047; }
.log-row.my-ip-row td { color: #fef08a; }
.device-row { display: flex; justify-content: space-between; align-items: center; padding: .85rem 0; border-bottom: 1px solid rgba(255,255,255,.03); }
.device-row:last-child { border-bottom: none; }

/* Pagination & info */
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin: 1.5rem 0 2rem; color: var(--text-secondary); font-size: .9rem; }
.pagination button { background: rgba(255,255,255,.05); color: var(--text-primary); border: 1px solid var(--border-color); border-radius: 8px; padding: .5rem 1rem; cursor: pointer; font-family: inherit; }
.pagination button:disabled { opacity: .35; cursor: default; }
.info-box { background: rgba(59,130,246,.07); border: 1px solid rgba(59,130,246,.25); border-radius: 12px; padding: 1.25rem 1.5rem; margin: 2rem 0; font-size: .9rem; color: #cbd5e1; }
.info-box h3 { font-size: 1rem; margin-bottom: .6rem; color: var(--text-primary); }
.info-box p { margin-bottom: .5rem; line-height: 1.6; }
.info-box strong { color: #fff; }
.alert-box { background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.3); border-radius: 12px; padding: 1.25rem 1.5rem; margin-bottom: 1.5rem; }
.alert-box h3 { font-size: 1rem; margin-bottom: .6rem; color: #fcd34d; }
.alert-box li { margin: .35rem 0 .35rem 1.2rem; font-size: .9rem; color: #e2e8f0; }
.empty { text-align: center; color: var(--text-secondary); padding: 2rem; }
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: #0b1220; border: 1px solid var(--border-color); padding: .7rem 1.2rem; border-radius: 10px; font-size: .9rem; z-index: 99; }

/* Login */
.login-wrap { max-width: 400px; margin: 10vh auto 0; }
.login-card { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 16px; padding: 2rem; box-shadow: var(--card-shadow); }
.login-card h2 { text-align: center; font-size: 1.2rem; font-weight: 600; margin-bottom: 1.5rem; color: var(--text-secondary); }
.login-card .form-group { margin-bottom: 1rem; }
.login-card .refresh-btn { width: 100%; justify-content: center; margin-top: .5rem; }
.remember { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--text-secondary); margin: .5rem 0; }
.error-msg { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; border-radius: 8px; padding: .6rem .9rem; font-size: .9rem; margin-bottom: 1rem; display: none; }

@media (max-width: 1024px) { .analytics-split { grid-template-columns: 1fr; } }
@media (max-width: 768px) {
    body { padding: 1rem; }
    header { flex-direction: column; align-items: stretch; text-align: center; }
    .nav-actions { flex-direction: column; width: 100%; }
    .nav-btn, .refresh-btn { width: 100%; text-align: center; justify-content: center; }
    th, td { padding: .75rem 1rem; }
    .stats-grid { grid-template-columns: 1fr; }
}
