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

:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-card-hover: #222633;
    --bg-input: #12141c;
    --border: #2a2e3d;
    --border-focus: #6c63ff;
    --text: #e4e4e7;
    --text-muted: #8b8fa3;
    --text-dim: #5c6078;
    --primary: #6c63ff;
    --primary-hover: #7b73ff;
    --primary-glow: rgba(108, 99, 255, 0.15);
    --green: #22c55e;
    --green-bg: rgba(34, 197, 94, 0.12);
    --green-border: rgba(34, 197, 94, 0.25);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.12);
    --red-border: rgba(239, 68, 68, 0.25);
    --orange: #f59e0b;
    --orange-bg: rgba(245, 158, 11, 0.12);
    --blue: #3b82f6;
    --blue-bg: rgba(59, 130, 246, 0.12);
    --radius: 10px;
    --radius-lg: 14px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.4);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ===== Navbar ===== */
.navbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 28px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

.nav-brand {
    color: var(--text);
    text-decoration: none;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-brand::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--primary);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-user {
    font-size: 13px;
    color: var(--text-muted);
    padding: 6px 12px;
    background: var(--bg);
    border-radius: 20px;
    font-weight: 500;
    margin-right: 6px;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.nav-link:hover {
    color: var(--text);
    background: rgba(255,255,255,0.06);
}

/* ===== Container ===== */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 32px 28px;
}

/* ===== Typography ===== */
h1 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 20px;
    color: var(--text);
}

h2 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    background: var(--primary);
    color: white;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    letter-spacing: 0.2px;
}

.btn:hover {
    background: var(--primary-hover);
    box-shadow: 0 0 20px var(--primary-glow);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

.btn-danger {
    background: var(--red);
}

.btn-danger:hover {
    background: #dc2626;
    box-shadow: 0 0 20px var(--red-bg);
}

.btn-success,
.btn-start {
    background: var(--green);
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius);
}

.btn-start:hover,
.btn-success:hover {
    background: #16a34a;
    box-shadow: 0 0 20px var(--green-bg);
}

.btn-stop {
    background: var(--red);
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius);
}

.btn-stop:hover {
    background: #dc2626;
    box-shadow: 0 0 20px var(--red-bg);
}

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

.btn-ghost:hover {
    background: rgba(255,255,255,0.04);
    color: var(--text);
    border-color: var(--text-muted);
    box-shadow: none;
}

.btn-login {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 0.3px;
}

.btn-login:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 24px var(--primary-glow);
    transform: translateY(-1px);
}

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 16px;
    border: 1px solid;
}

.alert-error {
    background: var(--red-bg);
    color: #fca5a5;
    border-color: var(--red-border);
}

.alert-success {
    background: var(--green-bg);
    color: #86efac;
    border-color: var(--green-border);
}

/* ===== Login Page ===== */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 60px);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.login-card h2 {
    margin-bottom: 24px;
    font-size: 24px;
    text-align: center;
    font-weight: 700;
    letter-spacing: -0.5px;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    letter-spacing: 0.2px;
}

.form-group input {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text);
    transition: all var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-group input::placeholder {
    color: var(--text-dim);
}

/* ===== Token Display ===== */
.token-display {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    overflow-x: auto;
}

.token-display code {
    color: var(--primary);
    font-size: 13px;
    word-break: break-all;
    white-space: pre-wrap;
    font-weight: 500;
}

/* ===== Package Tags ===== */
.package-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.package-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 5px 10px 5px 14px;
    font-size: 12px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    transition: all var(--transition);
}

.package-tag:hover {
    border-color: var(--text-dim);
}

.package-tag-name {
    color: var(--text);
}

.package-tag-delete {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.package-tag-delete:hover {
    background: var(--red);
    color: white;
}

/* ===== Device Grid ===== */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.device-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: all var(--transition);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.device-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), transparent);
    opacity: 0;
    transition: opacity var(--transition);
}

.device-card:hover {
    border-color: var(--primary);
    background: var(--bg-card-hover);
    box-shadow: 0 0 30px var(--primary-glow);
    transform: translateY(-2px);
}

.device-card:hover::before {
    opacity: 1;
}

.device-icon {
    font-size: 28px;
    filter: grayscale(0.3);
}

.device-info h3 {
    font-size: 14px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    word-break: break-all;
    margin-bottom: 6px;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
}

.device-stats {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-muted);
}

.device-stats span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.device-targets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.device-registered {
    font-size: 11px;
    color: var(--text-dim);
}

/* ===== Config Panel ===== */
.config-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
}

.config-panel h3 {
    font-size: 13px;
    margin-bottom: 10px;
    color: var(--text-muted);
}

.config-form {
    display: flex;
    gap: 10px;
}

.config-form input[type="text"] {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 13px;
    color: var(--text);
    transition: all var(--transition);
}

.config-form input[type="text"]:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.config-form input[type="text"]::placeholder {
    color: var(--text-dim);
}

/* ===== Controls Bar ===== */
.controls {
    display: flex;
    gap: 16px;
    align-items: center;
    margin-bottom: 20px;
    padding: 12px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    flex-wrap: wrap;
}

.controls label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}

.controls select {
    padding: 6px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
}

.controls select:focus {
    outline: none;
    border-color: var(--border-focus);
}

.controls button {
    padding: 7px 18px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all var(--transition);
}

.controls button:hover {
    background: var(--primary-hover);
}

/* ===== Tables ===== */
.sessions-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.sessions-table th,
.sessions-table td {
    padding: 13px 18px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.sessions-table th {
    background: rgba(255,255,255,0.02);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
}

.sessions-table tr:last-child td {
    border-bottom: none;
}

.sessions-table tbody tr {
    transition: background var(--transition);
}

.sessions-table tbody tr:hover {
    background: rgba(255,255,255,0.03);
}

.sessions-table td {
    font-size: 13px;
}

.package-name {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.badge.active {
    background: var(--green-bg);
    color: var(--green);
    border: 1px solid var(--green-border);
}

.badge.active::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--green);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.badge-off {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid var(--red-border);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-dim);
    background: var(--bg-card);
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
}

.empty-state p {
    margin-bottom: 6px;
}

.empty-state p:first-child {
    font-size: 15px;
    color: var(--text-muted);
    font-weight: 500;
}

/* ===== Session Detail ===== */
.session-header {
    margin-bottom: 28px;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
    transition: color var(--transition);
}

.back-link:hover {
    color: var(--primary);
}

.session-meta {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    font-size: 14px;
    color: var(--text-muted);
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 12px;
    align-items: center;
}

.session-meta strong {
    color: var(--text-dim);
    font-weight: 500;
}

/* ===== Event Cards ===== */
.event-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.event-meta {
    padding: 12px 16px;
    display: flex;
    gap: 12px;
    align-items: center;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.event-type {
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.event-type.touch {
    background: var(--orange-bg);
    color: var(--orange);
}

.event-type.periodic {
    background: var(--blue-bg);
    color: var(--blue);
}

.event-time {
    color: var(--text-dim);
    font-size: 12px;
}

.event-coords {
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--text-muted);
    font-size: 12px;
}

/* ===== Screenshot Grid ===== */
.screenshot-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

@media (max-width: 1000px) {
    .screenshot-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
    .screenshot-grid { grid-template-columns: 1fr; }
    .device-grid { grid-template-columns: 1fr; }
    .navbar { padding: 0 16px; }
    .container { padding: 20px 16px; }
}

.grid-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: all var(--transition);
}

.grid-card:hover {
    border-color: var(--primary);
    box-shadow: 0 0 20px var(--primary-glow);
}

.grid-meta {
    padding: 10px 12px;
    display: flex;
    gap: 8px;
    align-items: center;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    flex-wrap: wrap;
}

.grid-screenshot {
    width: 100%;
    display: block;
    cursor: pointer;
    transition: all var(--transition);
}

.grid-screenshot:hover {
    opacity: 0.85;
    filter: brightness(1.05);
}

.grid-no-screenshot {
    padding: 48px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
}

/* ===== Lightbox ===== */
.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.92);
    backdrop-filter: blur(8px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    cursor: zoom-out;
}

.lightbox.active {
    display: flex;
}

.lightbox img {
    max-width: 95vw;
    max-height: 95vh;
    border-radius: var(--radius);
    box-shadow: 0 0 60px rgba(0,0,0,0.6);
}

/* ===== Utility ===== */
.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 16px; }
.mb-lg { margin-bottom: 24px; }
.gap-sm { gap: 8px; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* ===== Selection ===== */
::selection {
    background: var(--primary);
    color: white;
}

/* ===== Page subtitle ===== */
.page-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: -12px;
    margin-bottom: 24px;
}

/* ===== Status dot inline ===== */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
}

.status-dot.on {
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
}

.status-dot.off {
    background: var(--red);
    box-shadow: 0 0 8px var(--red);
}

/* ===== Divider ===== */
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* ===== Action row ===== */
.action-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* ===== Inline form ===== */
.inline-form {
    display: inline;
    margin: 0;
}
