/* === CSS Variables === */
:root {
    --royal-gold: #B4975A;
    --royal-gold-light: #D4BC84;
    --royal-gold-dark: #8B7340;
    --deep-brown: #5D4B33;
    --deep-brown-light: #7D6B53;
    --light-beige: #F2EBE0;
    --pure-white: #FFFFFF;
    --surface-light: #F8F4EE;
    --success-green: #6B8E23;
    --danger-red: #DC3545;
    --warning-orange: #E8A317;
    --info-blue: #4A90D9;
    --sidebar-bg: #1a1410;
    --sidebar-hover: #2a2018;
    --card-bg: rgba(255,255,255,0.95);
}

/* === Reset & Base === */
* { margin:0; padding:0; box-sizing:border-box; }
body {
    font-family: 'Tajawal', sans-serif;
    background: var(--light-beige);
    color: var(--deep-brown);
    min-height: 100vh;
    direction: rtl;
}

/* === Login Page === */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--deep-brown) 0%, #2a1a0a 50%, #1a1410 100%);
    position: relative;
    overflow: hidden;
}
.login-page::before {
    content: '';
    position: absolute;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 40%, var(--royal-gold) 0%, transparent 40%),
                radial-gradient(circle at 70% 60%, var(--royal-gold-dark) 0%, transparent 30%);
    opacity: 0.06;
    animation: float 20s ease-in-out infinite;
}
@keyframes float {
    0%,100% { transform: translate(0,0) rotate(0deg); }
    50% { transform: translate(-2%,2%) rotate(3deg); }
}
.login-container {
    background: rgba(255,255,255,0.05);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(180,151,90,0.2);
    border-radius: 28px;
    padding: 48px 40px;
    width: 420px;
    max-width: 90vw;
    text-align: center;
    position: relative;
    z-index: 1;
}
.login-logo {
    width: 80px; height: 80px;
    background: linear-gradient(135deg, var(--royal-gold), var(--royal-gold-light));
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 20px;
    box-shadow: 0 8px 32px rgba(180,151,90,0.3);
}
.logo-icon { font-size: 40px; color: var(--deep-brown); }
.login-title {
    font-size: 32px; font-weight: 800;
    color: var(--pure-white);
    margin-bottom: 4px;
}
.login-subtitle {
    color: var(--royal-gold-light);
    font-size: 15px;
    margin-bottom: 32px;
}
.login-form { display: flex; flex-direction: column; gap: 16px; }
.input-group {
    position: relative;
    display: flex;
    align-items: center;
}
.input-icon {
    position: absolute;
    right: 16px;
    color: var(--royal-gold);
    font-size: 20px;
}
.input-group input {
    width: 100%;
    padding: 14px 50px 14px 16px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(180,151,90,0.25);
    border-radius: 14px;
    color: var(--pure-white);
    font-family: 'Tajawal', sans-serif;
    font-size: 15px;
    outline: none;
    transition: all 0.3s;
}
.input-group input::placeholder { color: rgba(255,255,255,0.4); }
.input-group input:focus {
    border-color: var(--royal-gold);
    background: rgba(255,255,255,0.12);
}
.error-msg {
    color: var(--danger-red);
    font-size: 13px;
    background: rgba(220,53,69,0.1);
    padding: 8px 12px;
    border-radius: 8px;
}
.btn-gold {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    background: linear-gradient(135deg, var(--royal-gold), var(--royal-gold-dark));
    color: var(--pure-white);
    border: none;
    border-radius: 14px;
    font-family: 'Tajawal', sans-serif;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(180,151,90,0.3);
}
.btn-gold:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(180,151,90,0.4);
}
.btn-gold:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}
.btn-sm { padding: 8px 18px; font-size: 14px; border-radius: 10px; }
.btn-outline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    background: transparent;
    color: var(--deep-brown-light);
    border: 1px solid var(--light-beige);
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-outline:hover { background: var(--light-beige); }
.btn-danger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(220,53,69,0.1);
    color: var(--danger-red);
    border: none;
    border-radius: 8px;
    font-family: 'Tajawal', sans-serif;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-danger:hover { background: rgba(220,53,69,0.2); }
.btn-success {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(107,142,35,0.1);
    color: var(--success-green);
    border: none;
    border-radius: 8px;
    font-family: 'Tajawal', sans-serif;
    font-size: 13px;
    cursor: pointer;
}

/* === Dashboard Layout === */
.dashboard {
    display: flex;
    min-height: 100vh;
}

/* === Sidebar === */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; right: 0;
    z-index: 100;
    transition: transform 0.3s;
}
.sidebar-header {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(180,151,90,0.15);
}
.sidebar-logo {
    font-size: 28px;
    color: var(--royal-gold);
}
.sidebar-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--pure-white);
}
.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: rgba(255,255,255,0.6);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    border-right: 3px solid transparent;
}
.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--pure-white);
}
.nav-item.active {
    background: rgba(180,151,90,0.12);
    color: var(--royal-gold);
    border-right-color: var(--royal-gold);
}
.nav-item .material-icons-round { font-size: 20px; }
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(180,151,90,0.15);
}
.btn-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    background: rgba(220,53,69,0.1);
    color: var(--danger-red);
    border: none;
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-logout:hover { background: rgba(220,53,69,0.2); }

/* === Main Content === */
.main-content {
    flex: 1;
    margin-right: 260px;
    min-height: 100vh;
}
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 28px;
    background: var(--pure-white);
    border-bottom: 1px solid var(--light-beige);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar h1 { font-size: 22px; font-weight: 700; flex: 1; }
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--deep-brown);
    cursor: pointer;
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.user-name { font-size: 14px; color: var(--deep-brown-light); }
.user-avatar { font-size: 32px; color: var(--royal-gold); }
.content-area { padding: 24px 28px; }

/* === Sections === */
.section { display: none; }
.section.active { display: block; }

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 12px rgba(93,75,51,0.06);
    transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }
.stat-icon {
    width: 52px; height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.stat-icon .material-icons-round { font-size: 26px; color: var(--pure-white); }
.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 28px; font-weight: 800; color: var(--deep-brown); }
.stat-label { font-size: 13px; color: var(--deep-brown-light); }

/* === Cards === */
.card {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(93,75,51,0.06);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--light-beige);
}
.card-header h3 { font-size: 16px; font-weight: 700; }
.card-body { padding: 16px 20px; }
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* === Tables === */
.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    background: var(--surface-light);
    padding: 12px 16px;
    text-align: right;
    font-size: 13px;
    font-weight: 700;
    color: var(--deep-brown);
    white-space: nowrap;
}
.data-table td {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--light-beige);
    white-space: nowrap;
}
.data-table tr:hover td { background: rgba(180,151,90,0.04); }

/* === Badges === */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.badge-success { background: rgba(107,142,35,0.12); color: var(--success-green); }
.badge-danger { background: rgba(220,53,69,0.12); color: var(--danger-red); }
.badge-warning { background: rgba(232,163,23,0.12); color: var(--warning-orange); }
.badge-info { background: rgba(74,144,217,0.12); color: var(--info-blue); }
.badge-neutral { background: var(--light-beige); color: var(--deep-brown-light); }

/* === Section Toolbar === */
.section-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.section-toolbar h2 { font-size: 20px; font-weight: 700; }

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 24px;
    color: var(--deep-brown-light);
    font-size: 14px;
}

/* === Alert Item === */
.alert-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--light-beige);
}
.alert-item:last-child { border-bottom: none; }
.alert-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.alert-text { flex: 1; font-size: 14px; }
.alert-time { font-size: 12px; color: var(--deep-brown-light); }

/* === Modal === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: var(--pure-white);
    border-radius: 20px;
    width: 480px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
}
.modal.modal-wide .modal-content {
    width: 780px;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--light-beige);
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--deep-brown-light);
    cursor: pointer;
}
.modal-body { padding: 24px; }
.modal-footer {
    display: flex;
    justify-content: flex-start;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--light-beige);
}
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--deep-brown);
}
.form-group input, .form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--light-beige);
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus {
    border-color: var(--royal-gold);
}

/* === Searchable Dropdown === */
.searchable-dropdown {
    position: relative;
}
.searchable-dropdown .sd-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--light-beige);
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    cursor: text;
    background: var(--pure-white);
}
.searchable-dropdown .sd-input:focus {
    border-color: var(--royal-gold);
}
.searchable-dropdown .sd-list {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    max-height: 200px;
    overflow-y: auto;
    background: var(--pure-white);
    border: 1px solid var(--light-beige);
    border-radius: 10px;
    margin-top: 4px;
    z-index: 1000;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}
.searchable-dropdown .sd-list.open {
    display: block;
}
.searchable-dropdown .sd-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.searchable-dropdown .sd-item:hover {
    background: var(--surface-light);
}
.searchable-dropdown .sd-item.selected {
    background: var(--light-beige);
    font-weight: 600;
}
.searchable-dropdown .sd-item .sd-role {
    font-size: 11px;
    color: var(--deep-brown-light);
    background: var(--light-beige);
    padding: 2px 8px;
    border-radius: 6px;
}
.searchable-dropdown .sd-empty {
    padding: 12px 14px;
    color: var(--deep-brown-light);
    font-size: 13px;
    text-align: center;
}

/* === Location Picker === */
.location-picker {
    border: 1px solid var(--light-beige);
    border-radius: 12px;
    overflow: hidden;
}
.location-picker .lp-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--surface-light);
}
.location-picker .lp-search {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--light-beige);
    border-radius: 8px;
    font-family: 'Tajawal', sans-serif;
    font-size: 13px;
    outline: none;
    background: var(--pure-white);
}
.location-picker .lp-search:focus {
    border-color: var(--royal-gold);
}
.location-picker .lp-search-results {
    display: none;
    position: absolute;
    right: 12px;
    left: 12px;
    max-height: 160px;
    overflow-y: auto;
    background: var(--pure-white);
    border: 1px solid var(--light-beige);
    border-radius: 8px;
    z-index: 1001;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}
.location-picker .lp-search-results.open {
    display: block;
}
.location-picker .lp-search-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid var(--light-beige);
    transition: background 0.15s;
}
.location-picker .lp-search-item:last-child {
    border-bottom: none;
}
.location-picker .lp-search-item:hover {
    background: var(--surface-light);
}
.location-picker .lp-map {
    height: 200px;
    width: 100%;
}
.location-picker .lp-coords {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--deep-brown-light);
    background: var(--surface-light);
    border-top: 1px solid var(--light-beige);
}
.location-picker .lp-coords code {
    background: var(--light-beige);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
}

/* === Stop Points === */
.stop-points-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}
.stop-point-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--surface-light);
    border-radius: 10px;
    border: 1px solid var(--light-beige);
}
.stop-point-item .sp-number {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--royal-gold);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}
.stop-point-item .sp-info {
    flex: 1;
    font-size: 13px;
}
.stop-point-item .sp-info .sp-name {
    font-weight: 600;
}
.stop-point-item .sp-info .sp-coord {
    font-size: 11px;
    color: var(--deep-brown-light);
}
.stop-point-item .sp-remove {
    background: none;
    border: none;
    color: var(--danger-red);
    cursor: pointer;
    font-size: 18px;
    padding: 2px 6px;
    border-radius: 6px;
    transition: background 0.15s;
}
.stop-point-item .sp-remove:hover {
    background: rgba(220,53,69,0.1);
}
.btn-add-stop {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--surface-light);
    border: 1px dashed var(--royal-gold);
    border-radius: 10px;
    color: var(--royal-gold-dark);
    font-family: 'Tajawal', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    width: 100%;
    justify-content: center;
}
.btn-add-stop:hover {
    background: var(--light-beige);
}

/* === Trip Form Section Divider === */
.form-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--royal-gold-dark);
    margin: 20px 0 10px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--light-beige);
    display: flex;
    align-items: center;
    gap: 6px;
}
.form-section-title .material-icons-round {
    font-size: 18px;
    color: var(--royal-gold);
}

/* === Map === */
#liveMap, .lp-map { border-radius: 12px; overflow: hidden; }
#liveMap .leaflet-container, .lp-map .leaflet-container { border-radius: 12px; }

/* === Responsive === */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-right: 0; }
    .sidebar-toggle { display: block; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .device-control-grid { grid-template-columns: 1fr !important; }
}

/* === Device Control Panel === */
.device-control-panel {
    margin-top: 20px;
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.device-control-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.device-card {
    transition: box-shadow 0.2s;
}
.device-card:hover {
    box-shadow: 0 4px 20px rgba(93,75,51,0.1);
}
.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--light-beige);
}
.control-row:last-child { border-bottom: none; }
.control-row label {
    font-size: 14px;
    font-weight: 600;
    color: var(--deep-brown);
    min-width: 120px;
}
.slider-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    justify-content: flex-end;
}
.device-slider {
    appearance: none;
    -webkit-appearance: none;
    width: 160px;
    height: 6px;
    border-radius: 3px;
    background: var(--light-beige);
    outline: none;
    transition: background 0.2s;
}
.device-slider::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--royal-gold), var(--royal-gold-dark));
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(180,151,90,0.3);
}
.device-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--royal-gold), var(--royal-gold-dark));
    cursor: pointer;
    border: none;
}
.slider-val {
    font-size: 13px;
    font-weight: 700;
    color: var(--royal-gold-dark);
    min-width: 55px;
    text-align: left;
}
.device-select {
    padding: 8px 12px;
    border: 1px solid var(--light-beige);
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-size: 13px;
    background: var(--pure-white);
    color: var(--deep-brown);
    outline: none;
    cursor: pointer;
    min-width: 180px;
}
.device-select:focus { border-color: var(--royal-gold); }
.control-btns {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 14px;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #ccc;
    border-radius: 24px;
    transition: 0.3s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    right: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--success-green);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(-20px);
}
.toggle-switch input:disabled + .toggle-slider {
    opacity: 0.4;
    cursor: not-allowed;
}

/* GPIO Grid */
.gpio-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.gpio-section h4 {
    font-size: 13px;
    font-weight: 700;
    color: var(--deep-brown-light);
    margin-bottom: 12px;
    text-transform: uppercase;
}
.gpio-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--light-beige);
}
.gpio-row:last-child { border-bottom: none; }
.gpio-row span { font-size: 13px; }

/* Antenna Row */
.antenna-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--light-beige);
}
.antenna-row:last-child { border-bottom: none; }
.antenna-label {
    font-size: 14px;
    font-weight: 600;
    min-width: 60px;
}
.antenna-slider {
    width: 120px !important;
}

/* Fingerprint Stats */
.fp-stats {
    display: flex;
    gap: 20px;
    justify-content: center;
}
.fp-stat {
    text-align: center;
    padding: 12px 20px;
    background: var(--surface-light);
    border-radius: 12px;
    min-width: 100px;
}
.fp-stat-value {
    display: block;
    font-size: 28px;
    font-weight: 800;
    color: var(--deep-brown);
}
.fp-stat-label {
    font-size: 12px;
    color: var(--deep-brown-light);
}

/* Online dot animation */
.online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success-green);
    margin-right: 4px;
    animation: pulse-dot 1.5s infinite;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Command Log */
.command-log {
    max-height: 300px;
    overflow-y: auto;
}
.command-log .alert-item {
    padding: 8px 0;
}

/* ==================== SOS OVERLAY ==================== */
#sosOverlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sos-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.75);
}
.sos-card {
    position: relative;
    background: #fff;
    border-radius: 24px;
    padding: 40px 32px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(220,53,69,0.4);
    animation: sos-appear 0.3s ease;
}
@keyframes sos-appear {
    from { transform: scale(0.8); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}
.sos-icon-wrap {
    position: relative;
    width: 96px;
    height: 96px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sos-icon-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: #DC3545;
    animation: sos-pulse 0.7s ease-in-out infinite alternate;
}
@keyframes sos-pulse {
    from { transform: scale(1);    opacity: 0.85; }
    to   { transform: scale(1.15); opacity: 1; }
}
.sos-icon-text {
    position: relative;
    font-size: 48px;
    line-height: 1;
}
.sos-title {
    font-size: 28px;
    font-weight: 800;
    color: #DC3545;
    margin: 0 0 8px;
}
.sos-bus {
    font-size: 20px;
    font-weight: 600;
    color: #3E2723;
    margin: 0 0 8px;
}
.sos-msg {
    font-size: 15px;
    color: #7D6B53;
    margin: 0 0 28px;
}
.sos-btn {
    display: block;
    width: 100%;
    padding: 14px;
    background: #DC3545;
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
}
.sos-btn:hover { background: #b02a37; }

/* ==================== SORTING GATE DASHBOARD ==================== */
.sg-stats-grid {
    grid-template-columns: repeat(4, 1fr);
}
.sg-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--deep-brown);
    font-size: 16px;
    font-weight: 700;
    margin: 24px 0 12px;
}
.sg-section-title .material-icons-round {
    color: var(--royal-gold, #E8A317);
    font-size: 20px;
}

/* Camera Grid */
.sg-camera-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 8px;
}
.sg-camera-card {
    background: #fff;
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 1px 6px rgba(0,0,0,.06);
    border: 1.5px solid transparent;
    transition: border-color .3s, box-shadow .3s;
}
.sg-camera-card.sg-active {
    border-color: #E8A317;
    box-shadow: 0 3px 12px rgba(232,163,23,.18);
}
.sg-camera-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
}
.sg-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #ccc;
    flex-shrink: 0;
}
.sg-dot-active {
    background: #2E7D32;
    animation: pulse-dot 1.2s infinite;
}
.sg-camera-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--deep-brown);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sg-uhf-badge {
    font-size: 14px !important;
    color: #1E88E5;
}
.sg-camera-stats {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}
.sg-mini-stat {
    text-align: center;
}
.sg-val {
    display: block;
    font-size: 18px;
    font-weight: 700;
}
.sg-lbl {
    font-size: 10px;
    color: var(--deep-brown-light, #7D6B53);
}
.sg-entry .sg-val { color: #2E7D32; }
.sg-exit .sg-val { color: #DC3545; }
.sg-inside .sg-val { color: #E8A317; }
.sg-last-seen {
    font-size: 10px;
    color: var(--deep-brown-light, #7D6B53);
}

/* Dual column */
.sg-dual-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 8px;
}
@media (max-width: 900px) {
    .sg-dual-col { grid-template-columns: 1fr; }
    .sg-stats-grid { grid-template-columns: repeat(2, 1fr); }
    .sg-camera-grid { grid-template-columns: repeat(2, 1fr); }
}

/* List container */
.sg-list {
    background: #fff;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 1px 6px rgba(0,0,0,.06);
    max-height: 420px;
    overflow-y: auto;
}
.sg-empty {
    padding: 32px;
    text-align: center;
    color: var(--deep-brown-light, #7D6B53);
    font-size: 14px;
}

/* Transit rows */
.sg-transit-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid #f0ebe3;
}
.sg-transit-row:last-child { border-bottom: none; }
.sg-bus-icon { color: #E8A317; font-size: 22px; }
.sg-transit-info { flex: 1; min-width: 0; }
.sg-epc { font-size: 13px; font-weight: 600; color: var(--deep-brown); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sg-times { font-size: 11px; color: var(--deep-brown-light, #7D6B53); }
.sg-reads { font-size: 10px; color: #aaa; }
.sg-transit-right { text-align: center; flex-shrink: 0; }
.sg-elapsed { font-size: 14px; font-weight: 700; color: #1E88E5; }
.sg-elapsed-lbl { font-size: 9px; color: #1E88E5; }

/* UHF rows */
.sg-uhf-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid #f0ebe3;
    font-size: 13px;
}
.sg-uhf-row:last-child { border-bottom: none; }
.sg-icon-enter { color: #2E7D32; font-size: 18px; }
.sg-icon-exit { color: #DC3545; font-size: 18px; }
.sg-uhf-epc { flex: 1; color: var(--deep-brown); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sg-uhf-rssi { font-size: 11px; color: #aaa; }
.sg-uhf-time { font-size: 11px; color: var(--deep-brown-light, #7D6B53); }

/* Direction badge */
.sg-dir-badge {
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}
.sg-enter { background: rgba(46,125,50,.12); color: #2E7D32; }
.sg-exit  { background: rgba(220,53,69,.12); color: #DC3545; }
