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

:root {
    --primary-color: #6C5CE7;
    --primary-hover: #5B4BD5;
    --secondary-color: #A78BFA;
    --success-color: #2ecc71;
    --danger-color: #ff4757;
    --warning-color: #f39c12;
    --text-primary: #1a1a2e;
    --text-secondary: #666;
    --text-muted: #999;
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --border-color: #e0e0e0;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.12);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header .logo {
    margin-bottom: 16px;
}

.login-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 14px;
}

.login-form .form-group {
    margin-bottom: 20px;
}

.login-form label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.login-form input[type="text"],
.login-form input[type="password"] {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 15px;
    transition: border-color 0.3s;
}

.login-form input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.password-input {
    position: relative;
}

.password-input input {
    padding-right: 48px;
}

.password-input input::-ms-reveal,
.password-input input::-ms-clear {
    display: none;
}

.toggle-password {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
}

.toggle-password:hover {
    color: var(--text-secondary);
}

.form-group.remember {
    margin-bottom: 24px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
}

.checkbox-label span {
    font-size: 17px;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
    vertical-align: text-bottom;
}

.login-btn {
    width: 100%;
    padding: 14px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.login-btn:hover {
    background: var(--primary-hover);
}

.error-message {
    margin-top: 16px;
    padding: 12px;
    background: #fff5f5;
    color: var(--danger-color);
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
    display: none;
}

.error-message:not(:empty) {
    display: block;
}

.login-footer {
    margin-top: 32px;
    text-align: center;
}

.login-footer p {
    font-size: 12px;
    color: var(--text-muted);
}

.register-form {
    margin-top: 10px;
}

.register-form .form-group {
    margin-bottom: 8px;
}

.register-form label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.register-form input[type="text"],
.register-form input[type="password"],
.register-form input[type="tel"] {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 15px;
    transition: border-color 0.3s;
}

.register-form input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.password-strength {
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}

.password-strength-bar {
    height: 100%;
    width: 0;
    transition: all 0.3s;
}

.password-strength-bar.weak {
    width: 33%;
    background: #ff4d4f;
}

.password-strength-bar.medium {
    width: 66%;
    background: #faad14;
}

.password-strength-bar.strong {
    width: 100%;
    background: #52c41a;
}

.code-input-group {
    display: flex;
    gap: 10px;
}

.code-input-group input {
    flex: 1;
}

.send-code-btn {
    padding: 10px 20px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.3s;
}

.send-code-btn:hover {
    background: var(--primary-hover);
}

.send-code-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.agreement {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 15px 0;
    font-size: 13px;
    color: #666;
}

.agreement input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 3px;
    accent-color: var(--primary-color);
}

.agreement a {
    color: var(--primary-color);
    text-decoration: none;
}

.register-btn {
    width: 100%;
    padding: 14px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.register-btn:hover {
    background: var(--primary-hover);
}

.register-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.login-link {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: #666;
}

.login-link a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header .logo {
    color: var(--primary-color);
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 10px;
    margin-bottom: 4px;
    transition: all 0.3s;
}

.nav-item:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.nav-item.active {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.user-role {
    font-size: 12px;
    color: var(--text-muted);
}

.logout-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.3s;
}

.logout-btn:hover {
    background: var(--bg-primary);
    color: var(--danger-color);
}

.main-content {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
}

.top-bar {
    background: var(--bg-secondary);
    padding: 20px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 50;
}

.page-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.top-actions {
    display: flex;
    gap: 12px;
}

.refresh-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-primary);
    border: none;
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

.refresh-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.content-area {
    flex: 1;
    padding: 24px 32px;
}

.page-content {
    display: none;
}

.page-content.active {
    display: block;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon.firmware {
    background: rgba(108, 92, 231, 0.1);
    color: var(--primary-color);
}

.stat-icon.device {
    background: rgba(46, 204, 113, 0.1);
    color: var(--success-color);
}

.stat-icon.download {
    background: rgba(243, 156, 18, 0.1);
    color: var(--warning-color);
}

.stat-icon.user {
    background: rgba(167, 139, 250, 0.1);
    color: var(--secondary-color);
}

.stat-info {
    display: flex;
    flex-direction: column;
}

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

.stat-label {
    font-size: 14px;
    color: var(--text-muted);
}

.recent-section {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
}

.recent-section h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.recent-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.recent-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg-primary);
    border-radius: 12px;
}

.recent-item-info {
    display: flex;
    flex-direction: column;
}

.recent-item-version {
    font-weight: 600;
    color: var(--text-primary);
}

.recent-item-device {
    font-size: 13px;
    color: var(--text-muted);
}

.recent-item-time {
    font-size: 13px;
    color: var(--text-muted);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.filter-bar {
    display: flex;
    gap: 12px;
}

.filter-select,
.search-input,
.date-input {
    padding: 10px 16px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    background: var(--bg-secondary);
    transition: border-color 0.3s;
}

.filter-select:focus,
.search-input:focus,
.date-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.search-input {
    width: 240px;
}

.searchable-select {
    position: relative;
    min-width: 200px;
}

.searchable-select-input {
    width: 100%;
    padding: 10px 36px 10px 16px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    background: var(--bg-secondary);
    transition: border-color 0.3s;
    cursor: pointer;
}

.searchable-select-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.searchable-select-arrow {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--text-muted);
    font-size: 12px;
    transition: transform 0.3s;
}

.searchable-select.open .searchable-select-arrow {
    transform: translateY(-50%) rotate(180deg);
}

.searchable-select-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.searchable-select.open .searchable-select-dropdown {
    display: block;
}

.searchable-select-option {
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.searchable-select-option:hover {
    background: var(--bg-primary);
}

.searchable-select-option.selected {
    background: linear-gradient(135deg, #f0f0ff 0%, #e8e8ff 100%);
    color: var(--primary-color);
    font-weight: 500;
}

.searchable-select-option.no-result {
    color: var(--text-muted);
    cursor: default;
}

.searchable-select-option.no-result:hover {
    background: transparent;
}

.primary-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.primary-btn:hover {
    background: var(--primary-hover);
}

.primary-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

.secondary-btn {
    padding: 12px 20px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
}

.secondary-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.export-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.3s;
}

.export-btn:hover {
    background: var(--primary-hover);
}

.table-container {
    background: var(--bg-secondary);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 16px 20px;
    text-align: left;
}

.data-table th {
    background: var(--bg-primary);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table td {
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: var(--bg-primary);
}

.loading-cell {
    text-align: center;
    color: var(--text-muted);
    padding: 40px !important;
}

.version-badge {
    display: inline-block;
    padding: 4px 12px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
}

.checksum-badge {
    display: inline-block;
    padding: 4px 10px;
    background: #e8f4f8;
    color: #0066cc;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    font-family: 'Consolas', 'Monaco', monospace;
}

.role-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
}

.role-badge.admin {
    background: rgba(255, 71, 87, 0.1);
    color: var(--danger-color);
}

.role-badge.operator {
    background: rgba(108, 92, 231, 0.1);
    color: var(--primary-color);
}

.role-badge.viewer {
    background: rgba(153, 153, 153, 0.1);
    color: var(--text-muted);
}

.action-btns {
    display: flex;
    gap: 8px;
}

.action-btn {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s;
}

.action-btn.view {
    background: rgba(108, 92, 231, 0.1);
    color: var(--primary-color);
}

.action-btn.view:hover {
    background: var(--primary-color);
    color: white;
}

.action-btn.download {
    background: rgba(46, 204, 113, 0.1);
    color: var(--success-color);
}

.action-btn.download:hover {
    background: var(--success-color);
    color: white;
}

.action-btn.edit {
    background: rgba(108, 92, 231, 0.1);
    color: var(--primary-color);
}

.action-btn.edit:hover {
    background: var(--primary-color);
    color: white;
}

.action-btn.delete {
    background: rgba(255, 71, 87, 0.1);
    color: var(--danger-color);
}

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

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 24px;
}

.pagination button {
    padding: 8px 16px;
    border: 2px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.pagination button:hover:not(:disabled) {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.pagination button.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 20px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-content.modal-sm {
    max-width: 420px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 20px;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.close-btn:hover {
    color: var(--text-primary);
}

.modal-form {
    padding: 24px;
}

.modal-form .form-group {
    margin-bottom: 20px;
}

.modal-form label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.modal-form .required {
    color: var(--danger-color);
}

.modal-form input[type="text"],
.modal-form input[type="password"],
.modal-form select,
.modal-form textarea {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    transition: border-color 0.3s;
    background: var(--bg-secondary);
}

.modal-form input:focus,
.modal-form select:focus,
.modal-form textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.modal-form textarea {
    resize: vertical;
    min-height: 100px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.file-upload {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
}

.file-upload:hover {
    border-color: var(--primary-color);
    background: rgba(108, 92, 231, 0.02);
}

.file-upload input[type="file"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.file-upload-text {
    color: var(--text-muted);
}

.file-upload-text svg {
    margin-bottom: 12px;
    color: var(--primary-color);
}

.file-upload-text p {
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.file-hint {
    font-size: 12px;
}

.file-selected {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-primary);
}

.remove-file {
    background: none;
    border: none;
    color: var(--danger-color);
    cursor: pointer;
    font-size: 13px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

.upload-progress {
    margin-top: 20px;
}

.progress-bar {
    height: 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border-radius: 4px;
    transition: width 0.3s;
}

.progress-text {
    display: block;
    text-align: center;
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.firmware-detail {
    padding: 24px;
}

.detail-row {
    display: flex;
    margin-bottom: 16px;
}

.detail-label {
    width: 100px;
    font-weight: 500;
    color: var(--text-muted);
}

.detail-value {
    flex: 1;
    color: var(--text-primary);
}

.detail-description {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.detail-description h4 {
    margin-bottom: 12px;
    color: var(--text-secondary);
    font-size: 14px;
}

.detail-description p {
    color: var(--text-primary);
    line-height: 1.8;
    white-space: pre-wrap;
}

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 16px 24px;
    background: var(--text-primary);
    color: white;
    border-radius: 12px;
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    z-index: 2000;
}

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

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

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

.modal-form h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 20px 0 12px;
}

.modal-form h3:first-child {
    margin-top: 0;
}

.modal-form p {
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 12px;
}

.modal-form ul {
    margin: 12px 0;
    padding-left: 20px;
}

.modal-form ul li {
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: 8px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .page-header {
        flex-direction: column;
        gap: 16px;
        align-items: stretch;
    }
    
    .filter-bar {
        flex-wrap: wrap;
    }
    
    .search-input {
        width: 100%;
    }
}