/* ===== CSS Variables ===== */
:root {
    --primary: var(--theme-color, #7c3aed);
    --primary-light: color-mix(in srgb, var(--primary) 80%, white);
    --primary-alpha: color-mix(in srgb, var(--primary) 12%, transparent);
    --app-bg: #f8fafc;
    --surface-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --hover-bg: #f1f5f9;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.1);
    --font-size-base: 14px;
    /* Gradient button reference colors */
    --teal-primary: #2EADA9;
    --teal-dark: #238F8B;
    --accent-orange: #FF6B35;
    --accent-orange-dark: #E55A2B;
    --success-green: #52C41A;
    --success-green-dark: #3DA814;
    --error-red: #FF4D4F;
    --error-red-dark: #D9363E;
}

html.dark {
    --app-bg: #0f172a;
    --surface-bg: #1e293b;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --hover-bg: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.3);
}

/* ===== Global Dark Mode Override ===== */
html.dark body {
    background: var(--app-bg);
    color: var(--text-primary);
}

/* Syncfusion Dark Adaptation */
html.dark .e-grid,
html.dark .e-grid .e-gridheader,
html.dark .e-grid .e-headercell,
html.dark .e-grid .e-rowcell,
html.dark .e-grid .e-gridcontent,
html.dark .e-grid .e-table {
    background-color: var(--surface-bg) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

html.dark .e-grid .e-row:hover .e-rowcell {
    background-color: var(--hover-bg) !important;
}

html.dark .e-dialog,
html.dark .e-dlg-content,
html.dark .e-footer-content,
html.dark .e-dlg-header-content {
    background-color: var(--surface-bg) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

html.dark .e-input,
html.dark .e-textbox,
html.dark .e-input-group,
html.dark .e-input-group .e-input,
html.dark .e-ddl,
html.dark .e-dropdownlist,
html.dark .e-input-group.e-control-wrapper,
html.dark .e-numeric,
html.dark .e-numerictextbox {
    background-color: var(--app-bg) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

html.dark .e-popup,
html.dark .e-list-parent,
html.dark .e-dropdownbase .e-list-item {
    background-color: var(--surface-bg) !important;
    color: var(--text-primary) !important;
}

html.dark .e-dropdownbase .e-list-item:hover,
html.dark .e-dropdownbase .e-list-item.e-active {
    background-color: var(--hover-bg) !important;
}

html.dark .e-pager {
    background-color: var(--surface-bg) !important;
    color: var(--text-secondary) !important;
    border-color: var(--border-color) !important;
}

/* ===== App Layout ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--app-bg);
    color: var(--text-primary);
    transition: background 0.3s, color 0.3s;
    font-size: var(--font-size-base);
}

.app-container {
    display: flex;
    min-height: 100vh;
    background: var(--app-bg);
}

/* ===== Sidebar ===== */
.sidebar {
    width: 240px;
    background: var(--surface-bg);
    color: var(--text-primary);
    height: 100vh;
    position: fixed;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--border-color);
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--primary);
}

.sidebar-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    display: block;
}

/* ===== Navigation Menu ===== */
.nav-menu {
    padding: 12px 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.nav-group {
    margin-top: 16px;
}

.nav-group-title {
    padding: 8px 20px 4px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 1px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: var(--hover-bg);
    color: var(--primary);
}

.nav-item.active {
    background: var(--primary-alpha);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 500;
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.nav-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-fixed-bottom {
    margin-top: auto;
    padding-bottom: 12px;
}

.nav-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 20px;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-left: 240px;
    min-width: 0;
    overflow: hidden;
}

/* ===== Top Bar ===== */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--surface-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    color: var(--text-primary);
}

.top-bar .top-left {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.top-bar .top-left span {
    color: var(--text-secondary) !important;
}

.top-right {
    display: flex;
    align-items: center;
    gap: 16px;
    color: var(--text-primary);
}

.top-bar-logo {
    font-weight: 700;
    font-size: 16px;
    color: var(--primary) !important;
}

.top-bar-divider {
    color: var(--border-color);
    margin: 0 4px;
}

.top-bar-page {
    font-size: 14px;
    color: var(--text-secondary) !important;
}

.top-bar-datetime {
    font-size: 13px;
    color: var(--text-secondary);
}

.top-bar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.logout-btn {
    background: #ef4444;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.logout-btn:hover {
    background: #dc2626;
}

/* ===== Tab Bar ===== */
.tab-bar-wrapper {
    display: flex;
    align-items: center;
    background: var(--surface-bg);
    border-bottom: 1px solid var(--border-color);
    min-height: 38px;
}

.tab-scroll-btn {
    flex-shrink: 0;
    width: 28px;
    height: 38px;
    border: none;
    background: var(--surface-bg);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    padding: 0;
}

.tab-scroll-btn:hover {
    background: var(--hover-bg);
    color: var(--primary);
}

.tab-bar {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    gap: 2px;
    min-height: 38px;
    padding: 0 4px;
    scrollbar-width: none;
}

.tab-bar::-webkit-scrollbar {
    height: 0;
}

.tab-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: all 0.15s;
    user-select: none;
    text-decoration: none;
}

.tab-item:hover {
    color: var(--text-primary);
    background: var(--hover-bg);
}

.tab-item.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 500;
}

.tab-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    font-size: 11px;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    border: none;
    background: none;
    padding: 0;
}

.tab-close:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

/* ===== Content Area ===== */
.content-area {
    padding: 20px;
    overflow-y: auto;
    height: calc(100vh - 110px);
    background: var(--app-bg);
}

/* ===== Login Card ===== */
.login-card {
    background: var(--surface-bg);
    padding: 40px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 400px;
    max-width: 90vw;
    margin: 0 auto;
    margin-top: 10vh;
    color: var(--text-primary);
}

.login-card h2 {
    margin: 0 0 8px;
    font-size: 24px;
    text-align: center;
    color: var(--text-primary);
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* ===== Form Styling ===== */
.form-group {
    margin-bottom: 16px;
    flex: 1;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input,
.form-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.2s;
    background: var(--surface-bg);
    color: var(--text-primary);
}

.form-input:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-alpha);
}

.login-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    margin-top: 8px;
    transition: background 0.2s;
}

.login-btn:hover {
    filter: brightness(0.9);
}

.login-btn:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

.error-message {
    background: #fef2f2;
    color: #dc2626;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
    text-align: center;
}

/* Password toggle */
.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-wrapper .form-input {
    padding-right: 40px;
}

.password-toggle {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.password-toggle:hover {
    opacity: 1;
}

/* Remember password */
.remember-row {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    margin-top: -4px;
}

.remember-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
}

.remember-label input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--primary);
}

html.dark .error-message {
    background: rgba(220,38,38,0.15);
}

.success-message {
    background: #f0fdf4;
    color: #16a34a;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
    text-align: center;
}

html.dark .success-message {
    background: rgba(22,163,106,0.15);
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ===== Dialog Form ===== */
.dialog-form {
    padding: 8px 0;
}

.dialog-form .form-group {
    margin-bottom: 14px;
}

.dialog-form .form-group label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-row .form-group {
    flex: 1;
    min-width: 0;
}

/* ===== Pager Bar ===== */
.pager-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
    padding: 8px 0;
}

.page-info {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0 8px;
}

/* ===== Toast Notifications ===== */
.toast {
    position: fixed;
    top: 24px;
    right: 24px;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: white;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: toast-in 0.3s ease;
}

.toast-success { background: #22c55e; }
.toast-danger { background: #ef4444; }
.toast-warning { background: #f59e0b; }
.toast-info { background: var(--primary); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Badge Styling ===== */
.e-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.e-badge-success {
    background: #dcfce7;
    color: #16a34a;
}

.e-badge-warning {
    background: #fef3c7;
    color: #d97706;
}

.e-badge-danger {
    background: #fee2e2;
    color: #dc2626;
}

.e-badge-info {
    background: #dbeafe;
    color: #2563eb;
}

html.dark .e-badge-success { background: rgba(22,163,106,0.2); }
html.dark .e-badge-warning { background: rgba(217,119,6,0.2); }
html.dark .e-badge-danger { background: rgba(220,38,38,0.2); }
html.dark .e-badge-info { background: rgba(37,99,235,0.2); }

/* Grid action button spacing */
.e-grid .e-rowcell .e-btn {
    margin-right: 4px;
}

.e-grid .e-rowcell .e-btn:last-child {
    margin-right: 0;
}

/* ===== Settings Page ===== */
.settings-container {
    max-width: 800px;
}

.settings-section {
    background: var(--surface-bg);
    border-radius: 10px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.settings-section h4 {
    margin: 0 0 16px;
    font-size: 16px;
    color: var(--text-primary);
}

.settings-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.settings-item:last-child {
    border-bottom: none;
}

.settings-label {
    color: var(--text-secondary);
    font-size: 14px;
}

.settings-value {
    color: var(--text-primary);
    font-weight: 500;
    font-size: 14px;
}

/* ===== Theme Settings ===== */
.settings-theme-container {
    max-width: 700px;
}

.theme-section {
    background: var(--surface-bg);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.theme-card {
    flex: 1;
    padding: 16px;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    border: 2px solid var(--border-color);
    background: var(--surface-bg);
    transition: all 0.2s;
}

.theme-card:hover {
    border-color: var(--primary);
}

.theme-card.selected {
    border-color: var(--primary);
    background: var(--primary-alpha);
}

.color-swatch {
    width: 80px;
    height: 60px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.color-swatch:hover {
    transform: scale(1.05);
}

.color-swatch.selected {
    border-color: white;
    box-shadow: 0 0 0 2px var(--primary);
}

/* ===== Placeholder Page ===== */
.placeholder-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    background: var(--surface-bg);
    border-radius: 8px;
    margin-top: 10px;
    color: var(--text-primary);
}

/* ===== Loading Spinner ===== */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    font-size: 18px;
    color: var(--text-secondary);
}

/* ===== Info Card (Device Detail) ===== */
.detail-card {
    background: var(--surface-bg);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.detail-card h4 {
    margin-top: 0;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.detail-item {
    font-size: 13px;
}

.detail-item .detail-label {
    color: var(--text-secondary);
    font-size: 12px;
    display: block;
    margin-bottom: 2px;
}

.detail-item .detail-value {
    color: var(--text-primary);
    font-weight: 500;
}

/* ===== Checkbox styling ===== */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* ===== Upload area ===== */
.upload-area {
    grid-column: span 2;
}

.upload-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.upload-status {
    font-size: 12px;
    margin-top: 4px;
}

.upload-status.uploading {
    color: var(--primary);
}

.upload-status.success {
    color: var(--success-green);
}

.upload-status.error {
    color: var(--error-red);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }

    .sidebar-header h3,
    .sidebar-sub,
    .nav-group-title,
    .nav-label,
    .nav-divider {
        display: none;
    }

    .nav-item {
        justify-content: center;
        padding: 12px;
    }

    .nav-icon {
        font-size: 20px;
    }

    .main-content {
        margin-left: 60px;
    }

    .form-row {
        flex-direction: column;
    }
}
