/* RESET & CORE */
:root {
    /* Colors */
    --primary: #1e40af;
    /* Blue 800 - Strong Primary */
    --primary-hover: #1e3a8a;
    /* Blue 900 */
    --accent: #3b82f6;
    /* Blue 500 */

    --bg-body: #f1f5f9;
    /* Slate 100 - Light Grey Background */
    --bg-card: #ffffff;
    /* White - Card Background */

    --text-main: #0f172a;
    /* Slate 900 - Darkest Text for Headings */
    --text-body: #334155;
    /* Slate 700 - Body Text */
    --text-muted: #64748b;
    /* Slate 500 - Secondary Text */

    --border: #cbd5e1;
    /* Slate 300 - Borders */
    --border-focus: #3b82f6;
    /* Blue 500 - Focus Ring */

    --success: #166534;
    /* Green 800 */
    --success-bg: #dcfce7;
    /* Green 100 */
    --danger: #991b1b;
    /* Red 800 */
    --danger-bg: #fee2e2;
    /* Red 100 */
    --warning: #854d0e;
    /* Yellow 800 */
    --warning-bg: #fef9c3;
    /* Yellow 100 */

    /* Spacing & Layout */
    --radius: 8px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-body);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

/* TYPOGRAPHY */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-main);
    font-weight: 700;
    line-height: 1.2;
}

a {
    text-decoration: none;
    color: inherit;
}

/* UTILITIES */
.text-muted {
    color: var(--text-muted);
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-danger {
    color: var(--danger);
}

.text-sm {
    font-size: 0.875rem;
}

.mt-1 {
    margin-top: 0.25rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.flex-end {
    display: flex;
    justify-content: flex-end;
}

.d-none {
    display: none;
}

/* LAYOUT: PORTAL CONTAINER (Legacy) */
.portal-container {
    width: 100%;
    margin: 0;
    padding: 20px;
    min-height: 100vh;
}

/* NAVBAR */
.navbar {
    background-color: #1e293b;
    /* Slate 800 - Dark Header */
    color: #ffffff;
    padding: 1rem 2rem;
    border-radius: var(--radius);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
}

.navbar-brand h2 {
    color: #ffffff;
    /* White text for contrast */
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.user-details {
    text-align: right;
    line-height: 1.3;
}

.user-name {
    display: block;
    font-weight: 600;
    font-size: 0.95rem;
    color: #ffffff;
}

.user-role {
    display: block;
    font-size: 0.8rem;
    color: #94a3b8;
    /* Slate 400 */
}

/* GRID SYSTEM */
.dashboard-grid {
    display: grid;
    gap: 2rem;
}

/* CARDS */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 2rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #f1f5f9;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
}

.card-title {
    font-size: 1.25rem;
    color: var(--primary);
}

/* TOOLBAR & CONTROLS */
.header-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    width: 100%;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--border);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}

.control-group label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    white-space: nowrap;
}

.control-group .form-control-sm {
    border: none;
    background: transparent;
    padding: 2px 4px;
    font-weight: 600;
    color: var(--primary);
}


/* STATS */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    border-left: 5px solid var(--accent);
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}

.stat-value {
    font-size: 2.25rem;
    font-weight: 800;
    color: var(--text-main);
    margin-top: 0.5rem;
}

/* FORMS */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-body);
    font-size: 0.95rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: #ffffff;
    color: var(--text-main);
    transition: all 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--radius);
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-transform: capitalize;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

.btn-xs {
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
    line-height: 1;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: #f1f5f9;
    color: var(--text-body);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background-color: #e2e8f0;
}

.btn-approve {
    background-color: var(--success);
    color: white;
}

.btn-approve:hover {
    background-color: #14532d;
}

.btn-reject {
    background-color: var(--danger);
    color: white;
}

.btn-reject:hover {
    background-color: #7f1d1d;
}

.btn-logout {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.5rem 1rem;
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

/* TABLES */
.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    font-size: 0.95rem;
}

thead {
    background-color: #f8fafc;
}

th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.8rem;
    border-bottom: 2px solid var(--border);
}

td {
    padding: 1rem;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text-body);
    vertical-align: top;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: #f8fafc;
}

/* BADGES */
.badge {
    display: inline-block;
    padding: 0.35em 0.8em;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
    color: #fff;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 9999px;
}

.status-approved,
.badge-approved {
    background-color: var(--success);
}

.status-rejected,
.badge-rejected {
    background-color: var(--danger);
}

.status-pending,
.badge-pending {
    background-color: var(--warning);
    color: #fff;
}

.status-pending-coo,
.badge-pending-coo {
    background-color: var(--accent);
}

.badge-success {
    background-color: var(--success);
}

.badge-danger {
    background-color: var(--danger);
}

/* ALERTS */
.alert {
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border-color: #bbf7d0;
}

.alert-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border-color: #fde68a;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: #fecaca;
}

/* LOGIN PAGE SPECIALS */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e40af 0%, #0f172a 100%);
    padding: 20px;
}

.login-card {
    background: white;
    padding: 3rem;
    border-radius: 1rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 450px;
    text-align: center;
}

.login-header h1 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-muted);
}


/* LOGIN SPLIT LAYOUT */
.login-body {
    background-color: #f8fafc;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-wrapper {
    display: flex;
    width: 100%;
    max-width: 1000px;
    height: 600px;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    margin: 20px;
}

.login-brand-side {
    flex: 1;
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
    padding: 60px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: white;
    position: relative;
    overflow: hidden;
}

.login-brand-side::before {
    content: '';
    position: absolute;
    top: -50px;
    left: -50px;
    width: 200px;
    height: 200px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
}

.login-brand-side::after {
    content: '';
    position: absolute;
    bottom: -50px;
    right: -50px;
    width: 300px;
    height: 300px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
}

.brand-content {
    position: relative;
    z-index: 10;
}

.brand-content h1 {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 20px;
    color: white;
    line-height: 1.1;
}

.brand-content p {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 40px;
    line-height: 1.6;
}

.login-form-side {
    flex: 1;
    padding: 60px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: #ffffff;
}

.login-header {
    text-align: left;
    margin-bottom: 40px;
}

.login-header h2 {
    font-size: 2rem;
    color: var(--text-main);
    margin-bottom: 10px;
}

.login-header p {
    color: var(--text-muted);
}

/* HERO SECTION FOR PORTALS */
.hero-section {
    background: linear-gradient(120deg, #1e40af, #2563eb);
    padding: 40px;
    border-radius: var(--radius);
    color: white;
    margin-bottom: 2rem;
    box-shadow: 0 10px 20px -5px rgba(37, 99, 235, 0.3);
    position: relative;
    overflow: hidden;
}

.hero-content {
    z-index: 2;
    padding-right: 120px;
}

.hero-title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 10px;
    color: white;
}

.hero-subtitle {
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.9);
    max-width: 600px;
}

.hero-decoration {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    font-size: 7rem;
    /* Reduced from 10rem to prevent overflow push */
    opacity: 0.1;
    pointer-events: none;
    overflow: hidden;
}

/* ATTENDANCE CALENDAR */
.calendar-container {
    padding: 1rem;
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
    background: #f8fafc;
    padding: 15px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.calendar-day-label {
    text-align: center;
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding-bottom: 5px;
    text-transform: uppercase;
}

.calendar-day {
    min-height: 100px;
    background: white;
    border-radius: 8px;
    padding: 8px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: all 0.2s ease;
}

.calendar-day:hover:not(.empty) {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    transform: translateY(-2px);
    border-color: var(--accent);
}

.calendar-day.empty {
    background: transparent;
    border: none;
}

.calendar-date {
    font-weight: 700;
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.calendar-punch {
    font-size: 0.65rem;
    padding: 2px 4px;
    border-radius: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.punch-in {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.punch-out {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
}

.status-perfect {
    border: 1px solid #bbf7d0;
    background: #f0fdf4;
}

.status-issue {
    border: 2px solid #ef4444;
    background: #fef2f2;
}

.calendar-legend {
    display: flex;
    gap: 1.5rem;
    margin-top: 1rem;
    font-size: 0.75rem;
    justify-content: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-box {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

/* SIDEBAR LAYOUT */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
    background-color: var(--bg-body);
    overflow-x: hidden;
    /* Prevent any child from causing horizontal scroll */
    width: 100%;
}

.sidebar {
    width: 260px;
    background-color: #1e293b;
    color: white;
    padding: 1.5rem 0;
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 1001;
    /* Above almost everything */
}

.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 2rem;
    min-width: 0;
    width: calc(100% - 260px);
    box-sizing: border-box;
    transition: all 0.3s ease;
    overflow-x: visible;
}

@media (max-width: 1400px) {
    .main-content {
        padding: 1.5rem;
    }
}

@media (max-width: 1200px) {
    .sidebar {
        width: 240px;
    }

    .main-content {
        margin-left: 240px;
        padding: 1rem;
    }
}



.sidebar-brand {
    padding: 0 1.5rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 0.5rem;
}

.sidebar-nav {
    list-style: none;
}

.nav-item {
    padding: 0.25rem 1rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.85rem 1rem;
    color: #94a3b8;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.nav-link.active {
    background: var(--accent);
    color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Shift Roster Styles */
.roster-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.roster-card {
    background: white;
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: box-shadow 0.2s;
}

.roster-card:hover {
    box-shadow: var(--shadow-md);
}

.roster-info {
    display: flex;
    flex-direction: column;
}

.roster-name {
    font-weight: 600;
    color: var(--text-main);
}

.roster-id {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.shift-selector {
    display: flex;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 6px;
    gap: 4px;
}

.shift-btn {
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-muted);
    transition: all 0.2s;
}

.shift-btn.active {
    background: white;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.shift-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.5);
}

/* Mobile Navigation Toggle */
.mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
}

/* Responsive Sidebar & Drawer */
@media (max-width: 768px) {
    .mobile-toggle {
        display: block;
    }

    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        z-index: 1000;
        width: 280px !important;
        transition: left 0.3s ease;
        display: block !important;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2);
    }

    .sidebar.active {
        left: 0;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 1rem;
        width: 100% !important;
        max-width: 100vw;
    }

    /* Overlay for mobile sidebar */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.active {
        display: block;
    }
}

/* MODAL STYLES (Added for Holiday Management) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    /* Hidden by default */
    justify-content: center;
    align-items: center;
    z-index: 2000;
    /* High z-index to cover sidebar (1001) */
    backdrop-filter: blur(2px);
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    position: relative;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.modal-header h3 {
    margin: 0;
    color: var(--text-main);
    font-size: 1.25rem;
}

.close-modal {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.close-modal:hover {
    color: var(--danger);
}

/* Role-based Visibility (Robust Fallback) */
body[data-super-admin="true"] .super-admin-only,
body[data-super-admin="true"] .sys-admin-only,
body[data-accrual-access="true"] .accrual-only {
    display: block !important;
}

body[data-super-admin="true"] #admin-tab-link {
    display: block !important;
}

/* -------------------------------------------------------------------------- */
/* MOBILE PORTRAIT ROTATION PROMPT */
/* -------------------------------------------------------------------------- */
#rotate-prompt {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #0f172a;
    /* Dark background */
    z-index: 99999;
    color: white;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
}

#rotate-prompt .icon {
    font-size: 4rem;
    margin-bottom: 20px;
    animation: rotatePhone 2s infinite ease-in-out;
}

#rotate-prompt h2 {
    color: #fff;
    margin-bottom: 15px;
    font-size: 1.5rem;
}

#rotate-prompt p {
    color: #cbd5e1;
    font-size: 1rem;
    line-height: 1.5;
    max-width: 300px;
}

@keyframes rotatePhone {
    0% {
        transform: rotate(0deg);
    }

    50% {
        transform: rotate(-90deg);
    }

    100% {
        transform: rotate(-90deg);
    }
}

/* Trigger on screens narrower than 768px in portrait mode AND are touch devices */
@media screen and (max-width: 768px) and (orientation: portrait) and (pointer: coarse) {
    #rotate-prompt {
        display: flex !important;
    }

    .login-wrapper {
        display: none !important;
    }
}

/* SWITCH TOGGLE (NOBS) */
.switch-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1;
  transition: .3s;
  border-radius: 24px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider {
  background-color: #10b981; /* Success Green for Active */
}

input:checked + .slider:before {
  transform: translateX(18px);
}

.slider.master-slider {
  background-color: #cbd5e1;
}

input:checked + .slider.master-slider {
  background-color: #0284c7; /* Sky Blue for Master Case */
}

.switch-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}