:root {
    --bg: #1A1816;
    --bg-card: #232019;
    --bg-card-hover: #2a2620;
    --bg-surface: #1e1c19;
    --fg: #E2DDD9;
    --fg-dim: #9a9590;
    --accent: #C2B2A9;
    --green: #7dba6a;
    --red: #d46a6a;
    --yellow: #d4a94a;
    --blue: #6a9fd4;
    --radius: 10px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--fg);
    min-height: 100vh;
    line-height: 1.5;
}

.hidden { display: none !important; }
.mono { font-family: 'SF Mono', 'Consolas', monospace; font-size: 0.8em; color: var(--fg-dim); }

/* Lucide icon defaults */
.card-icon svg, .empty-icon svg { color: var(--fg-dim); }
.card-icon svg { width: 20px; height: 20px; }
.empty-icon svg { width: 48px; height: 48px; opacity: 0.3; }
.dc-icon { width: 16px; height: 16px; color: var(--accent); vertical-align: -2px; }
.dc-batt-icon { width: 14px; height: 14px; color: var(--fg-dim); flex-shrink: 0; }
.dc-info-icon { width: 12px; height: 12px; vertical-align: -2px; opacity: 0.6; }
.sms-empty-icon { width: 32px; height: 32px; opacity: 0.4; margin-bottom: 0.5rem; }

button svg { width: 14px; height: 14px; vertical-align: -2px; }
.btn-back svg { width: 16px; height: 16px; vertical-align: -3px; }
.modal-close svg { width: 18px; height: 18px; }

@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 1s linear infinite; }

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.2rem 2rem;
    border-bottom: 1px solid #2a2620;
    background: var(--bg-surface);
}

.header-left { display: flex; align-items: baseline; gap: 1rem; }
h1 { font-size: 1.3rem; font-weight: 600; letter-spacing: -0.02em; }
h1:hover { opacity: 0.8; }
.subtitle { font-size: 0.85rem; color: var(--fg-dim); }

#connection-badge {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.4rem 0.9rem; border-radius: 20px;
    background: #1a1a1a; font-size: 0.8rem; font-weight: 500;
}

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-dim); transition: background 0.3s; }
.dot.connected { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.disconnected { background: var(--red); box-shadow: 0 0 6px var(--red); }

/* Main */
main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 2rem; }

/* Baileys section */
.baileys-section {
    background: var(--bg-card);
    border: 1px solid #2a2620;
    border-radius: var(--radius);
    padding: 1.2rem;
    margin-bottom: 1.5rem;
}

.baileys-badge {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.85rem; font-weight: 500;
}

.dot.warning { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }

.baileys-body { margin-top: 1rem; }

.baileys-qr-container {
    display: flex; flex-direction: column; align-items: center;
    gap: 1rem; padding: 1.5rem; margin-bottom: 1rem;
    background: var(--bg-surface); border-radius: var(--radius);
}

.baileys-qr-container img {
    max-width: 280px; width: 100%; border-radius: 8px;
    background: #fff; padding: 12px;
}

.baileys-qr-hint {
    font-size: 0.8rem; color: var(--fg-dim); text-align: center; line-height: 1.5;
}

.baileys-meta {
    font-size: 0.75rem; color: var(--fg-dim);
}

/* Device grid */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.device-card {
    background: var(--bg-card);
    border: 1px solid #2a2620;
    border-radius: var(--radius);
    padding: 1.2rem;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.1s;
}
.device-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.device-card.offline { opacity: 0.5; }

.dc-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.2rem; }
.dc-title { display: flex; align-items: center; gap: 0.5rem; }
.dc-model { font-size: 1rem; font-weight: 600; }
.dc-dot { width: 8px; height: 8px; border-radius: 50%; }
.dc-dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dc-dot.off { background: var(--red); }
.dc-serial { font-size: 0.7rem; color: var(--fg-dim); font-family: monospace; margin-bottom: 0.8rem; padding-left: 1.6rem; }

.dc-battery { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; }
.dc-batt-bar { flex: 1; height: 6px; background: #333; border-radius: 3px; overflow: hidden; }
.dc-batt-fill { height: 100%; border-radius: 3px; transition: width 0.5s; }
.dc-batt-pct { font-size: 0.8rem; font-weight: 600; min-width: 32px; text-align: right; }

.dc-info { display: flex; justify-content: space-between; font-size: 0.8rem; }
.dc-operator { color: var(--accent); font-weight: 500; display: flex; align-items: center; gap: 0.3rem; }
.dc-net { color: var(--fg-dim); }

.empty-state { grid-column: 1 / -1; text-align: center; padding: 4rem 2rem; color: var(--fg-dim); }
.empty-icon { margin-bottom: 1rem; }
.empty-hint { font-size: 0.8rem; margin-top: 0.5rem; opacity: 0.6; }
.device-count { font-size: 0.8rem; color: var(--fg-dim); }

/* Detail actions */
.detail-actions { margin-bottom: 1.5rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Remote control */
.remote-topbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1rem; flex-wrap: wrap; gap: 0.5rem;
}
.remote-controls-top { display: flex; gap: 0.5rem; align-items: center; }
.active-toggle { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.active-toggle:hover { background: var(--fg); }

.remote-phone { display: flex; justify-content: center; margin-bottom: 1rem; }

.remote-screen-container {
    position: relative; background: #000; border-radius: 12px;
    overflow: hidden; max-width: 360px; width: 100%;
    border: 2px solid #2a2620;
}
.remote-screen-container img {
    width: 100%; display: block; cursor: crosshair;
    user-select: none; -webkit-user-drag: none;
}
.remote-loading {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    color: var(--fg-dim); font-size: 0.85rem; text-align: center; padding: 2rem;
    background: #000;
}
.remote-loading.hidden { display: none; }

.remote-nav {
    display: flex; justify-content: center; gap: 1rem; padding: 0.5rem 0;
}
.remote-nav button { min-width: 80px; justify-content: center; }

/* Screenshot modal */
.screenshot-modal-content { max-width: 400px; }
.screenshot-body { display: flex; justify-content: center; align-items: center; min-height: 200px; }
.screenshot-body img { max-width: 100%; border-radius: 6px; }
.screenshot-loading { color: var(--fg-dim); font-size: 0.9rem; display: flex; align-items: center; gap: 0.5rem; }
.modal-header-actions { display: flex; align-items: center; gap: 0.5rem; }
.btn-download {
    color: var(--fg-dim); display: inline-flex; align-items: center; padding: 0.2rem;
    text-decoration: none; transition: color 0.2s;
}
.btn-download:hover { color: var(--fg); }
.btn-download svg { width: 18px; height: 18px; }

/* Back button */
.btn-back {
    background: none; border: none; color: var(--accent);
    font-size: 0.85rem; cursor: pointer; padding: 0.3rem 0;
    margin-bottom: 1rem; display: inline-flex; align-items: center; gap: 0.3rem;
}
.btn-back:hover { color: var(--fg); }

/* Cards */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem; margin-bottom: 2rem;
}

.card {
    background: var(--bg-card); border: 1px solid #2a2620;
    border-radius: var(--radius); padding: 1.2rem; transition: border-color 0.2s;
}
.card:hover { border-color: #3a3630; }
.card-icon { margin-bottom: 0.5rem; }
.card h3 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-dim); margin-bottom: 0.8rem; }
.card-body { display: flex; flex-direction: column; gap: 0.5rem; }

.field { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; }
.field .label { color: var(--fg-dim); }
.accent { color: var(--accent); font-weight: 500; }

/* Battery */
.battery-container { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.5rem; }
.battery-shell {
    width: 100%; max-width: 120px; height: 22px;
    border: 2px solid var(--fg-dim); border-radius: 4px; padding: 2px; position: relative;
}
.battery-shell::after {
    content: ''; position: absolute; right: -6px; top: 4px;
    width: 4px; height: 10px; background: var(--fg-dim); border-radius: 0 2px 2px 0;
}
.battery-fill { height: 100%; border-radius: 2px; transition: width 0.5s, background 0.5s; }
.battery-info { display: flex; flex-direction: column; }
.battery-pct { font-size: 1.2rem; font-weight: 600; line-height: 1; }
.battery-detail { font-size: 0.7rem; color: var(--fg-dim); }

/* Signal bars */
.signal-bars { display: flex; align-items: flex-end; gap: 3px; height: 28px; margin-bottom: 0.5rem; }
.signal-bars .bar { width: 6px; background: #333; border-radius: 2px; transition: background 0.3s; }
.bar-1 { height: 20%; } .bar-2 { height: 40%; } .bar-3 { height: 60%; } .bar-4 { height: 80%; } .bar-5 { height: 100%; }
.bar.active { background: var(--green); }

/* Section headers */
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.section-header h2 { font-size: 1.1rem; font-weight: 600; }
.section-actions { display: flex; align-items: center; gap: 1rem; }
.sms-count { font-size: 0.8rem; color: var(--fg-dim); }

/* Buttons */
button {
    padding: 0.4rem 1rem; background: var(--bg-card); color: var(--accent);
    border: 1px solid #3a3630; border-radius: 6px; cursor: pointer;
    font-size: 0.8rem; font-weight: 500; transition: background 0.2s, border-color 0.2s;
    display: inline-flex; align-items: center; gap: 0.4rem;
}
button:hover { background: var(--bg-card-hover); border-color: var(--accent); }
button:active { transform: scale(0.97); }

/* SMS send */
.sms-send-section { margin-bottom: 1.5rem; }
.sms-send-form {
    background: var(--bg-card); border: 1px solid #2a2620;
    border-radius: var(--radius); padding: 1rem;
}
.sms-send-fields { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 0.8rem; }
.sms-send-fields input, .sms-send-fields textarea {
    background: var(--bg-surface); border: 1px solid #2a2620; border-radius: 6px;
    padding: 0.6rem 0.8rem; color: var(--fg); font-size: 0.85rem; font-family: inherit;
    resize: vertical;
}
.sms-send-fields input::placeholder, .sms-send-fields textarea::placeholder { color: var(--fg-dim); }
.sms-send-fields input:focus, .sms-send-fields textarea:focus { outline: none; border-color: var(--accent); }
.sms-send-actions { display: flex; justify-content: space-between; align-items: center; }
.sms-send-status { font-size: 0.8rem; }
.sms-send-status.success { color: var(--green); }
.sms-send-status.error { color: var(--red); }

/* SMS */
.sms-section { margin-top: 0.5rem; }

#sms-list {
    display: flex; flex-direction: column; gap: 1px;
    background: #2a2620; border-radius: var(--radius); overflow: hidden;
}

.sms-item {
    display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto;
    gap: 0.15rem 1rem; padding: 0.8rem 1rem;
    background: var(--bg-card); cursor: pointer; transition: background 0.15s;
}
.sms-item:hover { background: var(--bg-card-hover); }
.sms-item.unread { border-left: 3px solid var(--accent); }

.sms-sender { font-size: 0.85rem; font-weight: 600; grid-column: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sms-date { font-size: 0.7rem; color: var(--fg-dim); grid-column: 2; grid-row: 1; text-align: right; white-space: nowrap; }
.sms-preview { font-size: 0.8rem; color: var(--fg-dim); grid-column: 1 / -1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sms-empty { padding: 3rem; text-align: center; color: var(--fg-dim); background: var(--bg-card); font-size: 0.9rem; }

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

.modal-content {
    background: var(--bg-card); border: 1px solid #3a3630;
    border-radius: var(--radius); padding: 1.5rem;
    max-width: 500px; width: 90%; max-height: 80vh; overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.3rem; }
.modal-header h3 { font-size: 1rem; color: var(--accent); }
.modal-close { background: none; border: none; color: var(--fg-dim); cursor: pointer; padding: 0.2rem; line-height: 1; }
.modal-close:hover { color: var(--fg); }
.modal-date { font-size: 0.75rem; color: var(--fg-dim); margin-bottom: 1rem; }
.modal-body { font-size: 0.9rem; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }

/* Footer */
footer {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 2rem; border-top: 1px solid #2a2620;
    font-size: 0.75rem; color: var(--fg-dim);
    max-width: 1100px; margin: 2rem auto 0;
}
.auto-refresh { opacity: 0.5; }

@media (max-width: 600px) {
    header { padding: 1rem; }
    main { padding: 1rem; }
    .cards { grid-template-columns: 1fr 1fr; }
    .device-grid { grid-template-columns: 1fr; }
    .section-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    footer { padding: 1rem; }
}
