:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --bg-card-hover: #334155;
    --bg-input: #0f172a;
    --border: #334155;
    --border-focus: #3b82f6;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4);
    --transition: 0.2s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* HEADER */

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 64px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.header-logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
    filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.3));
}

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

.ws-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
}

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

.ws-connected .ws-dot {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
    animation: pulse 2s infinite;
}

.ws-disconnected .ws-dot {
    background: var(--text-muted);
}

.ws-connected .ws-label { color: var(--success); }
.ws-disconnected .ws-label { color: var(--text-muted); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* MAIN */

main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px;
}

.view { display: none; }
.view.active { display: block; }

/* SECTION HEADER */

.section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.section-header h2 {
    font-size: 24px;
    font-weight: 600;
}

.registro-meta {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* BADGES */

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

.badge-info { background: rgba(59, 130, 246, 0.15); color: var(--accent); }
.badge-pending { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge-active { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.badge-blocked { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* DEVICES GRID */

.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.device-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: all var(--transition);
    cursor: default;
}

.device-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent);
    box-shadow: var(--shadow-lg);
}

.device-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.device-card-header h3 {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

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

.online-dot.offline {
    background: var(--text-muted);
}

.device-card-id {
    font-size: 12px;
    color: var(--text-muted);
    font-family: monospace;
    margin-bottom: 12px;
    word-break: break-all;
    overflow-wrap: break-word;
}

.device-card-info {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.device-card-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.detail-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.detail-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.detail-value {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0.5;
    transition: opacity var(--transition);
}

.btn-icon:hover {
    opacity: 1;
}

.device-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* BUTTONS */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

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

.btn-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}
.btn-success:hover { background: rgba(16, 185, 129, 0.25); }

.btn-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.3);
}
.btn-warning:hover { background: rgba(245, 158, 11, 0.25); }

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

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

/* FORM */

.registro-form {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.form-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 24px;
}

@media (max-width: 900px) {
    .form-layout {
        grid-template-columns: 1fr;
    }
}

.form-uploads {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.upload-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.upload-card > label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.upload-hint {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    padding: 4px 0;
}

.upload-error {
    font-size: 12px;
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius);
    padding: 8px 12px;
    text-align: center;
}

.foto-preview, .pdf-preview {
    width: 100%;
    aspect-ratio: 3/4;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    overflow: hidden;
    background: var(--bg-input);
    position: relative;
}

.foto-preview:hover, .pdf-preview:hover {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.05);
}

.foto-preview span, .pdf-preview span {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 16px;
}

.foto-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pdf-preview.has-file {
    border-color: var(--success);
}

.pdf-preview.has-file span {
    color: var(--success);
}

.file-input {
    display: none;
}

/* FIELDS */

.field-group {
    margin-bottom: 24px;
}

.field-group h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.fields-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (max-width: 600px) {
    .fields-grid {
        grid-template-columns: 1fr;
    }
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field.full {
    grid-column: 1 / -1;
}

.field label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.field input, .field select {
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    transition: border-color var(--transition);
}

.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

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

.field select {
    cursor: pointer;
}

.field select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* MODELO SWITCH */

.modelo-switch-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
}

.modelo-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    transition: color var(--transition);
}

.modelo-label.active {
    color: var(--accent);
    font-weight: 600;
}

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 26px;
    transition: background var(--transition);
}

.switch-slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    bottom: 3px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform var(--transition);
}

.switch input:checked + .switch-slider {
    background: var(--accent);
}

.switch input:checked + .switch-slider::before {
    transform: translateX(22px);
}

/* FORM ACTIONS */

.form-actions {
    display: flex;
    gap: 12px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

/* CATEGORIAS TABLE */

.categorias-table-wrapper {
    overflow-x: auto;
}

.categorias-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.categorias-table th,
.categorias-table td {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: left;
}

.categorias-table th {
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.categorias-table td:first-child {
    font-weight: 600;
    color: var(--accent);
    width: 80px;
    white-space: nowrap;
}

.categorias-table td input[type="date"] {
    width: 100%;
    padding: 6px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    transition: border-color var(--transition);
}

.categorias-table td input[type="date"]:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.categorias-table tr:hover {
    background: rgba(59, 130, 246, 0.03);
}

/* EMPTY STATE */

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 24px;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-state span {
    font-size: 13px;
}

/* TOAST */

.toast-container {
    position: fixed;
    top: 80px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 380px;
}

.toast {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 4.7s forwards;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.toast-info {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.toast-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.toast-error {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* TEXT UTILITIES */

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

/* 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);
}

/* LOGIN */

.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

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

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

.login-logo {
    margin-bottom: 20px;
}

.login-logo img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    filter: drop-shadow(0 0 20px rgba(59, 130, 246, 0.4));
    animation: logoGlow 3s ease-in-out infinite;
}

@keyframes logoGlow {
    0%, 100% { filter: drop-shadow(0 0 20px rgba(59, 130, 246, 0.4)); }
    50% { filter: drop-shadow(0 0 30px rgba(59, 130, 246, 0.6)); }
}

.login-header h1 {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #60a5fa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

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

.login-container .field {
    margin-bottom: 16px;
}

.login-container .field input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    transition: border-color var(--transition);
}

.login-container .field input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.login-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
    text-align: center;
}

.btn-full {
    width: 100%;
    padding: 12px;
    font-size: 15px;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}
