:root {
    --primary: #d4a017;
    /* Predial Scan Yellow/Gold */
    --primary-dark: #b8860b;
    --secondary: #3e2723;
    /* Dark Brown */
    --bg-light: #f8f9fa;
    --bg-dark: #121212;
    --text-main: #333;
    --text-muted: #666;
    --white: #ffffff;
    --error: #d32f2f;
    --success: #388e3c;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-light);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Views */
.view {
    display: none;
    min-height: 100vh;
}

.view.active {
    display: flex;
}

/* Login View */
#login-view {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--secondary) 0%, #1a0f0d 100%);
    padding: 20px;
}

.login-card {
    background: var(--white);
    padding: 40px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
    text-align: center;
}

.logo {
    width: 150px;
    margin-bottom: 40px;
}

h1 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--secondary);
}

header p {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 30px;
}

/* Forms */
.form-group {
    text-align: left;
    margin-bottom: 20px;
}

label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-main);
}

input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Buttons */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--secondary);
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: none;
    box-shadow: 0 4px 15px rgba(212, 160, 23, 0.3);
    position: relative;
    overflow: hidden;
}

.btn-primary:active {
    background: var(--primary-dark);
}

.btn-text {
    background: transparent;
    border: 1.5px solid transparent;
    color: var(--primary-dark);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-text:hover {
    color: var(--primary);
}

.error-msg {
    color: var(--error);
    font-size: 13px;
    margin-top: 15px;
}

/* Dashboard Layout */
#dashboard-view {
    flex-direction: row;
    height: 100vh;
    overflow: hidden;
}

#sidebar {
    width: 280px;
    background: linear-gradient(180deg, #4e342e 0%, #2c1e1c 100%);
    color: var(--white);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.sidebar-logo {
    padding: 40px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-img {
    max-width: 140px;
    height: auto;
}

.sidebar-nav {
    flex-grow: 1;
    padding: 20px 0;
    overflow-y: auto;
}

#nav-links {
    list-style: none;
}

#nav-links li {
    margin-bottom: 4px;
    padding: 0 15px;
}

#nav-links a {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.3s ease;
    gap: 12px;
}

#nav-links a span {
    font-size: 18px;
    opacity: 1;
}

#nav-links a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--primary);
    transform: translateX(5px);
}

#nav-links li.active a {
    background: var(--primary);
    color: var(--secondary);
    font-weight: 700;
}

#nav-links li.active a span {
    filter: brightness(0.2);
}

.sidebar-footer {
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.user-info {
    margin-bottom: 15px;
}

.user-details {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#user-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-logout {
    width: 100%;
    padding: 12px;
    background: rgba(211, 47, 47, 0.08);
    color: #ff5252;
    border: 1.5px solid rgba(211, 47, 47, 0.2);
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-logout:hover {
    background: #d32f2f;
    color: white;
}

.btn-full {
    width: 100% !important;
}

#content {
    flex-grow: 1;
    padding: 30px;
    background-color: var(--bg-light);
    height: 100vh;
    overflow-y: auto;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

#view-title {
    flex-grow: 1;
    font-size: 20px;
    font-weight: 700;
    color: var(--secondary);
    margin: 0;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    #dashboard-view {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        height: auto;
    }

    .sidebar-logo {
        padding: 15px;
    }

    .sidebar-img {
        max-width: 100px;
    }

    .sidebar-nav {
        display: none;
        /* Can be toggled with JS */
    }

    .sidebar-nav.active {
        display: block;
    }

    .sidebar-footer {
        padding: 10px 15px;
    }
}

/* Table Design */
.panel {
    background: var(--white);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 12px;
    border-bottom: 2px solid #eee;
    color: var(--text-muted);
    font-size: 13px;
    text-transform: uppercase;
}

td {
    padding: 12px;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}

.badge {
    padding: 4px 8px;
    background: var(--primary);
    color: var(--white);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
}

/* Grids and Layouts */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.full-width {
    grid-column: span 2;
}

.separator {
    display: flex;
    align-items: center;
    margin: 25px 0 15px;
    color: var(--primary);
    font-weight: 600;
    font-size: 14px;
    grid-column: span 2;
}

.separator::after {
    content: "";
    flex: 1;
    height: 1px;
    background: #eee;
    margin-left: 15px;
}

.form-tip {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: -10px;
}

/* Sensor Configuration */
.sensor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

/* Botão Deslizante (Switch) */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #f44336;
    /* Vermelho (OFF) */
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: #4CAF50;
    /* Verde (ON) */
}

input:focus+.slider {
    box-shadow: 0 0 1px #4CAF50;
}

input:checked+.slider:before {
    transform: translateX(24px);
}

.sensor-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    padding: 12px 15px;
    border: 1px solid #eee;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    transition: all 0.2s;
}

.sensor-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.sensor-item label {
    margin-bottom: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--secondary);
    cursor: pointer;
}

@media (max-width: 600px) {

    .form-grid,
    .sensor-grid {
        grid-template-columns: 1fr;
    }

    .full-width,
    .separator {
        grid-column: span 1;
    }
}

/* Telemetry Dashboard */
.telemetria-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-top: 20px;
}

.device-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    border-top: 4px solid var(--primary);
    transition: transform 0.2s;
}

.device-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.device-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--secondary);
    display: block;
}

.device-last-reading {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.sensor-values {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
}

.sensor-card {
    padding: 16px;
    border-radius: 8px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 80px;
}

.sensor-label {
    font-size: 13px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 600;
}

.sensor-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--secondary);
}


.dashboard-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.pulse {
    background: #e6fffa;
    color: #047857;
}

@keyframes blink {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }

    100% {
        opacity: 1;
    }
}

.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #e6f4ea;
    color: #1e8e3e;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.5px;
    animation: blink 2s infinite ease-in-out;
}

@media (max-width: 600px) {
    .telemetria-grid {
        grid-template-columns: 1fr;
    }

    .sensor-values {
        grid-template-columns: 1fr;
    }
}