/* ===== Reset & Base Styles ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4CAF50;
    --secondary-color: #2196F3;
    --danger-color: #f44336;
    --warning-color: #ff9800;
    --success-color: #4CAF50;
    --dark-bg: #1a1a2e;
    --sidebar-bg: #16213e;
    --card-bg: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --border-color: #e0e0e0;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    color: var(--text-primary);
    line-height: 1.6;
}

/* ===== Container Layout ===== */
.container {
    display: flex;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: white;
    padding: 20px;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.logo i {
    font-size: 32px;
    color: var(--primary-color);
}

.logo h2 {
    font-size: 24px;
}

.nav-menu {
    list-style: none;
}

.nav-menu li {
    margin-bottom: 10px;
}

.nav-menu a {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 15px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.3s;
}

.nav-menu a:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.nav-menu li.active a {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.nav-menu i {
    font-size: 18px;
    width: 20px;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-left: 250px;
    padding: 20px 40px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.header h1 {
    font-size: 32px;
    color: var(--text-primary);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
}

.user-info i {
    font-size: 32px;
    color: var(--primary-color);
}

/* ===== Welcome Section ===== */
.welcome-section {
    margin-bottom: 30px;
}

.welcome-card {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 40px;
    border-radius: 15px;
    box-shadow: var(--shadow);
}

.welcome-card h2 {
    font-size: 28px;
    margin-bottom: 10px;
}

.welcome-card p {
    font-size: 16px;
    margin-bottom: 20px;
    opacity: 0.9;
}

/* ===== Buttons ===== */
.btn-primary, .btn-secondary, .btn-danger, .btn-control {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

.btn-primary:hover {
    background: #45a049;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #1976D2;
}

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

.btn-danger:hover {
    background: #da190b;
}

/* ===== Statistics Cards ===== */
.stats-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: transform 0.3s;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: white;
}

.stat-icon.good {
    background: var(--success-color);
}

.stat-icon.bad {
    background: var(--danger-color);
}

.stat-icon.time {
    background: var(--secondary-color);
}

.stat-icon.alerts {
    background: var(--warning-color);
}

.stat-info h3 {
    font-size: 28px;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.stat-info p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ===== Info Section ===== */
.info-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.info-card {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.info-card h3 {
    margin-bottom: 15px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.info-card ul {
    list-style: none;
    padding-left: 0;
}

.info-card li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.info-card li:before {
    content: "✓";
    color: var(--primary-color);
    font-weight: bold;
}

/* ===== Activity Section ===== */
.activity-section {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.activity-section h2 {
    margin-bottom: 20px;
}

.activity-list {
    max-height: 300px;
    overflow-y: auto;
}

.no-data {
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
}

/* ===== Modal ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
    margin-bottom: 10px;
}

.modal-content p {
    margin-bottom: 20px;
    color: var(--text-secondary);
}

.input-field {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 20px;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ===== Video Section ===== */
.video-section {
    margin-bottom: 30px;
}

.video-container {
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow);
}

.video-feed {
    width: 100%;
    height: auto;
    display: block;
}

.video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
}

.video-overlay i {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.video-overlay.hidden {
    display: none;
}

/* ===== Calibration Overlay ===== */
.calibration-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.calibration-overlay.hidden {
    display: none;
}

.calibration-content {
    text-align: center;
    color: white;
    padding: 40px;
    max-width: 600px;
}

.countdown-container {
    margin-bottom: 30px;
}

.countdown-text {
    font-size: 24px;
    margin-bottom: 30px;
    font-weight: 600;
}

.countdown-number {
    font-size: 120px;
    font-weight: bold;
    color: var(--primary-color);
    animation: pulse 1s ease-in-out;
    text-shadow: 0 0 30px rgba(76, 175, 80, 0.5);
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.8;
    }
}

.calibration-result {
    margin-top: 30px;
}

.calibration-success,
.calibration-error {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 30px;
    backdrop-filter: blur(10px);
}

.calibration-success h3 {
    color: var(--success-color);
    margin-bottom: 20px;
    font-size: 28px;
}

.calibration-values {
    margin: 20px 0;
    text-align: left;
}

.calib-value {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    margin: 10px 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.calib-value .label {
    font-weight: 500;
    color: rgba(255, 255, 255, 0.8);
}

.calib-value .value {
    font-size: 24px;
    font-weight: bold;
    color: var(--primary-color);
}

.info-text {
    margin: 20px 0;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    line-height: 1.6;
}

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

.calibration-result .btn-primary {
    margin-top: 20px;
    padding: 12px 40px;
    font-size: 16px;
}


/* ===== Controls ===== */
.controls {
    display: flex;
    gap: 15px;
    margin-top: 20px;
    justify-content: center;
}

.btn-control {
    flex: 1;
    max-width: 200px;
}

.btn-start {
    background: var(--success-color);
    color: white;
}

.btn-stop {
    background: var(--danger-color);
    color: white;
}

.btn-calibrate {
    background: var(--secondary-color);
    color: white;
}

.btn-control:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== Status Panel ===== */
.status-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.status-card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.status-card h3 {
    margin-bottom: 15px;
    font-size: 16px;
    color: var(--text-secondary);
}

.posture-status {
    text-align: center;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 15px 25px;
    border-radius: 25px;
    font-size: 18px;
    font-weight: bold;
}

.status-badge.good {
    background: var(--success-color);
    color: white;
}

.status-badge.bad {
    background: var(--danger-color);
    color: white;
}

.status-badge.unknown {
    background: var(--text-secondary);
    color: white;
}

/* ===== Angle Display ===== */
.angle-display {
    text-align: center;
}

.angle-value {
    font-size: 36px;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.angle-bar {
    width: 100%;
    height: 10px;
    background: var(--border-color);
    border-radius: 5px;
    overflow: hidden;
}

.angle-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s, background 0.3s;
}

.angle-fill.warning {
    background: var(--warning-color);
}

.angle-fill.danger {
    background: var(--danger-color);
}

/* ===== Timer ===== */
.timer-display {
    text-align: center;
    font-size: 32px;
    font-weight: bold;
    color: var(--primary-color);
}

.timer-display i {
    margin-right: 10px;
}

/* ===== Live Stats ===== */
.live-stats {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.live-stats h2 {
    margin-bottom: 20px;
}

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

.mini-stat {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 8px;
}

.mini-stat i {
    font-size: 32px;
    color: var(--primary-color);
}

.mini-stat h4 {
    font-size: 24px;
    margin-bottom: 5px;
}

.mini-stat p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ===== Monitoring Status ===== */
.monitoring-status {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: pulse 2s infinite;
}

.status-indicator.active {
    background: var(--success-color);
}

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

/* ===== Filter Tabs ===== */
.filter-tabs {
    display: flex;
    gap: 10px;
}

.tab-btn {
    padding: 10px 20px;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

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

.tab-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ===== Summary Section ===== */
.summary-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.summary-card {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 20px;
}

.summary-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: white;
}

.summary-content h3 {
    font-size: 32px;
    margin-bottom: 5px;
}

.trend {
    font-size: 14px;
    padding: 4px 8px;
    border-radius: 4px;
}

.trend.up {
    color: var(--success-color);
    background: rgba(76, 175, 80, 0.1);
}

.trend.down {
    color: var(--danger-color);
    background: rgba(244, 67, 54, 0.1);
}

/* ===== Charts ===== */
.charts-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.chart-card {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.chart-card h3 {
    margin-bottom: 20px;
}

.chart-placeholder {
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== History Table ===== */
.history-section {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 30px;
}

.history-section h2 {
    margin-bottom: 20px;
}

.table-container {
    overflow-x: auto;
}

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

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

.history-table th {
    background: #f9f9f9;
    font-weight: 600;
    color: var(--text-primary);
}

.history-table tbody tr:hover {
    background: #f9f9f9;
}

/* ===== Settings ===== */
.settings-section {
    max-width: 800px;
}

.settings-card {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.settings-card h3 {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid var(--border-color);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-label {
    flex: 1;
}

.setting-label span {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
}

.setting-description {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ===== Switch Toggle ===== */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    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: #ccc;
    transition: 0.4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

/* ===== Form Inputs ===== */
.input-number,
.select-field {
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    min-width: 150px;
}

.range-slider {
    width: 200px;
    margin-right: 10px;
}

.range-value {
    font-weight: 600;
    color: var(--primary-color);
}

.settings-actions {
    display: flex;
    gap: 15px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* ===== About Section ===== */
.about-section {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.about-card p {
    margin-bottom: 10px;
    line-height: 1.8;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        width: 200px;
    }
    
    .main-content {
        margin-left: 200px;
        padding: 15px;
    }
    
    .stats-section,
    .summary-section {
        grid-template-columns: 1fr;
    }
    
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
}

@media (max-width: 576px) {
    .sidebar {
        width: 60px;
        padding: 10px;
    }
    
    .sidebar .logo h2,
    .sidebar .nav-menu span {
        display: none;
    }
    
    .main-content {
        margin-left: 60px;
        padding: 10px;
    }
}

/* ===== Sidebar Footer (user info + logout) ===== */
.sidebar-footer {
    margin-top: auto;
    padding: 1rem 0.5rem 0.5rem;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.user-info-sidebar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.75rem;
    color: rgba(255,255,255,0.8);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    overflow: hidden;
}

.user-info-sidebar i {
    font-size: 1.25rem;
    flex-shrink: 0;
    color: rgba(255,255,255,0.6);
}

#sidebarUsername {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.75rem;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.875rem;
    transition: background 0.2s, color 0.2s;
}

.btn-logout:hover {
    background: rgba(239,68,68,0.2);
    color: #fca5a5;
}

.btn-logout i {
    font-size: 1rem;
}

/* Sidebar flex column agar footer selalu di bawah */
.sidebar {
    display: flex;
    flex-direction: column;
}

.sidebar .nav-menu {
    flex: 1;
}

/* ===== Dashboard Welcome & Mode Cards ===== */
.welcome-section {
    margin-bottom: 0;
}

/* Override welcome-card lama jika ada */
.welcome-section .welcome-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 14px;
    padding: 1.75rem 2rem;
    color: white;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 16px rgba(102,126,234,.3);
}

.welcome-section .welcome-card h2 {
    font-size: 1.5rem;
    margin: 0 0 .4rem;
    color: white;
}

.welcome-section .welcome-card p {
    opacity: .85;
    margin: 0;
    font-size: .95rem;
    color: white;
}
