/* Tipografía global */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

body,
.sa-app-body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Modo aplicación cuando se muestra el panel */
.sa-app-body {
    background: #f4f6f9; /* similar a AdminLTE */
}

/* Contenedor principal del panel */
#sa_panel_container {
    margin: 0;
    padding: 0;
    max-width: 100%;
}

.sa-layout {
    display: flex;
    min-height: 100vh;
    background: #f4f6f9;
}

/* Sidebar */
.sa-sidebar {
    width: 240px;
    flex-shrink: 0;
    background: #1e293b;
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
}

.sa-sidebar-header {
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sa-sidebar-brand-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}
.sa-sidebar-icon {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 8px;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.08);
}
.sa-sidebar-brand {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #94a3b8;
    text-transform: uppercase;
}

.sa-sidebar-user {
    display: block;
    margin-top: 6px;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
}

/* Grupos del menú (jerarquía) */
.sa-nav-group {
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.sa-nav-group:last-of-type {
    border-bottom: none;
}
.sa-nav-group-title {
    display: block;
    padding: 6px 18px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #64748b;
}
.sa-nav-item-soon {
    display: block;
    padding: 8px 18px;
    font-size: 0.85rem;
    color: #475569;
    font-style: italic;
}

.sa-sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.sa-sidebar-link {
    display: block;
    padding: 10px 18px;
    font-size: 0.9rem;
    color: #94a3b8;
    text-decoration: none;
    transition: color 0.15s, background 0.15s;
}

.sa-sidebar-link:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.05);
}

.sa-sidebar-link.sa-nav-active {
    color: #fff;
    background: rgba(59, 130, 246, 0.2);
    border-left: 3px solid #3b82f6;
    padding-left: 15px;
}

.sa-sidebar-footer {
    padding: 12px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sa-sidebar-logout {
    color: #94a3b8;
    font-size: 0.85rem;
}

.sa-sidebar-logout:hover {
    color: #f87171;
}

/* Botón hamburguesa (solo móvil) */
.sa-menu-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1002;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: #1e293b;
    color: #fff;
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.sa-menu-toggle:hover {
    background: #334155;
}
.sa-menu-toggle-bar {
    display: block;
    width: 20px;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
}
.sa-layout.sa-menu-open .sa-menu-toggle .sa-menu-toggle-bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.sa-layout.sa-menu-open .sa-menu-toggle .sa-menu-toggle-bar:nth-child(2) {
    opacity: 0;
}
.sa-layout.sa-menu-open .sa-menu-toggle .sa-menu-toggle-bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}
.sa-menu-toggle .sa-menu-toggle-bar {
    transition: transform 0.2s, opacity 0.2s;
    transform-origin: center;
}

/* Overlay del menú móvil */
.sa-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.25s ease;
}

/* Área principal */
.sa-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 8px 0 0 0;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.04);
    padding: 20px 24px 40px;
    margin: 12px 12px 12px 0;
}

.sa-app-footer {
    margin-top: auto;
    padding-top: 20px;
    text-align: center;
    font-size: 0.8rem;
    color: #6b7280;
}
.sa-app-footer a {
    color: #6b7280;
    text-decoration: none;
}
.sa-app-footer a:hover {
    color: #374151;
    text-decoration: underline;
}

.sa-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.sa-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sa-header-inline-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sa-header-link {
    font-size: 0.9rem;
    font-weight: 500;
    color: #2563eb;
    text-decoration: none;
}

.sa-header-link:hover {
    text-decoration: underline;
    color: #1d4ed8;
}

.sa-header-select {
    min-width: 140px;
}

.sa-page-title {
    margin: 0 0 16px;
    font-size: 1.25rem;
    font-weight: 600;
    color: #111827;
}

/* Login: página centrada */
.sa-login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
    overflow-x: hidden;
}

.sa-login-page .sa-login-wrap {
    width: 100%;
    max-width: 400px;
    min-width: 0;
}

.sa-box {
    padding: 40px 36px;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.04);
    box-sizing: border-box;
    overflow: hidden;
}

.sa-box-logo {
    text-align: center;
    margin-bottom: 28px;
    overflow: hidden;
}

.sa-box-logo img {
    width: 64px !important;
    height: 64px !important;
    max-width: 64px !important;
    max-height: 64px !important;
    object-fit: contain;
    border-radius: 12px;
    display: block;
    margin: 0 auto 14px;
    box-sizing: border-box;
}

.sa-box h3 {
    margin: 0 0 6px;
    font-size: 1.35rem;
    font-weight: 700;
    color: #111827;
    letter-spacing: -0.02em;
}

.sa-box-subtitle {
    font-size: 0.9rem;
    color: #6b7280;
    margin-bottom: 26px;
}

.sa-box input {
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 14px;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}

.sa-box input::placeholder {
    color: #9ca3af;
}

.sa-box input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.sa-box button {
    width: 100%;
    padding: 12px 14px;
    margin-top: 6px;
    background: #2563eb;
    color: #ffffff;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s ease, box-shadow 0.2s ease;
}

.sa-box button:hover {
    background: #1d4ed8;
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.35);
}

#sa_error {
    color: #dc2626;
    margin-top: 14px;
    font-size: 0.9rem;
    text-align: center;
}

.sa-install-hint {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
    text-align: center;
}

.sa-install-btn {
    padding: 10px 18px;
    font-size: 0.9rem;
    font-family: inherit;
    color: #2563eb;
    background: transparent;
    border: 1px solid #2563eb;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.sa-install-btn:hover {
    background: #2563eb;
    color: #fff;
}

.sa-ios-hint {
    font-size: 0.85rem;
    color: #6b7280;
    border-top: none;
    padding-top: 8px;
}

.sa-login-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 0.8rem;
    color: #9ca3af;
}

.sa-login-footer a {
    color: #6b7280;
    text-decoration: none;
}

.sa-login-footer a:hover {
    color: #111827;
    text-decoration: underline;
}

/* Utilidades generales */
.sa-section-title {
    margin-top: 8px;
    margin-bottom: 10px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #6c757d;
}

.sa-section-subtitle {
    margin: 0 0 6px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #6b7280;
}

.sa-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    margin-top: 16px;
}

.sa-card {
    cursor: pointer;
    padding: 18px 18px 16px;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    background: #ffffff;
    transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.sa-card h4 {
    margin-top: 0;
    margin-bottom: 4px;
    font-size: 1rem;
    font-weight: 600;
    color: #111827;
}

.sa-card p {
    margin: 0 0 4px;
    font-size: 0.9rem;
    color: #4b5563;
}

.sa-card small {
    font-size: 0.8rem;
    color: #6b7280;
}

.sa-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
    border-color: #cbd5f5;
}

.sa-logout {
    padding:10px 16px;
    background:#dc3545;
    color:#fff;
    border:none;
    border-radius:4px;
    cursor:pointer;
    white-space:nowrap;
}

.sa-logout:hover {
    background:#c82333;
}

.sa-panel-title {
    margin: 0 0 2px;
    font-size: 1.35rem;
    font-weight: 600;
    color: #343a40;
}

.sa-panel-subtitle {
    margin: 0;
    font-size: 0.9rem;
    color: #6b7280;
}

.sa-panel-body {
    margin-top: 6px;
}

.sa-content {
    margin-top: 8px;
}

.sa-breadcrumb {
    font-size: 1.05rem;
    color: #6b7280;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    font-weight: 500;
}

.sa-bc-parent {
    color: #6b7280;
    font-weight: 500;
}

.sa-bc-link {
    background: transparent;
    border: none;
    padding: 0;
    color: #2563eb;
    cursor: pointer;
    font-size: 1.05rem;
    font-weight: 500;
}

.sa-bc-link:hover {
    text-decoration: underline;
}

.sa-bc-current {
    font-weight: 600;
    color: #111827;
}

.sa-bc-sep {
    color: #9ca3af;
}

.sa-est-card {
    border-left: 4px solid #6c757d;
}

.sa-card-actions {
    margin-top: 8px;
}

.sa-link-btn {
    background: transparent;
    border: none;
    padding: 0;
    color: #2563eb;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
}

.sa-link-btn:hover {
    text-decoration: underline;
}

.sa-device-card {
    border-left: 4px solid #17a2b8;
}

.sa-sensor-card {
    border-left: 4px solid #28a745;
}

.sa-sensor-header {
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:16px;
    margin-bottom:10px;
}

.sa-export {
    margin-left: auto;
}

.sa-chart-wrapper {
    margin-top: 10px;
    margin-bottom: 24px;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    background: #ffffff;
    padding: 8px 10px 4px;
    height: 220px; /* altura controlada para la gráfica */
}

.sa-chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

.sa-btn {
    display:inline-flex;
    align-items:center;
    justify-content:center;
    padding:8px 14px;
    border-radius:4px;
    border:none;
    cursor:pointer;
    font-size:0.9rem;
    font-weight:500;
    white-space:nowrap;
    transition:background 0.2s ease, box-shadow 0.2s ease, transform 0.1s ease;
}

.sa-btn-primary {
    background:#2563eb;
    color:#ffffff;
}

.sa-btn-primary:hover {
    background:#1d4ed8;
    box-shadow:0 6px 18px rgba(37,99,235,0.35);
}

/* Tablas */
.sa-table-wrapper {
    margin-top: 10px;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    background: #ffffff;
}

.sa-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.sa-table thead {
    background: #f3f4f6;
}

.sa-table th,
.sa-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.sa-table th {
    font-weight: 600;
    color: #111827;
}

.sa-table-striped tbody tr:nth-child(odd) {
    background: #f9fafb;
}

.sa-table-striped tbody tr:hover {
    background: #e5f0ff;
}

/* Tablas clicables: fila = ficha */
.sa-table-clickable .sa-row-clickable {
    cursor: pointer;
}

.sa-table-clickable .sa-row-clickable:not([data-can-edit="0"]):hover {
    background: #eff6ff !important;
}

.sa-table-clickable .sa-row-clickable[data-can-edit="0"] {
    cursor: default;
}

.sa-cell-main {
    font-weight: 600;
    color: #111827;
}

/* Ficha en modal (solo lectura) */
.sa-ficha p {
    margin: 0 0 10px;
    font-size: 0.95rem;
    color: #374151;
}

.sa-ficha p:last-of-type {
    margin-bottom: 0;
}

.sa-ficha .sa-form-actions {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
}

/* Toolbar y filtros */
.sa-toolbar {
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sa-select {
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    font-size: 0.9rem;
    background: #fff;
    min-width: 160px;
}

.sa-select:focus {
    outline: none;
    border-color: #2563eb;
}

/* Badges */
.sa-badge {
    display: inline-block;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-radius: 6px;
}

.sa-badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.sa-badge-success {
    background: #d1fae5;
    color: #065f46;
}

.sa-badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.sa-form-section {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
}

/* Botón pequeño */
.sa-btn-sm {
    padding: 6px 10px;
    font-size: 0.8rem;
}

.sa-btn-secondary {
    background: #6b7280;
    color: #fff;
}

.sa-btn-secondary:hover {
    background: #4b5563;
}

/* Modales */
.sa-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.sa-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    overflow: auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
    z-index: 1001;
    border: 1px solid #e5e7eb;
}

.sa-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
    border-radius: 12px 12px 0 0;
}

.sa-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #111827;
}

.sa-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    line-height: 1;
    color: #6b7280;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
}

.sa-modal-close:hover {
    color: #111827;
    background: #e5e7eb;
}

.sa-modal-body {
    padding: 20px;
}

.sa-modal-desc {
    margin: 0 0 14px;
    font-size: 0.9rem;
    color: #6b7280;
}

/* Formularios */
.sa-form label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #374151;
}

.sa-form .sa-input {
    width: 100%;
    padding: 9px 12px;
    margin-bottom: 14px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    box-sizing: border-box;
}

.sa-form .sa-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.sa-form textarea.sa-input {
    resize: vertical;
    min-height: 80px;
}

.sa-form-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid #e5e7eb;
}

.sa-msg {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
}

.sa-msg-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.sa-cell-wrap {
    max-width: 280px;
    word-wrap: break-word;
}

/* Responsive: en móvil menú oculto, se abre con hamburguesa */
@media (max-width: 768px) {
    .sa-menu-toggle {
        display: flex;
    }

    .sa-sidebar-overlay {
        display: block;
        pointer-events: none;
        visibility: hidden;
    }
    .sa-layout.sa-menu-open .sa-sidebar-overlay {
        pointer-events: auto;
        opacity: 1;
        visibility: visible;
    }

    .sa-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 85vw;
        z-index: 1001;
        transform: translateX(-100%);
        transition: transform 0.25s ease, box-shadow 0.25s ease;
        box-shadow: none;
    }
    .sa-layout.sa-menu-open .sa-sidebar {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.25);
    }

    .sa-main {
        margin: 0;
        border-radius: 0;
        padding: 16px;
        padding-top: 56px;
        min-height: 100vh;
    }
}

@media (max-width: 640px) {
    .sa-panel-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .sa-sensor-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .sa-header-link {
        margin-top: 4px;
    }

    .sa-modal {
        width: 95%;
        max-height: 85vh;
    }

    .sa-table th,
    .sa-table td {
        padding: 8px 10px;
    }

    /* En móvil mantener tabla en una línea y permitir swipe horizontal */
    .sa-table {
        width: max-content;
        min-width: 100%;
    }
    .sa-table th,
    .sa-table td {
        white-space: nowrap;
    }
}
