/* ─── CSS Variables & Reset ─────────────────────────────────────────────── */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #222639;
    --bg-card-hover: #2a2f45;
    --bg-input: #181b25;
    --border: #2e3348;
    --text-primary: #e8eaf0;
    --text-secondary: #9ca3b8;
    --text-muted: #6b7280;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.25);
    --online: #22c55e;
    --online-glow: rgba(34, 197, 94, 0.3);
    --offline: #ef4444;
    --offline-glow: rgba(239, 68, 68, 0.3);
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ─── Scrollbar ────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
}

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

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

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

/* ─── Header ──────────────────────────────────────────────────────────── */
.header {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, #1e2235 100%);
    border-bottom: 1px solid var(--border);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    cursor: pointer;
}

.header-brand .logo {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: white;
}

.header-brand h1 {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-hover));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-left: auto;
}

.header-stats {
    display: flex;
    gap: 20px;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--text-muted);
}

.btn-logout {
    padding: 5px 12px;
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    text-decoration: none;
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.25);
}

.header-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.header-stat .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.dot-online {
    background: var(--online);
    box-shadow: 0 0 8px var(--online-glow);
}

.dot-offline {
    background: var(--offline);
    box-shadow: 0 0 8px var(--offline-glow);
}

/* ─── Main Layout ─────────────────────────────────────────────────────── */
.main-layout {
    display: flex;
    height: calc(100vh - 69px);
    position: relative;
}

/* ─── Sidebar (Left Panel) ────────────────────────────────────────────── */
.sidebar {
    width: 300px;
    min-width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s, min-width 0.3s;
    position: relative;
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
    border-right: none;
}

.sidebar.collapsed .sidebar-content,
.sidebar.collapsed .guest-notice,
.sidebar.collapsed .sidebar-accordion {
    display: none;
}

.sidebar-toggle {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 300px;
    width: 20px;
    height: 48px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 6px 6px 0;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    transition: left 0.3s, color 0.2s, background 0.2s;
}

.sidebar-toggle.collapsed {
    left: 0;
    border-left: 1px solid var(--border);
}

.sidebar-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}

.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.sidebar-tab {
    flex: 1;
    padding: 14px 16px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 2px solid transparent;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}

.sidebar-tab:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.02);
}

.sidebar-tab.active {
    color: var(--accent-hover);
    border-bottom-color: var(--accent);
    background: rgba(99, 102, 241, 0.05);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* ─── Sidebar Accordion ──────────────────────────────────────────────── */
.sidebar-accordion {
    border-bottom: 1px solid var(--border);
}

.accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 14px 20px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.accordion-header:hover {
    background: var(--bg-card);
}

.accordion-arrow {
    font-size: 11px;
    color: var(--text-muted);
    transition: transform 0.25s;
}

.sidebar-accordion.open .accordion-arrow {
    transform: rotate(180deg);
}

.accordion-body {
    display: none;
    padding: 0 20px 16px;
}

.sidebar-accordion.open .accordion-body {
    display: block;
}

/* ─── Registration Form ───────────────────────────────────────────────── */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-row {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.form-row .form-group {
    margin-bottom: 0;
}

.form-grow {
    flex: 1;
}

.form-port {
    width: 90px;
    flex-shrink: 0;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
    transition: var(--transition);
    font-family: inherit;
}

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

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    font-family: inherit;
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    color: white;
}

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

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

.btn-danger-sm {
    padding: 4px 10px;
    font-size: 11px;
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    border-radius: 6px;
}

.btn-danger-sm:hover {
    background: var(--danger);
    color: white;
}

/* ─── Robot List (Sidebar) ────────────────────────────────────────────── */
.robot-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    transition: var(--transition);
}

.robot-list-item:hover {
    border-color: var(--accent);
}

.robot-list-info {
    flex: 1;
    min-width: 0;
}

.robot-list-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.robot-list-ip {
    font-size: 12px;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ─── Content Area (Right Panel) ──────────────────────────────────────── */
.content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: var(--bg-primary);
}

.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title .count {
    background: var(--bg-card);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    color: var(--text-muted);
}

.divider {
    height: 1px;
    background: var(--border);
    margin: 24px 0;
}

/* ─── Robot Cards Grid ────────────────────────────────────────────────── */
.robot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.robot-card {
    aspect-ratio: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
}

.robot-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    transition: var(--transition);
}

.robot-card.online::before {
    background: linear-gradient(90deg, var(--online), #4ade80);
}

.robot-card.offline::before {
    background: linear-gradient(90deg, var(--offline), #f87171);
}

.robot-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
    border-color: var(--accent);
    background: var(--bg-card-hover);
}

.robot-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.robot-card-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

.robot-card.online .robot-card-icon {
    background: rgba(34, 197, 94, 0.12);
}

.robot-card.offline .robot-card-icon {
    background: rgba(239, 68, 68, 0.12);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.status-badge.online {
    background: rgba(34, 197, 94, 0.12);
    color: var(--online);
}

.status-badge.offline {
    background: rgba(239, 68, 68, 0.12);
    color: var(--offline);
}

.status-badge .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-badge.online .dot {
    background: var(--online);
    box-shadow: 0 0 6px var(--online-glow);
    animation: pulse 2s infinite;
}

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

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.robot-card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.robot-card-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.robot-card-ip {
    font-size: 12px;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    margin-bottom: 4px;
}

.robot-card-admin {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ─── Empty State ─────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 14px;
}

/* ─── Toast ───────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    z-index: 1000;
    transform: translateY(100px);
    opacity: 0;
    transition: var(--transition);
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    background: var(--online);
    color: white;
}

.toast.error {
    background: var(--danger);
    color: white;
}

/* ─── Detail Page ─────────────────────────────────────────────────────── */
.detail-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 24px;
    transition: var(--transition);
}

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

.detail-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 32px;
}

.detail-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
}

.detail-info h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.detail-meta {
    display: flex;
    gap: 20px;
    font-size: 13px;
    color: var(--text-secondary);
}

.detail-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-top: 24px;
}

.detail-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.detail-card.full-width {
    grid-column: 1 / -1;
}

.detail-card h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 16px;
}

.detail-card .value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.detail-card .label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

#map {
    width: 100%;
    height: 500px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.position-data {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    margin-top: 16px;
}

.position-item {
    background: var(--bg-card);
    padding: 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.position-item .label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.position-item .value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 4px;
}

/* ─── Loading Spinner ─────────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ─── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .main-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: auto;
        max-height: 50vh;
    }

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

    .robot-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

/* ─── Guest Mode ──────────────────────────────────────────────────────── */
.guest-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: rgba(245, 158, 11, 0.12);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.guest-notice {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.25);
    color: #f59e0b;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.5;
    margin-bottom: 4px;
}

.guest-notice small {
    color: #d97706;
    font-size: 11px;
}

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

.app-version {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    align-self: flex-end;
    margin-bottom: 2px;
}

/* ─── Group Toggle ────────────────────────────────────────────────────── */
.group-toggle {
    display: flex;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.group-btn {
    flex: 1;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.group-btn:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.04);
}

.group-btn.active {
    background: var(--accent);
    color: white;
}

.group-toggle-sm {
    margin: 6px 0;
}

.group-toggle-sm .group-btn {
    padding: 6px 10px;
    font-size: 12px;
}

/* ─── Group Badge (in robot list) ────────────────────────────────────── */
.group-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.03em;
    vertical-align: middle;
}

.group-badge-prod {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-hover);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.group-badge-dev {
    background: rgba(245, 158, 11, 0.12);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

/* ─── Robot List Actions ──────────────────────────────────────────────── */
.robot-list-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.robot-list-view {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.robot-list-edit {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 4px;
}

.form-input-sm {
    padding: 7px 10px;
    font-size: 13px;
}

.robot-list-edit-btns {
    display: flex;
    gap: 6px;
}

.btn-edit-sm {
    padding: 4px 10px;
    font-size: 11px;
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent-hover);
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: var(--transition);
}

.btn-edit-sm:hover {
    background: var(--accent);
    color: white;
}

.btn-save-sm {
    flex: 1;
    padding: 6px 10px;
    font-size: 12px;
    background: var(--accent);
    border: none;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: var(--transition);
}

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

.btn-cancel-sm {
    flex: 1;
    padding: 6px 10px;
    font-size: 12px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: var(--transition);
}

.btn-cancel-sm:hover {
    border-color: var(--text-secondary);
    color: var(--text-secondary);
}

/* ─── Group Section (main content) ───────────────────────────────────── */
.group-section {
    margin-bottom: 40px;
}

.group-section-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border);
}

.group-section-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.group-section-stats {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.group-section-stats .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
}