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

:root {
    --bg:       #0f1117;
    --surface:  #1a1d27;
    --border:   #2a2d3a;
    --accent:   #7c6af7;
    --green:    #3ecf8e;
    --red:      #f87171;
    --yellow:   #fbbf24;
    --text:     #e2e8f0;
    --muted:    #64748b;
    --radius:   10px;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 2rem;
}

header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

header h1 { font-size: 1.5rem; font-weight: 700; }
header .subtitle { color: var(--muted); font-size: 0.9rem; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-green  { background: #0d3320; color: var(--green); }
.badge-red    { background: #2d1515; color: var(--red); }
.badge-yellow { background: #2d2010; color: var(--yellow); }

/* ── Grid of tracker cards ── */
.tracker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.1s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }

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

.card-title { font-weight: 600; font-size: 1rem; }
.card-region { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }

.card-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.stat-box {
    background: var(--bg);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
}
.stat-box .label { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-box .value { font-size: 1.25rem; font-weight: 700; margin-top: 2px; }

/* ── Dashboard layout ── */
.dashboard-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.back-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    text-decoration: none;
}
.back-btn:hover { border-color: var(--accent); }

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

@media (max-width: 900px) {
    .dashboard-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    body { padding: 1rem; }
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.panel-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 1rem;
}

/* ── Live visitors table ── */
.live-panel { grid-column: 1 / -1; }

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
    text-align: left;
    color: var(--muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0 0 0.6rem;
    border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody td { padding: 0.65rem 0; vertical-align: middle; }

.avatar-cell { display: flex; align-items: center; gap: 0.6rem; }
.avatar-img  { width: 28px; height: 28px; border-radius: 50%; background: var(--border); }

/* ── Peak hours chart ── */
.bar-chart { display: flex; align-items: flex-end; gap: 3px; height: 80px; padding-top: 2.5rem; margin-top: -2.5rem; overflow: visible; margin-bottom: 1.2rem; position: relative; }
.bar-wrap  { display: flex; flex-direction: column; align-items: center; flex: 1; min-width: 12px; flex-shrink: 0; }
.bar {
    width: 100%;
    background: var(--accent);
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transition: height 0.3s;
    opacity: 0.8;
}
.bar:hover { opacity: 1; }
.bar-label {
    font-size: 0.55rem;
    color: var(--muted);
    position: absolute;
    bottom: -1.1rem;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
}

/* ── Activity feed ── */
.feed { display: flex; flex-direction: column; gap: 0.5rem; max-height: 320px; overflow-y: auto; }
.feed-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.82rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
}
.feed-item:last-child { border-bottom: none; }
.feed-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.feed-time { color: var(--muted); font-size: 0.72rem; margin-left: auto; white-space: nowrap; }

/* ── Daily summaries ── */
.summary-table td:not(:first-child) { text-align: right; }

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.5rem;
    box-shadow: 0 25px 60px rgba(0,0,0,0.5);
    animation: modalIn 0.18s ease;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.25rem;
}

.modal-title  { font-size: 1.2rem; font-weight: 700; }
.modal-region { color: var(--muted); font-size: 0.82rem; margin-top: 3px; }

.modal-close {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
    width: 28px; height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.modal-close:hover { border-color: var(--red); color: var(--red); }

.modal-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.modal-stat {
    background: var(--bg);
    border-radius: 8px;
    padding: 0.65rem 0.85rem;
    text-align: center;
}
.modal-stat .label { color: var(--muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; }
.modal-stat .value { font-size: 1.4rem; font-weight: 700; margin-top: 2px; }

.modal-section-title {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 0.75rem;
}

/* Visitor rows inside modal */
.visitor-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
}
.visitor-row:last-child { border-bottom: none; }

.visitor-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--border);
    object-fit: cover;
    flex-shrink: 0;
}

.visitor-info { flex: 1; min-width: 0; }
.visitor-name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.visitor-username { color: var(--muted); font-size: 0.76rem; margin-top: 1px; }

.visitor-badges { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

.dwell-badge {
    background: #0d3320;
    color: var(--green);
    border-radius: 99px;
    padding: 2px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.visit-badge {
    background: #1a1630;
    color: var(--accent);
    border-radius: 99px;
    padding: 2px 10px;
    font-size: 0.72rem;
    white-space: nowrap;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
    padding: 1.5rem 0;
}

.modal-footer {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.5rem 1.1rem;
    border-radius: 7px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.85; }

a.visitor-row {
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
    border-radius: 6px;
    margin: 0 -0.25rem;
    padding-left: 0.25rem;
    padding-right: 0.25rem;
}
a.visitor-row:hover {
    background: rgba(124, 106, 247, 0.08);
    border-bottom-color: var(--border);
}
a.visitor-row:last-child { border-bottom: none; }


/* ── Modal divider ──────────────────────────────────────────── */
.modal-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.1rem 0;
}

.modal-section-sub {
    font-size: 0.65rem;
    color: var(--muted);
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
    margin-left: 4px;
}

/* ── Modal peak hours bar chart ──────────────────────────────── */
.modal-bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 54px;
    margin-bottom: 1.2rem;
    padding-top: 2.5rem;
    margin-top: -2.5rem;
    overflow: visible;
    position: relative;
}
.modal-bar-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    min-width: 12px;
    flex-shrink: 0;
    cursor: default;
}
.modal-bar {
    width: 100%;
    background: var(--accent);
    border-radius: 2px 2px 0 0;
    min-height: 2px;
    opacity: 0.75;
    transition: opacity 0.15s;
}
.modal-bar:hover { opacity: 1; }
.modal-bar-label {
    font-size: 0.5rem;
    color: var(--muted);
    position: absolute;
    bottom: -1rem;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    line-height: 1;
}

/* ── Modal two-column layout (top visitors + feed) ──────────── */
.modal-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    align-items: start;
}
@media (max-width: 520px) {
    .modal-two-col { grid-template-columns: 1fr; }
}

/* ── Top visitors list ───────────────────────────────────────── */
.modal-top-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.2rem;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
    border-radius: 4px;
    transition: background 0.15s;
}
.modal-top-row:last-child { border-bottom: none; }
.modal-top-row:hover { background: rgba(124,106,247,0.08); }

.modal-top-rank {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--muted);
    width: 14px;
    text-align: center;
    flex-shrink: 0;
}
.modal-top-avatar {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--border);
    object-fit: cover;
    flex-shrink: 0;
}
.modal-top-info { flex: 1; min-width: 0; }
.modal-top-name {
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.modal-top-user { font-size: 0.7rem; color: var(--muted); }

/* ── Modal activity feed ─────────────────────────────────────── */
.modal-feed {
    display: flex;
    flex-direction: column;
    max-height: 220px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.modal-feed-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border);
}
.modal-feed-item:last-child { border-bottom: none; }
.modal-feed-name {
    flex: 1;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.modal-feed-action {
    font-weight: 400;
    color: var(--muted);
    margin-left: 3px;
}
.modal-feed-time {
    color: var(--muted);
    font-size: 0.68rem;
    white-space: nowrap;
    margin-left: auto;
    flex-shrink: 0;
}

/* ── Owner gate ───────────────────────────────────────────── */
#owner-gate {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gate-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.gate-card h2  { font-size: 1.4rem; font-weight: 700; }
.gate-card p   { color: var(--muted); font-size: 0.9rem; }

.gate-card input {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: monospace;
    font-size: 0.9rem;
    padding: 0.6rem 0.85rem;
    width: 100%;
    outline: none;
}
.gate-card input:focus { border-color: var(--accent); }

.gate-card button {
    background: var(--accent);
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.65rem;
    width: 100%;
    transition: opacity 0.15s;
}
.gate-card button:hover { opacity: 0.88; }

.gate-error {
    color: var(--red);
    font-size: 0.82rem;
    min-height: 1rem;
}

/* ── Gate secondary link-button (e.g. "Forgot PIN?") ──────── */
.gate-link {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.84rem;
    padding: 0;
    text-align: center;
    text-decoration: underline;
    transition: color 0.15s;
    width: auto;
}
.gate-link:hover { color: var(--text); opacity: 1; }

/* ── PIN digit boxes ──────────────────────────────────────── */
.pin-inputs {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
}

.pin-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    height: 56px;
    text-align: center;
    width: 52px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    /* override the generic gate-card input width */
    padding: 0;
}
.pin-box:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(124, 106, 247, 0.25);
}
.pin-box:not(:placeholder-shown) {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Peak hours bar tooltip ─────────────────────────── */
.bar-wrap,
.modal-bar-wrap {
    position: relative;
}

.bar-tooltip {
    display: none;
    position: fixed;
    background: #1e2433;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.4;
    padding: 5px 8px;
    text-align: center;
    white-space: nowrap;
    z-index: 9999;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    transform: translateX(-50%);
}

/* Arrow */
.bar-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--border);
}

/* Tooltip show/hide handled by JS (position:fixed escapes overflow clipping) */

/* ── Peak hours: mobile min-width for tappable bars ──────── */
@media (max-width: 600px) {
    .bar-wrap       { min-width: 28px; }
    .modal-bar-wrap { min-width: 20px; }
}

/* ── Migrate button on tracker card ────────────────────── */
.migrate-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.72rem;
    padding: 2px 8px;
    transition: border-color 0.15s, color 0.15s;
    white-space: nowrap;
}
.migrate-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Sort bar ─────────────────────────────────────────────── */
.sort-bar {
    display:     flex;
    align-items: center;
    gap:         0.4rem;
    margin-bottom: 1rem;
    flex-wrap:   wrap;
}

.sort-label {
    font-size:  0.78rem;
    color:      var(--muted);
    margin-right: 0.15rem;
}

.sort-btn {
    background:    var(--surface);
    border:        1px solid var(--border);
    color:         var(--muted);
    border-radius: 6px;
    padding:       0.28rem 0.6rem;
    font-size:     0.78rem;
    cursor:        pointer;
    transition:    color 0.15s, border-color 0.15s;
    font-family:   inherit;
    white-space:   nowrap;
}

.sort-btn:hover {
    color:        var(--text);
    border-color: var(--text);
}

.sort-btn.sort-active {
    color:        var(--accent);
    border-color: var(--accent);
}

.sort-arrow {
    font-size: 0.7rem;
}
.tracker-search {
    flex:          1;
    min-width:     160px;
    max-width:     260px;
    background:    var(--surface);
    border:        1px solid var(--border);
    color:         var(--text);
    border-radius: 6px;
    padding:       0.28rem 0.65rem;
    font-size:     0.82rem;
    font-family:   inherit;
    outline:       none;
    transition:    border-color 0.15s;
}

.tracker-search::placeholder { color: var(--muted); }

.tracker-search:focus { border-color: var(--accent); }

.public-pill {
    border: 0;
    border-radius: 999px;
    padding: 0.1rem 0.5rem;
    font-size: 0.7rem;
    cursor: pointer;
    background: #111827;
    color: #9ca3af;
}

.is-public-card .public-pill,
.public-pill[data-public="1"] {
    background: rgba(46,204,113,0.12);
    color: #34d399;
}

/* ── Modal tabs (Live / History) ───────────────────────────── */
.modal-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.9rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.4rem;
}

.modal-tab {
    background: transparent;
    border: none;
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    color: var(--muted);
    cursor: pointer;
    border-radius: 999px;
    transition: background 0.15s, color 0.15s;
}

.modal-tab:hover {
    color: var(--text);
    background: rgba(148, 163, 184, 0.08);
}

.modal-tab-active {
    color: #fff;
    background: rgba(124, 106, 247, 0.25);
}

/* Hide peak-hours chart on narrow screens */
@media (max-width: 640px) {
    .modal-peak-wrapper {
        display: none;
    }
}

/* ── Daily overview accordion ───────────────────────────────── */
.day-row {
    border-bottom: 1px solid var(--border);
}
.day-row:last-child { border-bottom: none; }

.day-row-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 0.25rem;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
    gap: 0.5rem;
}
.day-row-summary:hover { background: rgba(124,106,247,0.07); }

.day-row-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.day-chevron {
    font-size: 0.6rem;
    color: var(--muted);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.day-row-date {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.day-row-pills {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
}

.day-row-detail {
    padding: 0.25rem 0 0.5rem 1.1rem;
}

.day-visit-row {
    padding: 0.35rem 0.25rem;
}
.day-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  overflow: hidden;
  transition: border-color 0.15s;
}

.day-card-open {
  border-color: var(--accent);
}

.day-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  cursor: pointer;
  background: var(--surface);
  user-select: none;
}

.day-card-header:hover {
  background: var(--surface-hover, var(--border));
}

.day-card-left {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.day-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.day-card-date {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}


.day-card-pills {
  display: flex;
  gap: 0.4rem;
}

.day-card-chevron {
  font-size: 1.1rem;
  color: var(--muted);
  line-height: 1;
  transition: color 0.15s;
}

.day-card-open .day-card-chevron {
  color: var(--accent);
}

.day-card-body {
  padding: 0 0.5rem;
  background: var(--bg);
}

.day-card-body .modal-top-row:last-child {
  border-bottom: none;
}
