/* Logistack Employee Portal - shared styles.
 * Compact & sharp: square corners, violet primary, slate neutrals.
 * Tokens live on :root; React pages (src/components) read the same variables. */

*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    /* Brand (violet). #7c3aed is the action color: white text on it is 5.7:1 (AA). */
    --primary: #7c3aed;
    --primary-dark: #6d28d9;
    --primary-light: #ede9fe;
    --primary-tint: #f5f3ff;
    --primary-ink: #4c1d95;

    /* Neutrals */
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --bg-subtle: #f8fafc;
    --text-main: #1e293b;
    --text-strong: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --border-strong: #cbd5e1;

    /* Status */
    --success: #047857;
    --success-bg: #ecfdf5;
    --success-border: #a7f3d0;
    --warning: #92400e;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;
    --danger: #b91c1c;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --info: #1d4ed8;
    --info-bg: #eff6ff;
    --info-border: #bfdbfe;

    /* Legacy alias (used by older markup) */
    --secondary: var(--success);

    --shadow-sm: 0 1px 2px 0 rgb(15 23 42 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(15 23 42 / 0.08), 0 2px 4px -2px rgb(15 23 42 / 0.06);
    --shadow-lg: 0 24px 48px -12px rgb(15 23 42 / 0.35);

    --sidebar-w: 248px;
    --ease: cubic-bezier(0.25, 1, 0.5, 1);
}

/* Set the base line-height explicitly. The React pages load Tailwind, whose
   preflight sets html { line-height: 1.5 }; the PHP pages don't, so without
   this every element (e.g. sidebar items) was ~10% taller on React pages and
   the sidebar visibly shifted when switching pages. */
html {
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    /* Always reserve the scrollbar's space, so content doesn't jump sideways
       between short pages (no scrollbar) and long ones (classic Windows scrollbar). */
    scrollbar-gutter: stable;
}

body {
    line-height: inherit;
    font-family: 'Outfit', 'Inter', system-ui, sans-serif;
    background: var(--bg-body);
    color: var(--text-main);
    min-height: 100vh;
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    margin: 0;
    color: var(--text-strong);
    text-wrap: balance;
}

p {
    margin: 0;
}

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.num {
    font-family: 'Inter', system-ui, sans-serif;
    font-variant-numeric: tabular-nums;
}

.icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.btn-sm .icon {
    width: 15px;
    height: 15px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------------------------------------------------------------- Layout */

.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    min-width: 0;
    /* let wide children (calendars, tables) scroll inside instead of widening the page */
    margin-left: var(--sidebar-w);
    padding: 1.5rem 2rem;
}

/* ---------------------------------------------------------------- Sidebar */

.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    padding: 1.25rem 0.875rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
}

.logo-area {
    padding: 0 0.625rem 1.5rem;
}

.logo-area img {
    height: 34px;
    width: auto;
    display: block;
}

.nav-links {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-height: 0;
}

.nav-section {
    margin: 1rem 0.625rem 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    color: #475569;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.nav-item .icon {
    color: #94a3b8;
    transition: color 0.15s var(--ease);
}

.nav-item:hover {
    background: var(--bg-subtle);
    color: var(--text-strong);
}

.nav-item:hover .icon {
    color: var(--text-muted);
}

.nav-item.active {
    background: var(--primary-tint);
    color: var(--primary-ink);
    font-weight: 600;
}

.nav-item.active .icon {
    color: var(--primary);
}

.nav-external {
    margin-left: auto;
    width: 14px;
    height: 14px;
    color: #94a3b8;
}

/* Legacy emoji span support */
.nav-icon {
    margin-right: 0.75rem;
    font-size: 1.1rem;
}

.sidebar-user {
    border-top: 1px solid var(--border-color);
    margin-top: 0.75rem;
    padding: 0.875rem 0.625rem 0;
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary-ink);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8125rem;
    flex-shrink: 0;
}

.sidebar-user-text {
    min-width: 0;
    flex: 1;
    line-height: 1.3;
}

.sidebar-user-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-strong);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-email {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logout-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    color: var(--text-muted);
    text-decoration: none;
    transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.logout-btn:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

/* Mobile top bar (hidden on desktop) */
.mobile-bar {
    display: none;
}

.sidebar-scrim {
    display: none;
}

/* ---------------------------------------------------------------- Page header */

.header-section {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.header-section h1,
.header-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-strong);
    letter-spacing: -0.01em;
    margin: 0;
}

.header-subtitle {
    color: var(--text-muted);
    font-size: 0.9375rem;
    margin-top: 0.25rem;
}

/* ---------------------------------------------------------------- Surfaces */

.section-container,
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.section-container.flush,
.card.flush {
    padding: 0;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.section-container.flush .section-header {
    padding: 1.125rem 1.5rem 0;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--text-strong);
    margin: 0;
}

.section-title .icon {
    color: var(--primary);
}

.section-meta {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* ---------------------------------------------------------------- Buttons */

.btn,
.btn-primary,
.btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 40px;
    padding: 0 1.125rem;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}

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

.btn:disabled,
.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-block {
    width: 100%;
}

.btn-sm,
.btn-action {
    height: 34px;
    padding: 0 0.875rem;
    font-size: 0.8125rem;
}

.btn-outline,
.btn.btn-outline,
.btn-action.btn-outline {
    background: var(--bg-card) !important;
    border-color: var(--border-color);
    color: #334155;
}

.btn-outline:hover,
.btn.btn-outline:hover,
.btn-action.btn-outline:hover {
    background: var(--bg-subtle) !important;
    border-color: var(--border-strong);
    color: var(--text-strong);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: #334155;
}

.btn-ghost:hover {
    background: var(--bg-subtle);
    border-color: transparent;
    color: var(--text-strong);
}

.btn-danger {
    background: var(--bg-card);
    border-color: var(--danger-border);
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-bg);
    border-color: var(--danger);
    color: var(--danger);
}

/* ---------------------------------------------------------------- Forms */

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

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

.form-group label,
.form-label {
    display: block;
    color: #334155;
    font-weight: 600;
    margin-bottom: 0.375rem;
    font-size: 0.8125rem;
}

.form-control,
.form-group input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.form-group select,
.form-group textarea {
    width: 100%;
    min-height: 40px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-strong);
    background: var(--bg-card);
    color: var(--text-strong);
    font: inherit;
    font-size: 0.9375rem;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.form-group textarea {
    resize: vertical;
    line-height: 1.5;
}

.form-control:focus,
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-control[aria-invalid="true"] {
    border-color: var(--danger);
}

.form-hint {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 0.375rem;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

/* Password field with show/hide toggle */
.input-with-action {
    position: relative;
}

.input-with-action .form-control,
.input-with-action input {
    padding-right: 3rem !important;
}

.input-action {
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    border: 0;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-action:hover {
    color: var(--text-strong);
}

.input-action .eye-off,
.input-action[aria-pressed="true"] .eye-on {
    display: none;
}

.input-action[aria-pressed="true"] .eye-off {
    display: block;
}

.field-error {
    font-size: 0.8125rem;
    color: var(--danger);
    margin-top: 0.375rem;
}

/* ---------------------------------------------------------------- Read-only info */

.info-group {
    margin-bottom: 1.125rem;
}

.info-group:last-child {
    margin-bottom: 0;
}

.info-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    margin-bottom: 0.125rem;
}

.info-value {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-strong);
}

/* ---------------------------------------------------------------- Stats */

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 1px;
    background: var(--border-color);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.125rem 1.25rem;
}

.stat-label {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.stat-value {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-strong);
}

/* ---------------------------------------------------------------- Tables */

.table-responsive {
    overflow-x: auto;
    position: relative; /* contains .sr-only header labels so they cannot widen the page */
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th {
    text-align: left;
    padding: 0.625rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

td {
    padding: 0.8125rem 1rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
    vertical-align: middle;
    color: var(--text-main);
}

tr:last-child td {
    border-bottom: none;
}

tbody tr:hover td {
    background: var(--bg-subtle);
}

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

.table-empty {
    text-align: center;
    padding: 2.5rem 1rem !important;
    color: var(--text-muted);
}

.table-empty strong {
    display: block;
    color: var(--text-main);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

/* ---------------------------------------------------------------- Badges */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.1875rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge-blue,
.badge-info {
    background: var(--info-bg);
    color: var(--info);
    border-color: var(--info-border);
}

.badge-active,
.badge-success {
    background: var(--success-bg);
    color: var(--success);
    border-color: var(--success-border);
}

.badge-warning,
.badge-pending {
    background: var(--warning-bg);
    color: var(--warning);
    border-color: var(--warning-border);
}

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

.badge-archived,
.badge-neutral {
    background: var(--bg-subtle);
    color: #475569;
    border-color: var(--border-color);
}

/* ---------------------------------------------------------------- Alerts */

.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    border: 1px solid transparent;
}

.alert .icon {
    margin-top: 1px;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border-color: var(--success-border);
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: var(--danger-border);
}

.alert-info {
    background: var(--info-bg);
    color: var(--info);
    border-color: var(--info-border);
}

/* ---------------------------------------------------------------- Empty state */

.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.empty-state .icon {
    width: 28px;
    height: 28px;
    color: #94a3b8;
    margin: 0 auto 0.75rem;
    display: block;
}

.empty-state strong {
    display: block;
    color: var(--text-main);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

/* ---------------------------------------------------------------- Modal (legacy pages) */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgb(15 23 42 / 0.45);
    z-index: 500;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
    animation: portal-fade 0.15s var(--ease);
}

.modal-content {
    background: var(--bg-card);
    padding: 1.5rem;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

.modal.active .modal-content {
    animation: portal-in 0.18s var(--ease);
}

.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.modal-head h2 {
    font-size: 1.125rem;
    font-weight: 700;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: 0;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: var(--bg-body);
    color: var(--text-strong);
}

/* ---------------------------------------------------------------- Auth pages (login / change password) */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    padding: 2.25rem 2rem 2rem;
}

.auth-logo {
    height: 36px;
    width: auto;
    display: block;
    margin-bottom: 1.75rem;
}

.auth-card h1 {
    font-size: 1.375rem;
    font-weight: 700;
    margin-bottom: 0.375rem;
}

.auth-card .auth-sub {
    color: var(--text-muted);
    font-size: 0.9375rem;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.auth-foot {
    margin-top: 1.25rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-align: center;
}

/* ---------------------------------------------------------------- Motion */

@keyframes portal-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes portal-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

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

/* ---------------------------------------------------------------- Responsive */

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

@media (max-width: 768px) {
    .main-content {
        margin-left: 0;
        padding: 1rem;
    }

    .mobile-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        position: sticky;
        top: 0;
        z-index: 30;
        background: var(--bg-card);
        border-bottom: 1px solid var(--border-color);
        padding: 0.5rem 0.75rem;
    }

    .mobile-bar img {
        height: 26px;
        width: auto;
    }

    .mobile-menu-btn {
        width: 40px;
        height: 40px;
        border: 1px solid var(--border-color);
        background: var(--bg-card);
        color: var(--text-strong);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s var(--ease);
        box-shadow: none;
        z-index: 600;
    }

    body.nav-open .sidebar {
        transform: none;
        box-shadow: var(--shadow-lg);
    }

    body.nav-open .sidebar-scrim {
        display: block;
        position: fixed;
        inset: 0;
        background: rgb(15 23 42 / 0.45);
        z-index: 590;
    }

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