/* ═══════════════════════════════════════════════════════════════
   System Services — Premium Neutral UI
   Mobile-first, monochrome, clean
   ═══════════════════════════════════════════════════════════════ */

:root {
    --bg: #f5f5f5;
    --surface: #ffffff;
    --surface-hover: #fafafa;
    --border: #e5e5e5;
    --border-light: #f0f0f0;
    --text: #171717;
    --text-secondary: #525252;
    --text-muted: #737373;
    --text-light: #a3a3a3;
    --accent: #171717;
    --accent-hover: #262626;
    --accent-subtle: #f5f5f5;
    --success: #22c55e;
    --danger: #ef4444;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.1);
    --transition: 0.15s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.hidden { display: none !important; }
.error { color: var(--danger); margin-top: 8px; font-size: 13px; }
.muted { color: var(--text-muted); font-size: 13px; }

/* ═══════════════════════════════════════════════════════════════
   Auth Screen
   ═══════════════════════════════════════════════════════════════ */

.screen { min-height: 100dvh; }

#auth-screen {
    display: flex;
    align-items: stretch;
    background: var(--bg);
}

.auth-shell {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    min-height: 100dvh;
}

.auth-card {
    background: var(--surface);
    padding: 40px 32px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
}

.auth-logo {
    width: 48px;
    height: 48px;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    margin-bottom: 24px;
    letter-spacing: -0.5px;
}

.auth-card h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: -0.3px;
}

.auth-card .muted {
    margin-bottom: 24px;
}

.auth-card label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.auth-card input {
    display: block;
    width: 100%;
    padding: 10px 14px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition);
    outline: none;
    background: var(--surface);
    color: var(--text);
}

.auth-card input:focus {
    border-color: var(--accent);
}

.auth-card input::placeholder {
    color: var(--text-light);
}

.link {
    display: block;
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-muted);
    text-decoration: none;
    text-align: center;
    transition: color var(--transition);
}

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

/* ═══════════════════════════════════════════════════════════════
   Buttons
   ═══════════════════════════════════════════════════════════════ */

.btn-primary {
    display: block;
    width: 100%;
    padding: 10px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background var(--transition);
    margin-bottom: 8px;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.99); }

.btn-ghost {
    display: block;
    width: 100%;
    padding: 10px 20px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: 8px;
}

.btn-ghost:hover {
    background: var(--accent-subtle);
    color: var(--text);
    border-color: var(--text-light);
}

.btn-ghost-sm {
    padding: 6px 14px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-ghost-sm:hover {
    background: var(--accent-subtle);
    color: var(--text);
    border-color: var(--text-light);
}

.btn-icon {
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    color: var(--text-muted);
    flex-shrink: 0;
}

.btn-icon:hover {
    border-color: var(--text-light);
    color: var(--text);
    background: var(--accent-subtle);
}

.btn-sm-action {
    padding: 7px 14px;
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-sm-action:hover { background: var(--accent-hover); }

.btn-sm-action.outline {
    background: var(--surface);
    color: var(--text-secondary);
    border-color: var(--border);
}

.btn-sm-action.outline:hover {
    background: var(--accent-subtle);
    border-color: var(--text-light);
    color: var(--text);
}

/* ═══════════════════════════════════════════════════════════════
   Header
   ═══════════════════════════════════════════════════════════════ */

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 8px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.brand {
    width: 32px;
    height: 32px;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
    letter-spacing: -0.5px;
}

#device-select {
    padding: 7px 28px 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    outline: none;
    cursor: pointer;
    min-width: 0;
    max-width: 160px;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%23737373' fill='none' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: border-color var(--transition);
}

#device-select:focus { border-color: var(--accent); }

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 4px 8px;
    background: var(--accent-subtle);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.status-dot, .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
}

.status-dot.offline {
    background: var(--text-light);
}

.screen-pill:hover {
    background: var(--border-light);
}

#screen-icon {
    font-size: 8px;
    line-height: 1;
    color: var(--text-light);
}

.header-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════
   Tabs / Navigation
   ═══════════════════════════════════════════════════════════════ */

nav {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

nav::-webkit-scrollbar { display: none; }

.tab {
    padding: 12px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
    white-space: nowrap;
    flex-shrink: 0;
}

.tab:hover { color: var(--text); }

.tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

.tab-content { display: none; padding: 16px; }
.tab-content.active { display: block; }

/* ═══════════════════════════════════════════════════════════════
   Action Bar
   ═══════════════════════════════════════════════════════════════ */

.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.action-bar h3 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.inline-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.inline-group .label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.inline-group select {
    padding: 7px 28px 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%23737373' fill='none' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: border-color var(--transition);
}

.inline-group select:focus { border-color: var(--accent); }

.input-search {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    background: var(--surface);
    color: var(--text);
    transition: border-color var(--transition);
    flex: 1;
    min-width: 120px;
    max-width: 300px;
}

.input-search:focus { border-color: var(--accent); }
.input-search::placeholder { color: var(--text-light); }

.counter {
    font-size: 12px;
    color: var(--text-light);
    white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════
   Map
   ═══════════════════════════════════════════════════════════════ */

.map-container {
    width: 100%;
    height: 50vh;
    min-height: 280px;
    max-height: 500px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    background: var(--accent-subtle);
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-light);
    font-size: 14px;
}

.legend {
    display: flex;
    gap: 20px;
    padding: 10px 14px;
    margin-top: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12px;
    color: var(--text-muted);
    align-items: center;
    flex-wrap: wrap;
}

.legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dot-legend {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.dot-legend.green { background: #22c55e; }
.dot-legend.red { background: #ef4444; }

.line-legend {
    width: 20px;
    height: 3px;
    background: #4f46e5;
    display: inline-block;
    border-radius: 2px;
}

/* ═══════════════════════════════════════════════════════════════
   Panel / Tables
   ═══════════════════════════════════════════════════════════════ */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.panel-title {
    font-size: 14px;
    font-weight: 600;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    letter-spacing: -0.2px;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 500px;
}

thead { background: var(--accent-subtle); }

th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

td {
    padding: 10px 14px;
    font-size: 13px;
    border-top: 1px solid var(--border-light);
    color: var(--text);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

tr.expandable { cursor: pointer; }
tr.expandable:hover td { background: var(--accent-subtle); }

tr.expanded td {
    white-space: normal;
    word-break: break-word;
    max-width: none;
}

tr:hover td { background: var(--surface-hover); }

.no-data {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
    font-size: 14px;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-incoming { background: #f0f9ff; color: #0369a1; }
.badge-outgoing { background: #fffbeb; color: #92400e; }
.badge-unknown { background: var(--accent-subtle); color: var(--text-muted); }
.badge-count { background: var(--accent-subtle); color: var(--text-secondary); }
.badge-missed { background: #fef2f2; color: #991b1b; }
.badge-rejected { background: #fef2f2; color: #991b1b; }
.badge-ambient { background: #f0fdf4; color: #166534; }

audio {
    height: 32px;
    width: 160px;
}

/* ═══════════════════════════════════════════════════════════════
   Pagination
   ═══════════════════════════════════════════════════════════════ */

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-top: 1px solid var(--border-light);
    font-size: 12px;
    color: var(--text-light);
    gap: 8px;
    flex-wrap: wrap;
}

.page-buttons {
    display: flex;
    gap: 4px;
}

.page-btn {
    padding: 5px 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    color: var(--text-muted);
    transition: all var(--transition);
}

.page-btn:hover {
    background: var(--accent-subtle);
    color: var(--text);
}

.page-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.page-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════════
   Commands
   ═══════════════════════════════════════════════════════════════ */

.cmd-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.cmd-card {
    padding: 18px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
    text-align: center;
}

.cmd-card:hover {
    border-color: var(--text-light);
    box-shadow: var(--shadow-sm);
}

.cmd-card:active {
    transform: scale(0.98);
}

.cmd-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.listen-card {
    cursor: default;
}

.listen-controls {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.listen-controls select {
    padding: 6px 24px 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%23737373' fill='none' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
}

#cmd-log-list {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
}

#cmd-log-list li {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    font-size: 12px;
    color: var(--text-muted);
    font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
}

#cmd-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-light);
    font-size: 13px;
}

/* ═══════════════════════════════════════════════════════════════
   Modals
   ═══════════════════════════════════════════════════════════════ */

.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-bg {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.modal-card {
    position: relative;
    background: var(--surface);
    padding: 28px 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 380px;
}

.modal-card h3 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: -0.2px;
}

.modal-card .muted {
    margin-bottom: 20px;
}

.modal-card input {
    display: block;
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    margin-bottom: 12px;
    background: var(--surface);
    color: var(--text);
    transition: border-color var(--transition);
}

.modal-card input:focus { border-color: var(--accent); }
.modal-card input::placeholder { color: var(--text-light); }

.modal-btns {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

.modal-btns button {
    width: auto;
    display: inline-flex;
    padding: 9px 20px;
    margin-bottom: 0;
}

/* ═══════════════════════════════════════════════════════════════
   Responsive — Mobile-first already, enhance for larger screens
   ═══════════════════════════════════════════════════════════════ */

/* Small mobile adjustments */
@media (max-width: 480px) {
    .auth-card {
        padding: 28px 20px;
    }

    header {
        flex-wrap: wrap;
    }

    .header-actions {
        width: 100%;
        justify-content: flex-end;
        padding-top: 8px;
        border-top: 1px solid var(--border-light);
    }

    .status-pill {
        display: none;
    }

    .action-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .input-search {
        max-width: 100%;
    }

    .cmd-grid {
        grid-template-columns: 1fr;
    }

    td { padding: 8px 10px; font-size: 12px; }
    th { padding: 8px 10px; font-size: 10px; }

    .pagination {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }
}

/* Tablet and up */
@media (min-width: 640px) {
    header { padding: 14px 24px; }
    .tab-content { padding: 20px 24px; }
    nav { padding: 0 24px; }

    .map-container {
        height: 55vh;
        max-height: 550px;
    }

    .input-search {
        max-width: 260px;
    }
}

/* Desktop */
@media (min-width: 1024px) {
    header { padding: 14px 32px; }
    .tab-content { padding: 24px 32px; }
    nav { padding: 0 32px; }

    .map-container {
        height: 60vh;
        max-height: 600px;
    }

    td { max-width: 300px; }
}
