/* ===== Design System ===== */
:root {
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    
    /* Neutral Palette (Premium Modern Classic) */
    --bg-gradient: linear-gradient(135deg, #fafafa 0%, #f1f5f9 100%); /* Ultra-clean neutral to slate */
    --bg: #fafafa;
    --surface: rgba(255, 255, 255, 0.85); /* Slightly frosty white */
    --surface-solid: #ffffff;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    
    /* Functional Palette */
    --text: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    
    /* Branding */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    
    /* Tab-Specific Brand Colors (Professional Palette) */
    --brand-dashboard: #1e40af; /* Deep Blue */
    --brand-inventory: #0f766e; /* Deep Teal */
    --brand-reports: #5b21b6;   /* Deep Purple */
    --brand-schedule: #b45309;  /* Deep Amber */
    --brand-users: #334155;     /* Slate */
    
    /* UI States */
    --success: #059669;
    --success-light: #ecfdf5;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --info: #2563eb;
    --info-light: #eff6ff;
    
    /* Glassmorphism & Shadows */
    --glass-bg: rgba(255, 255, 255, 0.5);
    --glass-border: rgba(255, 255, 255, 0.6);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.05), 0 2px 4px -1px rgba(15, 23, 42, 0.03);
    --shadow-md: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -2px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 10px 10px -5px rgba(15, 23, 42, 0.05);
    
    /* Spacing & Borders */
    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 18px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Tab Theme Application */
body.theme-dashboard { --accent: var(--brand-dashboard); }
body.theme-inventory { --accent: var(--brand-inventory); }
body.theme-reports { --accent: var(--brand-reports); }
body.theme-ppm { --accent: var(--brand-schedule); }
body.theme-users { --accent: var(--brand-users); }
body:not([class*="theme-"]) { --accent: var(--primary); }

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }
html { scroll-behavior: smooth; }
body {
    font-family: var(--font);
    background: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    transition: background var(--transition);
}

/* ===== Header ===== */
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 16px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}
.header-logo {
    flex-shrink: 0;
}
.header-text h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.header-text p {
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
}

/* ===== Navigation ===== */
.app-nav {
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 0 32px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}
.nav-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    font-family: var(--font);
    opacity: 0.8;
}
.nav-tab:hover { 
    color: var(--text);
    opacity: 1;
    background: rgba(0,0,0,0.02);
}
.nav-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    opacity: 1;
}
.nav-tab svg { 
    stroke: currentColor; 
    transition: transform 0.2s ease;
}
.nav-tab:hover svg { transform: translateY(-1px); }

/* ===== Main ===== */
.app-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 32px 48px;
}

/* ===== Pages ===== */
.page { animation: fadeIn 0.3s ease; }
.page.hidden { display: none; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
}
.page-header h2 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.page-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ===== Cards ===== */
.card {
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    transition: var(--transition);
}
.card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--accent);
}
.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.card-header-row h3 {
    font-size: 16px;
    font-weight: 600;
}

/* ===== Summary Cards ===== */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
.summary-cards.summary-3 {
    grid-template-columns: repeat(3, 1fr);
}
.summary-card {
    background: var(--surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-top: 4px solid var(--accent);
    border-radius: var(--radius);
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    transition: var(--transition);
}
.summary-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-4px);
}
.summary-card-info h4 {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    margin-bottom: 4px;
}
.summary-card-info .number {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.03em;
}
.summary-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.summary-card-icon.green { background: var(--success-light); color: var(--success); }
.summary-card-icon.yellow { background: var(--warning-light); color: var(--warning); }
.summary-card-icon.red { background: var(--danger-light); color: var(--danger); }
.summary-card-icon.blue { background: var(--primary-light); color: var(--primary); }
.summary-card-icon.purple { background: var(--info-light); color: var(--info); }

/* ===== Charts ===== */
.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
.chart-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}
.chart-container {
    position: relative;
    height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== Status Badges ===== */
.status-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: var(--shadow-sm);
    text-transform: capitalize;
}
.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}
.status-A { background: var(--success-light); color: var(--success); }
.status-B { background: var(--info-light); color: var(--info); }
.status-C { background: var(--warning-light); color: var(--warning); }
.status-D { background: var(--warning-light); color: var(--warning); }
.status-E { background: var(--danger-light); color: var(--danger); }
.status-F { background: var(--surface-solid); color: var(--text-secondary); border: 1px solid var(--border); }
.status-badge.status-Pending { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.status-badge.status-InProgress { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.status-badge.status-Completed { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.status-badge.status-Overdue { background: rgba(239, 68, 68, 0.15); color: #f87171; }

/* ===== Tables ===== */
.table-responsive { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.data-table th {
    text-align: left;
    padding: 12px 16px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text);
}
.data-table tbody tr {
    transition: var(--transition);
}
.data-table tbody tr:hover {
    background: var(--bg);
}
.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* ===== Action Buttons ===== */
.action-btns {
    display: flex;
    gap: 8px;
}
.btn-action {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.btn-action:hover { background: var(--bg); color: var(--text); }
.btn-action.delete:hover { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: var(--transition);
    border: none;
    text-decoration: none;
    white-space: nowrap;
}
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}
.btn-primary:hover {
    filter: brightness(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}
.btn-outline {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--surface);
}
.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ===== Inventory Toolbar ===== */
.inventory-toolbar {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
}
.search-box {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    transition: var(--transition);
}
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.search-box input {
    border: none;
    outline: none;
    width: 100%;
    padding: 10px 0;
    font-size: 14px;
    font-family: var(--font);
    background: transparent;
    color: var(--text);
}
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.filter-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    transition: var(--transition);
    min-width: 240px;
}
.filter-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.filter-box svg { color: var(--text-muted); flex-shrink: 0; }
.filter-box select {
    border: none;
    outline: none;
    width: 100%;
    padding: 10px 0;
    font-size: 14px;
    font-family: var(--font);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}
.showing-count {
    font-size: 13px;
    color: var(--primary);
    margin-bottom: 12px;
}

/* ===== Export Buttons ===== */
.export-btns {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* ===== Dropdowns ===== */
.dropdown-container {
    position: relative;
    display: inline-block;
}
@keyframes dropdownFadeIn {
    from { opacity: 0; transform: translateY(-4px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 8px;
    z-index: 100;
    min-width: 180px;
    display: none;
    flex-direction: column;
    gap: 4px;
    animation: dropdownFadeIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: top right;
}
/* Invisible bridge to prevent hover loss */
.dropdown-menu::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    right: 0;
    height: 10px;
}
.dropdown-container:hover .dropdown-menu,
.dropdown-menu:hover {
    display: flex;
}
.dropdown-item {
    width: 100%;
    justify-content: flex-start;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    padding: 10px 14px;
    font-size: 13.5px;
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font);
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.dropdown-item svg {
    color: var(--text-muted);
    transition: color 0.2s ease;
}
.dropdown-item:hover {
    background: var(--bg);
    color: var(--primary);
    transform: translateX(4px);
}
.dropdown-item:hover svg {
    color: var(--primary);
}
.btn-export {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-pdf {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
}
.btn-pdf:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: #f87171;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.btn-excel {
    background: rgba(16, 185, 129, 0.1);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.3);
}
.btn-excel:hover {
    background: rgba(16, 185, 129, 0.2);
    border-color: #34d399;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}
.empty-state svg { margin-bottom: 12px; }
.empty-state p { font-size: 15px; margin-bottom: 8px; }
.empty-state a {
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}
.empty-state a:hover { text-decoration: underline; }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: overlayIn 0.2s ease;
}
.modal-overlay.hidden { display: none; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn 0.25s ease;
}
#equipmentModal .modal,
#ppmModal .modal,
#reportModal .modal {
    width: 80%;
    max-width: 1200px;
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 0;
}
.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}
.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.modal-close:hover { background: var(--border); color: var(--text); }

/* ===== Forms ===== */
.modal form { padding: 20px 24px 24px; }
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.required { color: var(--danger); }
.form-group input,
.form-group select,
.form-group textarea {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface);
    transition: var(--transition);
    width: 100%;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-group textarea { resize: vertical; }
.input-with-btn {
    display: flex;
    gap: 8px;
}
.input-with-btn select { flex: 1; }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

/* ===== Recent Equipment List ===== */
.recent-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-light);
}
.recent-item:last-child { border-bottom: none; }
.recent-item-info h4 {
    font-size: 14px;
    font-weight: 600;
}
.recent-item-info p {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--text);
    color: white;
    padding: 14px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: toastIn 0.3s ease;
}
.toast.hidden { display: none; }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .summary-cards { grid-template-columns: repeat(2, 1fr); }
    .summary-cards.summary-3 { grid-template-columns: repeat(2, 1fr); }
    .charts-row { grid-template-columns: 1fr; }
    .app-main { padding: 16px 16px 48px; }
    .app-header { padding: 12px 16px; }
    .app-nav { padding: 0 16px; }
}
@media (max-width: 600px) {
    .summary-cards { grid-template-columns: 1fr; }
    .summary-cards.summary-3 { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .inventory-toolbar { flex-direction: column; }
    .filter-box { min-width: unset; }
    .page-header { flex-direction: column; gap: 12px; }
    .page-header h2 { font-size: 20px; }
}

/* ===== Login Overlay ===== */
.login-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.login-overlay.hidden { display: none; }
.login-box {
    background: var(--surface-solid);
    width: 100%;
    max-width: 400px;
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
    border: 1px solid #e2e8f0;
}

/* ===== User Profile ===== */
.header-user {
    display: flex;
    align-items: center;
    gap: 16px;
}
.header-user.hidden { display: none !important; }
.user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}
.user-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}
.user-role {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Structured Spare Parts Modal Styles ===== */
.spare-parts-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.spare-row {
    display: grid;
    grid-template-columns: 1fr 80px 120px 40px;
    gap: 8px;
    align-items: center;
}
.spare-row.used {
    grid-template-columns: 1fr 80px 40px;
}
.spare-row input {
    padding: 6px 10px !important;
    font-size: 13px !important;
}
.spare-row .btn-remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition);
}
.spare-row .btn-remove:hover {
    background: var(--danger-light);
}

/* ===== Interactive Modern Clicks ===== */
.btn:active, .btn-action:active, .btn-icon:active, .btn-export:active, .modal-close:active, .spare-row .btn-remove:active {
    transform: scale(0.95) !important;
    transition: transform 0.05s ease !important;
}
.nav-tab:active {
    transform: scale(0.97);
    opacity: 0.7;
    transition: transform 0.05s ease;
}
.summary-card:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-sm) !important;
    transition: all 0.05s ease !important;
}
.card[onclick]:active {
    transform: scale(0.99);
    transition: transform 0.05s ease;
}
