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

:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --secondary-color: #6b7280;
    --background: #f3f4f6;
    --surface: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    /* Compatibility aliases used across templates */
    --bg-secondary: var(--background);
    --bg-primary: var(--surface);
    --bg-card: var(--surface);
    --primary: var(--primary-color);
}

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

.container {
    min-height: 100vh;
}

/* Navbar */
.navbar {
    background-color: var(--surface);
    padding: 1rem 2rem;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.navbar-brand h1 {
    font-size: 1.5rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    line-height: 1;
    margin: 0;
}

.navbar-menu {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.navbar-user {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Sidebar Layout */
.sidebar-layout {
    display: flex;
    min-height: calc(100vh - 72px);
}

.sidebar {
    width: 250px;
    background-color: var(--surface);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem 0;
}

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

.sidebar-menu li {
    margin-bottom: 0.25rem;
}

.sidebar-menu a {
    display: block;
    padding: 0.75rem 1.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
}

.sidebar-menu a:hover {
    background-color: var(--background);
    color: var(--primary-color);
}

.sidebar-menu a.active {
    background-color: var(--primary-color);
    color: white;
}

.sidebar-section {
    padding: 0.5rem 1.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-top: 1rem;
}

/* Sub-section label (smaller than sidebar-section, no top margin) */
.sidebar-subsection {
    padding: 0.35rem 1.5rem 0.1rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    opacity: 0.75;
    margin-top: 0.5rem;
}

/* Indented sub-items under a parent nav item */
.sidebar-subitem > a {
    padding-left: 2.5rem;
    font-size: 0.9em;
}

/* Content Area */
.content, .content-full {
    flex: 1;
    padding: 2rem;
}

.content-full {
    max-width: 1200px;
    margin: 0 auto;
}

/* Cards */
.card {
    background-color: var(--surface);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

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

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

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

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

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

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

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn:disabled,
.btn[disabled] {
    opacity: 0.65;
    cursor: not-allowed;
    pointer-events: none;
}

/* Inline spinner inside a button (used during async actions) */
.btn-spinner {
    display: inline-block;
    width: 0.85em;
    height: 0.85em;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 0.35em;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: white;
}

/* Table */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table thead {
    background-color: var(--background);
}

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

.table th {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.table tbody tr:nth-child(even) {
    background-color: #f9fafb;
}

.table tbody tr:hover {
    background-color: var(--background);
}

/* Badge */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 0.25rem;
}

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

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

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

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

/* Alert */
.alert {
    padding: 1rem;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
}

.alert-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.alert-error {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #ef4444;
}

.alert-info {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #2563eb;
}

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

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--surface);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* Login Page */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    background-color: var(--surface);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    max-width: 400px;
    width: 100%;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Utility Classes */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.flex {
    display: flex;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

.grid {
    display: grid;
    gap: 1rem;
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* Breadcrumb */
.breadcrumb {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.125rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1.25rem;
    padding: 0.625rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
}

.breadcrumb a {
    color: var(--primary-color);
    text-decoration: none;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    transition: background 0.15s, color 0.15s;
}

.breadcrumb a:hover {
    background: var(--background);
    color: var(--primary-dark);
    text-decoration: none;
}

.breadcrumb span.sep {
    margin: 0 0.25rem;
    color: #9ca3af;
    font-size: 1rem;
    user-select: none;
}

.breadcrumb span.current {
    color: var(--text-primary);
    font-weight: 600;
    padding: 0.125rem 0.375rem;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 2.5rem 1.5rem;
    background: var(--background);
    border-radius: 0.5rem;
    border: 1px dashed var(--border-color);
}

.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.7;
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    max-width: 360px;
    margin-left: auto;
    margin-right: auto;
}

.empty-state .btn {
    margin-top: 0.25rem;
}

.loading-message {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 0.5rem;
}

.error-retry-box {
    padding: 1.25rem;
    background: #fee2e2;
    border: 1px solid #ef4444;
    border-radius: 0.5rem;
    text-align: center;
}

.error-retry-box p {
    margin-bottom: 0.75rem;
    color: #991b1b;
}

.error-retry-box .btn {
    margin-top: 0.25rem;
}

/* Loading Spinner */
.spinner {
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 2rem auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* Required field marker */
.req {
    color: var(--danger-color);
}

/* Alert – warning */
.alert-warning {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid var(--warning-color);
}

/* Tabs — shared across pages (organization, leaves, shifts, etc.) */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 0;
}

.tab-button {
    padding: 12px 24px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
}

.tab-button:hover {
    color: var(--primary-color);
}

.tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    display: none;
}

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

/* Responsive */
/* Sidebar toggle (hamburger) button – hidden on desktop, shown on mobile */
.sidebar-toggle-btn {
    display: none;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.3rem 0.55rem;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--text-secondary);
    transition: background 0.2s, border-color 0.2s;
}

.sidebar-toggle-btn:hover {
    background-color: var(--background);
    border-color: var(--text-secondary);
}

/* Sidebar overlay (backdrop for mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
}

.sidebar-overlay.show {
    display: block;
}

@media (max-width: 768px) {
    .sidebar-toggle-btn {
        display: inline-block;
    }

    .sidebar-layout {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 260px;
        height: 100vh;
        z-index: 100;
        border-right: 1px solid var(--border-color);
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        padding-top: 1rem;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .navbar {
        padding: 0.75rem 1rem;
    }

    .content {
        padding: 1rem;
    }

    .table {
        font-size: 0.75rem;
    }

    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr;
    }
}

/* Dark theme — use html[data-theme="dark"] for specificity (0,1,1) which
   beats :root (0,1,0), ensuring variable overrides always win. */
html[data-theme="dark"] {
    --primary-color: #3b82f6;
    --primary-dark: #2563eb;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --secondary-color: #9ca3af;
    --background: #111827;
    --surface: #1f2937;
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --border-color: #374151;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
}

/* Explicit overrides — belt-and-suspenders on top of CSS variable inheritance */
html[data-theme="dark"],
html[data-theme="dark"] body {
    background-color: #111827;
    color: #f9fafb;
}

html[data-theme="dark"] .navbar {
    background-color: #1f2937;
    border-bottom: 1px solid #374151;
}

html[data-theme="dark"] .sidebar {
    background-color: #1f2937;
    border-right-color: #374151;
}

html[data-theme="dark"] .card {
    background-color: #1f2937;
    color: #f9fafb;
}

html[data-theme="dark"] .breadcrumb {
    background: transparent;
    color: #9ca3af;
}

html[data-theme="dark"] .form-select,
html[data-theme="dark"] .form-control,
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
html[data-theme="dark"] textarea,
html[data-theme="dark"] select {
    background-color: #1f2937;
    color: #f9fafb;
    border-color: #374151;
}

html[data-theme="dark"] .table {
    color: #f9fafb;
}

html[data-theme="dark"] .table thead {
    background-color: #111827;
    color: #9ca3af;
}

html[data-theme="dark"] .table tbody tr:nth-child(even) {
    background-color: #243044;
}

html[data-theme="dark"] .table tbody tr:hover {
    background-color: #2d3a4e;
}

html[data-theme="dark"] .modal-content {
    background-color: #1f2937;
    color: #f9fafb;
}

html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer {
    border-color: #374151;
}

html[data-theme="dark"] .login-card {
    background-color: #1f2937;
}

html[data-theme="dark"] .empty-state {
    background: #1f2937;
    border-color: #374151;
    color: #f9fafb;
}

html[data-theme="dark"] .sidebar-section {
    color: #9ca3af;
}

html[data-theme="dark"] .btn-secondary {
    background-color: #374151;
    color: #f9fafb;
    border-color: #4b5563;
}

html[data-theme="dark"] .btn-secondary:hover {
    background-color: #4b5563;
}

html[data-theme="dark"] .alert-success {
    background-color: #064e3b;
    color: #6ee7b7;
    border-color: #059669;
}

html[data-theme="dark"] .alert-error {
    background-color: #7f1d1d;
    color: #fca5a5;
    border-color: #dc2626;
}

html[data-theme="dark"] .alert-info {
    background-color: #1e3a5f;
    color: #93c5fd;
    border-color: #2563eb;
}

html[data-theme="dark"] .alert-warning {
    background-color: #78350f;
    color: #fde68a;
    border-color: #f59e0b;
}

html[data-theme="dark"] .error-retry-box {
    background: #7f1d1d;
    border-color: #dc2626;
}

html[data-theme="dark"] .error-retry-box p {
    color: #fca5a5;
}

/* Theme toggle button */
.theme-toggle-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.3rem 0.55rem;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    color: var(--text-secondary);
    transition: background 0.2s, border-color 0.2s;
}

.theme-toggle-btn:hover {
    background-color: var(--background);
    border-color: var(--text-secondary);
}

/* Navbar brand logo — use max-height/max-width so the image scales down
   naturally without reserving a fixed-size box. */
.navbar-logo {
    max-height: 32px;
    height: auto;
    max-width: 120px;
    width: auto;
    object-fit: contain;
    vertical-align: middle;
    border-radius: 4px;
    display: block;
}

/* ── Dashboard stat cards ─────────────────────────────────────────────────── */
html[data-theme="dark"] .dash-stat-card {
    background: #1f2937;
    color: #f9fafb;
    box-shadow: 0 1px 4px rgba(0,0,0,.4);
}

html[data-theme="dark"] .dash-stat-val {
    color: #f9fafb;
}

html[data-theme="dark"] .dash-stat-label {
    color: #9ca3af;
}

/* ── Salary table column tints ────────────────────────────────────────────── */
/* Replace white-pastel backgrounds with dark-compatible tints so
   numbers remain readable in dark mode.                                       */
html[data-theme="dark"] .present-col  { background: rgba( 16,185,129,.15); color: #f9fafb; }
html[data-theme="dark"] .half-col     { background: rgba(245,158, 11,.12); color: #f9fafb; }
html[data-theme="dark"] .absent-col   { background: rgba(239, 68, 68,.15); color: #f9fafb; }
html[data-theme="dark"] .leave-col    { background: rgba( 59,130,246,.15); color: #f9fafb; }
html[data-theme="dark"] .holiday-col  { background: rgba(139, 92,246,.15); color: #f9fafb; }
html[data-theme="dark"] .ot-col       { background: rgba(249,115, 22,.12); color: #f9fafb; }
html[data-theme="dark"] .base-col     { background: rgba(255,255,255,.05); color: #f9fafb; }
html[data-theme="dark"] .total-col    { background: rgba( 16,185,129,.18); color: #f9fafb; }
html[data-theme="dark"] .breakdown-col{ background: rgba( 59,130,246,.12); color: #f9fafb; }

html[data-theme="dark"] .sal-approved-badge {
    background: #064e3b;
    color: #6ee7b7;
}

html[data-theme="dark"] .sal-approved-row {
    background: rgba(16,185,129,.08) !important;
    color: #d1d5db;
}

html[data-theme="dark"] .badge-monthly {
    background: #164e63;
    color: #7dd3fc;
}

html[data-theme="dark"] .badge-daily {
    background: #064e3b;
    color: #6ee7b7;
}

html[data-theme="dark"] .sal-table th {
    background: #111827;
    color: #9ca3af;
}

html[data-theme="dark"] .deduction-text {
    color: #fca5a5;
}

html[data-theme="dark"] .net-pay-text {
    color: #93c5fd;
}

/* ── Toast Notifications ──────────────────────────────────────────────────── */
#toastContainer {
    position: fixed;
    top: 1.25rem;
    right: 1.25rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 360px;
    pointer-events: none;
}

.toast {
    padding: 0.875rem 1rem 0.875rem 1.25rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    pointer-events: all;
    animation: toastIn 0.3s ease;
    line-height: 1.4;
}

.toast-success {
    background-color: #d1fae5;
    color: #065f46;
    border-left: 4px solid #10b981;
}

.toast-error {
    background-color: #fee2e2;
    color: #991b1b;
    border-left: 4px solid #ef4444;
}

.toast-info {
    background-color: #dbeafe;
    color: #1e40af;
    border-left: 4px solid #2563eb;
}

.toast-warning {
    background-color: #fef3c7;
    color: #92400e;
    border-left: 4px solid #f59e0b;
}

.toast-body {
    flex: 1;
}

.toast-close {
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.5;
    font-size: 1.1rem;
    padding: 0;
    line-height: 1;
    color: inherit;
    flex-shrink: 0;
    align-self: center;
}

.toast-close:hover {
    opacity: 1;
}

@keyframes toastIn {
    from { transform: translateX(110%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

@keyframes toastOut {
    from { transform: translateX(0);    opacity: 1; }
    to   { transform: translateX(110%); opacity: 0; }
}

/* Dark-mode toast overrides */
html[data-theme="dark"] .toast-success {
    background-color: #064e3b;
    color: #a7f3d0;
    border-color: #10b981;
}

html[data-theme="dark"] .toast-error {
    background-color: #7f1d1d;
    color: #fca5a5;
    border-color: #ef4444;
}

html[data-theme="dark"] .toast-info {
    background-color: #1e3a5f;
    color: #bfdbfe;
    border-color: #2563eb;
}

html[data-theme="dark"] .toast-warning {
    background-color: #78350f;
    color: #fde68a;
    border-color: #f59e0b;
}
