/* CSS Variables */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --background-light: #f8fafc;
    --background-dark: #0f172a;
    --surface-light: #ffffff;
    --surface-dark: #1e293b;
    --text-light: #1e293b;
    --text-dark: #f1f5f9;
    --border-light: #e2e8f0;
    --border-dark: #334155;
    --shadow-light: rgba(0, 0, 0, 0.1);
    --shadow-dark: rgba(0, 0, 0, 0.3);
}

/* Dark Mode */
body.dark-mode {
    --background: var(--background-dark);
    --surface: var(--surface-dark);
    --text: var(--text-dark);
    --border: var(--border-dark);
    --shadow: var(--shadow-dark);
}

body:not(.dark-mode) {
    --background: var(--background-light);
    --surface: var(--surface-light);
    --text: var(--text-light);
    --border: var(--border-light);
    --shadow: var(--shadow-light);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--background);
    color: var(--text);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

/* Login Page */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color) 0%, #1e40af 100%);
}

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

.login-box {
    background: var(--surface);
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 20px 60px var(--shadow);
}

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

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

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

.login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.login-footer {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

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

/* Dashboard Page */
.dashboard-page {
    min-height: 100vh;
}

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

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.3s, transform 0.3s;
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 100;
}

.sidebar.collapsed {
    width: 70px;
}

.sidebar.collapsed .sidebar-header h2,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .logout-btn span {
    display: none;
}

/* Collapsed sidebar: center the icons cleanly */
.sidebar.collapsed .nav-item,
.sidebar.collapsed .logout-btn {
    justify-content: center;
    padding: 12px 0;
    margin: 0 8px;
}
.sidebar.collapsed .nav-item svg,
.sidebar.collapsed .logout-btn svg {
    width: 22px;
    height: 22px;
    margin: 0;
}
/* Tooltip-style label on hover when collapsed (desktop only) */
@media (hover: hover) and (min-width: 769px) {
    .sidebar.collapsed .nav-item { position: relative; }
    .sidebar.collapsed .nav-item::after {
        content: attr(aria-label);
        position: absolute;
        left: calc(100% + 8px);
        top: 50%;
        transform: translateY(-50%);
        background: var(--text);
        color: var(--surface);
        padding: 4px 10px;
        border-radius: 6px;
        font-size: 12px;
        font-weight: 600;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.15s;
        z-index: 200;
    }
    .sidebar.collapsed .nav-item:hover::after { opacity: 1; }
}

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

.sidebar-header h2 {
    color: var(--primary-color);
    font-size: 20px;
    font-weight: 700;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.sidebar-toggle:hover {
    background-color: var(--background);
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--text);
    text-decoration: none;
    border-radius: 10px;
    margin: 0 10px;
    overflow: hidden;
    transition: background-color 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                color 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Left accent indicator */
.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 3px;
    height: 60%;
    background: var(--primary-color);
    border-radius: 0 3px 3px 0;
    transform: translateY(-50%) scaleY(0);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-item:hover {
    background-color: var(--background);
    transform: translateX(2px);
}

.nav-item:hover::before {
    transform: translateY(-50%) scaleY(0.6);
}

.nav-item.active {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover, #1d4ed8) 100%);
    color: #fff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.nav-item.active::before {
    transform: translateY(-50%) scaleY(0);
}

.nav-item.active:hover {
    transform: translateX(0);
    filter: brightness(1.05);
}

.nav-item svg {
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.nav-item:hover svg {
    transform: scale(1.1);
}

.nav-item.active:hover svg {
    transform: scale(1);
}

.nav-item span {
    font-weight: 500;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    color: var(--danger-color);
    text-decoration: none;
    border-radius: 6px;
    transition: background-color 0.2s;
}

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

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s;
}

.sidebar.collapsed ~ .main-content {
    margin-left: 70px;
}

/* Top Bar */
.top-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.top-bar-left h1 {
    font-size: 24px;
    font-weight: 600;
}

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

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

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

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

.btn-secondary:hover {
    background-color: #475569;
}

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

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

/* User Dropdown */
.user-dropdown {
    position: relative;
}

.user-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.user-toggle:hover {
    border-color: var(--primary-color);
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

/* Theme Toggle */
.theme-toggle {
    width: 40px;
    height: 40px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.theme-toggle:hover {
    border-color: var(--primary-color);
}

/* Stats Section */
.stats-section {
    padding: 24px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.stat-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 2px 8px var(--shadow);
}

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

.stat-icon.total {
    background: var(--primary-color);
}

.stat-icon.for-approval {
    background: #6366f1;
}

.stat-icon.under-purchasing {
    background: #f59e0b;
}

.stat-icon.under-maintenance {
    background: #3b82f6;
}

.stat-icon.done {
    background: #10b981;
}

.stat-icon.cancel-project {
    background: #ef4444;
}

.stat-content h3 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

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

/* Filter Section */
.filter-section {
    padding: 0 24px 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
}

.search-bar {
    flex: 1;
    min-width: 300px;
    position: relative;
    display: flex;
    align-items: center;
}

.search-bar svg {
    position: absolute;
    left: 12px;
    color: var(--secondary-color);
}

.search-bar input {
    width: 100%;
    padding: 12px 12px 12px 44px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    transition: border-color 0.2s;
}

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

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

.filter-select {
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.2s;
}

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

/* Kanban Board */
.kanban-board {
    flex: 1;
    padding: 0 24px 24px;
    display: grid;
    grid-template-columns: repeat(5, minmax(260px, 1fr));
    gap: 16px;
    overflow-x: auto;
}

.kanban-column {
    background: var(--background);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    min-height: 400px;
    border-top: 4px solid var(--border);
}

.kanban-column[data-status="FOR APPROVAL"] { border-top-color: #6366f1; }
.kanban-column[data-status="UNDER PURCHASING"] { border-top-color: #f59e0b; }
.kanban-column[data-status="UNDER MAINTENANCE"] { border-top-color: #3b82f6; }
.kanban-column[data-status="DONE"] { border-top-color: #10b981; }
.kanban-column[data-status="CANCEL PROJECT"] { border-top-color: #ef4444; }

.kanban-column[data-status="FOR APPROVAL"] .column-count { background: #6366f1; }
.kanban-column[data-status="UNDER PURCHASING"] .column-count { background: #f59e0b; }
.kanban-column[data-status="UNDER MAINTENANCE"] .column-count { background: #3b82f6; }
.kanban-column[data-status="DONE"] .column-count { background: #10b981; }
.kanban-column[data-status="CANCEL PROJECT"] .column-count { background: #ef4444; }

.kanban-card.status-for-approval { border-left: 3px solid #6366f1; }
.kanban-card.status-under-purchasing { border-left: 3px solid #f59e0b; }
.kanban-card.status-under-maintenance { border-left: 3px solid #3b82f6; }
.kanban-card.status-done { border-left: 3px solid #10b981; }
.kanban-card.status-cancel-project { border-left: 3px solid #ef4444; }

.card-remarks {
    margin-top: 8px;
    padding: 6px 10px;
    background: rgba(0,0,0,0.04);
    border-radius: 6px;
    font-size: 11px;
    color: var(--secondary-color);
    font-style: italic;
}

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

.column-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.column-count {
    background: var(--primary-color);
    color: white;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.kanban-cards {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 200px;
}

.kanban-cards.drag-over {
    background: rgba(37, 99, 235, 0.1);
    border-radius: 8px;
}

/* Kanban Card */
.kanban-card {
    background: var(--surface);
    border-radius: 10px;
    padding: 16px;
    cursor: grab;
    box-shadow: 0 2px 4px var(--shadow);
    transition: all 0.2s;
    border: 2px solid transparent;
}

.kanban-card:hover {
    box-shadow: 0 4px 12px var(--shadow);
    transform: translateY(-2px);
}

.kanban-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

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

.card-id {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color);
}

.card-priority {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.card-priority.High {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

.card-priority.Medium {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

.card-priority.Low {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 8px;
    line-height: 1.4;
}

.card-description {
    font-size: 13px;
    color: var(--secondary-color);
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-location {
    font-size: 12px;
    color: var(--secondary-color);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

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

.card-technician {
    font-size: 12px;
    color: var(--secondary-color);
    display: flex;
    align-items: center;
    gap: 4px;
}

.card-due-date {
    font-size: 12px;
    color: var(--secondary-color);
}

.card-due-date.overdue {
    color: var(--danger-color);
    font-weight: 600;
}

/* 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;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-large {
    max-width: 800px;
}

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

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

.modal-close {
    background: none;
    border: none;
    color: var(--secondary-color);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.modal-close:hover {
    background: var(--background);
}

.modal-body {
    padding: 20px;
}

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

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 14px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    transition: border-color 0.2s;
}

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

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

/* Alert */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
}

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

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

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 16px 24px;
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow);
    z-index: 1100;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
}

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

.toast.success {
    border-left: 4px solid var(--success-color);
}

.toast.error {
    border-left: 4px solid var(--danger-color);
}

/* Loading Overlay */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Settings Tabs */
.settings-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 16px;
}

.tab-btn {
    padding: 10px 20px;
    background: none;
    border: none;
    color: var(--secondary-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: var(--background);
    color: var(--text);
}

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

.tab-content {
    display: none;
}

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

.tab-content h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.tab-description {
    color: var(--secondary-color);
    font-size: 14px;
    margin-bottom: 24px;
}

.tab-content small {
    display: block;
    margin-top: 4px;
    color: var(--secondary-color);
    font-size: 12px;
}

/* View Modal Content */
.mwo-detail-section {
    margin-bottom: 24px;
}

.mwo-detail-section h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--secondary-color);
    text-transform: uppercase;
}

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

.mwo-detail-label {
    width: 120px;
    font-weight: 500;
    color: var(--secondary-color);
}

.mwo-detail-value {
    flex: 1;
}

.activity-log {
    max-height: 200px;
    overflow-y: auto;
}

.activity-item {
    padding: 8px 12px;
    background: var(--background);
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 13px;
}

.activity-item:last-child {
    margin-bottom: 0;
}

.activity-date {
    color: var(--secondary-color);
    font-size: 11px;
    margin-top: 4px;
}

.comments-section {
    max-height: 300px;
    overflow-y: auto;
}

.comment-item {
    padding: 12px;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 12px;
}

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

.comment-user {
    font-weight: 600;
    font-size: 13px;
}

.comment-date {
    color: var(--secondary-color);
    font-size: 11px;
}

.comment-text {
    font-size: 14px;
    line-height: 1.5;
}

.comment-form {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.comment-form textarea {
    flex: 1;
    min-height: 60px;
}

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

/* Responsive Design */
/* =========================================================
   RESPONSIVE LAYER
   Breakpoints:
     XS phone   : <= 480px
     Mobile     : <= 768px
     Tablet     : <= 1024px
     Laptop     : <= 1400px
     Desktop    : <= 1920px (default)
     Ultra/TV   : >= 1921px
   ========================================================= */

/* Fluid base typography */
html { font-size: clamp(14px, 0.6vw + 12px, 18px); }
body { font-size: 1rem; }

/* Prevent horizontal overflow globally */
html, body { overflow-x: hidden; max-width: 100%; }
img, svg, video, canvas { max-width: 100%; height: auto; }

/* Mobile sidebar backdrop (created dynamically) */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.sidebar-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

/* Fluid section padding helpers */
.stats-section,
.filter-section,
.kanban-board,
.analytics-grid,
.analytics-toolbar {
    padding-left: clamp(12px, 2vw, 32px);
    padding-right: clamp(12px, 2vw, 32px);
}

/* ===== Laptop (<= 1400px) ===== */
@media (max-width: 1400px) {
    .kanban-board {
        grid-template-columns: repeat(3, minmax(260px, 1fr));
    }
}

/* ===== Tablet (<= 1024px) ===== */
@media (max-width: 1024px) {
    .kanban-board {
        grid-template-columns: repeat(2, minmax(240px, 1fr));
    }
    .stats-section {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }
    .analytics-grid {
        grid-template-columns: 1fr !important;
    }
    .chart-card[style*="grid-column"] {
        grid-column: auto !important;
    }
    .modal-content { max-width: 92vw; }
    .modal-large { max-width: 95vw; }
}

/* ===== Mobile (<= 768px) ===== */
@media (max-width: 768px) {
    /* Mobile drawer */
    .sidebar {
        transform: translateX(-100%);
        width: min(280px, 80vw);
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }
    .sidebar.active {
        transform: translateX(0);
    }
    .sidebar.collapsed {
        width: min(280px, 80vw);
    }
    .sidebar.collapsed .sidebar-header h2,
    .sidebar.collapsed .nav-item span,
    .sidebar.collapsed .logout-btn span {
        display: inline;
    }
    .main-content,
    .sidebar.collapsed ~ .main-content {
        margin-left: 0 !important;
    }

    /* Header / top bar */
    .top-bar,
    .main-header {
        flex-wrap: wrap;
        gap: 12px;
        padding: 14px 16px;
    }
    .top-bar-left h1,
    .main-header h1 { font-size: clamp(18px, 4.5vw, 22px); }
    .top-bar-right { flex-wrap: wrap; gap: 8px; }
    .header-actions { width: 100%; display: flex; justify-content: flex-end; }

    /* Stats: horizontal swipe carousel on mobile so all 6 cards are reachable */
    .stats-section {
        display: flex;
        grid-template-columns: none;
        gap: 12px;
        padding: 12px 16px;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    .stats-section::-webkit-scrollbar { height: 6px; }
    .stats-section::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
    .stat-card {
        flex: 0 0 auto;
        min-width: 70vw;
        max-width: 70vw;
        padding: 16px;
        gap: 12px;
        scroll-snap-align: start;
    }
    .stat-icon { width: 44px; height: 44px; }
    .stat-content h3 { font-size: 22px; }

    .filter-section {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    .search-bar { min-width: auto; width: 100%; }
    .filter-controls { flex-direction: column; width: 100%; }
    .filter-select { width: 100%; }

    /* Kanban: horizontal swipe carousel on mobile (5 columns side-by-side, swipe to navigate) */
    .kanban-board {
        display: flex;
        grid-template-columns: none;
        gap: 12px;
        padding: 12px 16px 80px;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    .kanban-board::-webkit-scrollbar { height: 6px; }
    .kanban-board::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
    .kanban-column {
        flex: 0 0 auto;
        width: 85vw;
        max-width: 360px;
        min-height: auto;
        scroll-snap-align: start;
    }
    .kanban-cards {
        max-height: calc(100vh - 280px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Forms / Modals */
    .form-row { grid-template-columns: 1fr !important; }
    .modal { padding: 12px; align-items: flex-start; }
    .modal-content {
        max-width: 100%;
        max-height: calc(100vh - 24px);
        margin: 0;
        border-radius: 14px;
    }
    .modal-footer { flex-direction: column-reverse; }
    .modal-footer .btn { width: 100%; justify-content: center; }
    .btn { padding: 12px 18px; min-height: 44px; }

    /* Analytics */
    .analytics-toolbar { flex-direction: column; align-items: flex-start; gap: 12px; }
    .summary-pill { font-size: 12px; }
    .chart-card { padding: 14px; }
    .chart-canvas-wrap { height: 260px !important; }
    .chart-card.maximized { inset: 8px; border-radius: 10px; }

    /* Login */
    .login-box { padding: 24px 18px; }
}

/* ===== Small Phone (<= 480px) ===== */
@media (max-width: 480px) {
    /* Keep horizontal flex carousel; just tighten card sizing */
    .stat-card { padding: 14px; min-width: 78vw; max-width: 78vw; }
    .stat-content h3 { font-size: 20px; }
    .kanban-column { width: 88vw; }
    .top-bar, .main-header { padding: 12px; }
    .login-box { padding: 20px 14px; }
    .modal-header, .modal-body { padding: 14px; }
    .chart-card { padding: 12px; border-radius: 10px; }
    .chart-canvas-wrap { height: 220px !important; }
    .nav-item { padding: 14px 16px; }
    .card-btn { width: 32px; height: 32px; }
}

/* ===== Landscape phones (height-constrained) ===== */
@media (max-height: 480px) and (orientation: landscape) {
    .sidebar-header { padding: 12px 16px; }
    .sidebar-nav { padding: 8px 0; gap: 4px; }
    .nav-item { padding: 8px 16px; }
    .login-box { padding: 18px; }
}

/* ===== Ultra-wide / Smart TV (>= 1921px) ===== */
@media (min-width: 1921px) {
    .stats-section,
    .filter-section,
    .kanban-board,
    .analytics-grid,
    .analytics-toolbar,
    .top-bar,
    .main-header {
        max-width: 1800px;
        margin-left: auto;
        margin-right: auto;
    }
    .kanban-board {
        grid-template-columns: repeat(5, minmax(300px, 1fr));
        gap: 24px;
    }
    .stats-section {
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
        gap: 28px;
    }
    .analytics-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 28px;
    }
    .chart-canvas-wrap { height: 380px; }
    .stat-content h3 { font-size: 32px; }
    .stat-icon { width: 64px; height: 64px; }
}

/* ===== Cinema / 4K TV (>= 2560px) ===== */
@media (min-width: 2560px) {
    html { font-size: 20px; }
    .sidebar { width: 320px; }
    .main-content { margin-left: 320px; }
    .sidebar.collapsed ~ .main-content { margin-left: 80px; }
    .stats-section,
    .filter-section,
    .kanban-board,
    .analytics-grid,
    .analytics-toolbar,
    .top-bar,
    .main-header {
        max-width: 2200px;
    }
    .chart-canvas-wrap { height: 460px; }
}

/* ===== Touch device tweaks ===== */
@media (hover: none) and (pointer: coarse) {
    .btn, .nav-item, .filter-select, .search-bar input { min-height: 44px; }
    .kanban-card { cursor: default; }
    .card-btn { width: 36px; height: 36px; }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== Users Tab Styles ===== */
.users-tab-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}
.users-tab-header h3 { margin: 0 0 4px; }
.users-tab-header .tab-description { margin: 0; color: var(--text-secondary); font-size: 0.85rem; }

.users-table-wrap {
    overflow-x: auto;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
}

.users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.users-table th,
.users-table td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.users-table thead th {
    font-weight: 600;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

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

.users-table tbody tr:hover {
    background: var(--bg-hover, rgba(0,0,0,0.03));
}

.users-table a { color: var(--accent-color, #2563eb); text-decoration: none; }
.users-table a:hover { text-decoration: underline; }

.ta-center { text-align: center !important; }
.ta-right { text-align: right !important; }
.muted { color: var(--text-secondary); opacity: 0.7; }

/* Avatar / user cell */
.user-cell {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}
.user-avatar-sm {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #2563eb);
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.user-name { font-weight: 600; color: var(--text-primary); }

/* Role badge */
.role-badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: 1px solid transparent;
}
.role-superadmin { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.role-admin      { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.role-manager    { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.role-viewer     { background: #f3f4f6; color: #374151; border-color: #e5e7eb; }

/* Notify pill */
.pill {
    display: inline-block;
    padding: 0.18rem 0.6rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
}
.pill-on  { background: #dcfce7; color: #166534; }
.pill-off { background: #f3f4f6; color: #6b7280; }

/* User editor panel */
.user-editor {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-radius: 10px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0,0,0,0.04);
}
.user-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}
.user-editor-header h4 { margin: 0; font-size: 1.05rem; }
.user-editor-close {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 4px;
    display: inline-flex;
}
.user-editor-close:hover { background: var(--bg-hover, rgba(0,0,0,0.05)); color: var(--text-primary); }
.user-editor-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Permission grid */
.perm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-top: 0.5rem;
}
.perm-module {
    padding: 0.85rem 0.9rem;
    background: var(--bg-primary);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}
.perm-module strong {
    display: block;
    margin-bottom: 0.6rem;
    font-size: 0.78rem;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.perm-module .checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
    font-size: 0.85rem;
    cursor: pointer;
}
.perm-module .checkbox-label input { margin: 0; }

/* Small button */
.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.82rem;
}

/* iOS-style switch toggle */
.switch-label {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
}
.switch-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.switch-label .switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    background: #cbd5e1;
    border-radius: 999px;
    transition: background 0.2s ease;
    flex-shrink: 0;
}
.switch-label .switch::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch-label input:checked + .switch {
    background: #16a34a;
}
.switch-label input:checked + .switch::before {
    transform: translateX(18px);
}
.switch-label input:focus-visible + .switch {
    box-shadow: 0 0 0 3px rgba(22,163,74,0.25);
}

/* Dark mode tweaks */
[data-theme="dark"] .role-superadmin { background: #422006; color: #fbbf24; border-color: #78350f; }
[data-theme="dark"] .role-admin      { background: #172554; color: #93c5fd; border-color: #1e3a8a; }
[data-theme="dark"] .role-manager    { background: #052e16; color: #6ee7b7; border-color: #14532d; }
[data-theme="dark"] .role-viewer     { background: #1f2937; color: #d1d5db; border-color: #374151; }
[data-theme="dark"] .pill-on  { background: #052e16; color: #6ee7b7; }
[data-theme="dark"] .pill-off { background: #1f2937; color: #9ca3af; }
[data-theme="dark"] .switch-label .switch { background: #4b5563; }


/* ===== Analytics View (merged from analytics.php) ===== */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    padding: 0 24px 24px;
}
.chart-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px var(--shadow);
    display: flex;
    flex-direction: column;
    transition: transform 0.2s, box-shadow 0.2s;
}
.chart-card.minimized { padding-bottom: 12px; }
.chart-card.minimized .card-body { display: none; }
.chart-card.maximized {
    position: fixed;
    inset: 20px;
    z-index: 2000;
    grid-column: auto !important;
    width: auto !important;
    height: auto !important;
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
    border-radius: 14px;
}
.chart-card.maximized .chart-canvas-wrap { flex: 1 1 auto; height: auto !important; }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
.card-header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.card-controls { display: flex; gap: 6px; align-items: center; }
.card-btn {
    background: transparent;
    border: 1px solid var(--border, #e5e7eb);
    color: var(--secondary-color, #6b7280);
    width: 28px; height: 28px;
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.card-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}
.card-btn:active { transform: translateY(0) scale(0.95); box-shadow: none; }
.card-btn svg { display: block; transition: transform 0.15s ease; }
.card-btn:hover svg { transform: scale(1.15); }
.maximized-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1999;
    display: none;
}
.maximized-backdrop.active { display: block; }
body.has-maximized .app-container { overflow: hidden; }
.chart-card .chart-sub {
    font-size: 12px;
    color: var(--secondary-color);
    margin: 0 0 16px;
}
.chart-canvas-wrap { position: relative; height: 320px; }
.analytics-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    gap: 16px;
    flex-wrap: wrap;
}
.analytics-toolbar h2 { font-size: 22px; font-weight: 700; margin: 0; }
.analytics-toolbar .summary { display: flex; gap: 16px; flex-wrap: wrap; }
.summary-pill {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    gap: 6px;
    align-items: center;
}
.summary-pill span { color: var(--secondary-color); font-weight: 500; }

/* SPA view containers */
.view { display: none; }
.view.active { display: block; }

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

