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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: #f5f7fa;
    color: #1f2937;
    min-height: 100vh;
    line-height: 1.5;
    overflow-x: auto;
}

.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;
}

.sr-only:focus,
.sr-only:focus-visible {
    width: auto;
    height: auto;
    margin: 0;
    clip: auto;
    white-space: normal;
    left: 12px;
    top: 12px;
    z-index: 1000;
    padding: 8px 12px;
    background: #ffffff;
    color: #1d4ed8;
    border: 2px solid #2563eb;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.12);
}

:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

button,
[role="button"],
input,
select,
textarea,
a {
    touch-action: manipulation;
}

button,
[role="button"],
.btn,
.btn-sm,
.navbar-brand,
.navbar-link,
.navbar-logout-button,
.role-badge,
.admin-nav a {
    min-height: 44px;
}

button,
[role="button"],
.btn,
.btn-sm {
    min-width: 44px;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]),
select,
textarea {
    min-height: 44px;
}

input[type="checkbox"],
input[type="radio"] {
    width: 44px;
    height: 44px;
    cursor: pointer;
}
h2 { font-size: 1.5rem; font-weight: 700; color: #1f2937; margin-bottom: 0.75rem; }
h3 { font-size: 1.15rem; font-weight: 600; color: #1f2937; margin-bottom: 0.5rem; }

a {
    color: #2563eb;
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

.container > p > a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
}

/* ===== Nav ===== */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #ffffff;
    padding: 0 1.5rem;
    height: 56px;
    border-bottom: 1px solid #e5e7eb;
    position: relative;
    z-index: 200;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.navbar-brand {
    font-size: 1.15rem;
    font-weight: 700;
    color: #2563eb;
    letter-spacing: 1px;
    text-transform: uppercase;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}
.navbar-brand:hover {
    text-decoration: none;
    opacity: 0.9;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
}

.navbar-link {
    color: #6b7280;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 4px 12px;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.15s;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}
.navbar-link:hover {
    color: #2563eb;
    background: #eff6ff;
    text-decoration: none;
}
.navbar-link.active {
    color: #2563eb;
    background: #eff6ff;
}

.navbar-logout {
    margin: 0;
    display: inline;
}

.navbar-logout-button {
    border: 0;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    color: #6b7280;
    font-size: 0.85rem;
    padding: 0;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.navbar-logout-button:hover {
    color: #2563eb;
}

.navbar-user {
    color: #4b5563;
}

.role-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.role-badge.admin {
    background-color: #2563eb;
    color: #fff;
}
.role-badge.employee {
    background-color: #e5e7eb;
    color: #6b7280;
}

.navbar-right a {
    color: #6b7280;
    font-size: 0.85rem;
}
.navbar-right a:hover {
    color: #2563eb;
}
.navbar-right a.role-badge.admin,
.navbar-right a.role-badge.admin:hover,
.navbar-right a.role-badge.admin:active,
.navbar-right a.role-badge.admin:visited {
    color: #fff;
    text-decoration: none;
}

/* ===== Flash Messages ===== */
.flash-container {
    max-width: 800px;
    margin: 1rem auto 0;
    padding: 0 1rem;
}

.flash-msg {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}
.flash-msg.success {
    background-color: #ecfdf5;
    border: 1px solid #10b981;
    color: #065f46;
}
.flash-msg.error {
    background-color: #fef2f2;
    border: 1px solid #ef4444;
    color: #991b1b;
}
.flash-msg.info {
    background-color: #eff6ff;
    border: 1px solid #3b82f6;
    color: #1e40af;
}

/* ===== Container / Card ===== */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.card {
    background-color: #ffffff;
    border-radius: 10px;
    padding: 2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    border: 1px solid #e5e7eb;
}

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

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-control {
    width: 100%;
    padding: 0.7rem 0.9rem;
    background-color: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    color: #1f2937;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.form-control::placeholder {
    color: #9ca3af;
}

.file-input-native {
    position: absolute;
    width: 44px;
    height: 44px;
    opacity: 0;
    pointer-events: none;
}

.file-picker {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.file-picker-button {
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #374151;
    border-radius: 6px;
    padding: 8px 12px;
    min-height: 44px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.file-picker-clear {
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #991b1b;
    border-radius: 6px;
    padding: 8px 12px;
    min-height: 44px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.file-picker-button:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.file-picker-status {
    color: #6b7280;
    font-size: 13px;
    overflow-wrap: anywhere;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    text-align: center;
}
.btn:active {
    transform: scale(0.98);
}
.btn:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background-color: #2563eb;
    color: #fff;
}
.btn-block {
    width: 100%;
}
.btn-primary:hover {
    background-color: #1d4ed8;
}

.btn-secondary {
    background-color: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}
.btn-secondary:hover {
    background-color: #e5e7eb;
}

.btn-danger {
    background-color: #ef4444;
    color: #fff;
}

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

/* ===== Central UI Dialogs / Toasts ===== */
.ui-dialog-open {
    overflow: hidden;
}

.ui-dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.48);
}

.ui-dialog-overlay.is-open {
    display: flex;
}

.ui-dialog {
    width: min(460px, 100%);
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 22px;
    box-shadow: 0 24px 56px rgba(15, 23, 42, 0.22);
}

.ui-dialog-title {
    margin: 0 0 8px;
    color: #111827;
    font-size: 1.15rem;
}

.ui-dialog-message {
    margin: 0;
    color: #4b5563;
    line-height: 1.5;
    white-space: pre-line;
}

.ui-dialog-field {
    display: grid;
    gap: 6px;
    margin-top: 16px;
    color: #374151;
    font-size: 0.9rem;
    font-weight: 600;
}

.ui-dialog-input,
.ui-dialog-copy-field {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
}

.ui-dialog-copy-field {
    min-height: 120px;
    margin-top: 16px;
    resize: vertical;
}

.ui-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
    flex-wrap: wrap;
}

.ui-toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 5200;
    max-width: min(380px, calc(100vw - 40px));
    padding: 12px 16px;
    border-radius: 8px;
    color: #ffffff;
    background: #1f2937;
    font-size: 0.9rem;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.2);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s;
}

.ui-toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.ui-toast-success {
    background: #047857;
}

.ui-toast-error {
    background: #b91c1c;
}

/* ===== Login Page ===== */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    background-color: #f5f7fa;
}

.login-card {
    width: 100%;
    max-width: 400px;
}

.login-brand {
    text-align: center;
    margin-bottom: 2rem;
}
.login-brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #2563eb;
    letter-spacing: 2px;
    text-transform: uppercase;
}
.login-brand p {
    color: #6b7280;
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* ===== Utility ===== */
.text-center { text-align: center; }
.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; }

/* ===== Admin Nav ===== */
.admin-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 20px;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 10px;
    overflow-x: visible;
    white-space: normal;
}

.admin-nav a {
    flex: 0 0 auto;
    padding: 8px 16px;
    border-radius: 6px;
    color: #6b7280;
    font-size: 14px;
    text-decoration: none;
    transition: all 0.2s;
}

.admin-nav a:hover {
    background: #f3f4f6;
    color: #1f2937;
    text-decoration: none;
}

.admin-nav a.active {
    background: #eff6ff;
    color: #2563eb;
}

.admin-nav a.back-link {
    color: #374151;
    margin-right: 8px;
    padding-right: 16px;
    border-right: 1px solid #e5e7eb;
}

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.stat-card {
    background: #ffffff;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.stat-number {
    font-size: 28px;
    font-weight: 700;
    color: #2563eb;
}

.stat-label {
    font-size: 12px;
    color: #6b7280;
    text-transform: uppercase;
    margin-top: 4px;
}

/* ===== Admin Table ===== */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.admin-table th {
    background: #f9fafb;
    color: #6b7280;
    text-transform: uppercase;
    font-size: 11px;
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.admin-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
}

.admin-table tr:hover td {
    background: #f9fafb;
}

.card details > summary,
.admin-table details > summary {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 4px 6px;
    border-radius: 6px;
}

.card details > summary:hover,
.admin-table details > summary:hover {
    background: #f3f4f6;
}

/* ===== Table Pagination ===== */
.table-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 0;
    margin-top: 4px;
}
.table-pagination .pg-info {
    font-size: 13px;
    color: #6b7280;
    min-width: 120px;
    text-align: center;
}
.table-pagination .btn-sm {
    cursor: pointer;
}
.table-pagination .btn-sm:disabled {
    opacity: 0.4;
    cursor: default;
}

/* ===== Status Badges ===== */
.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.processing {
    background: #fefce8;
    color: #a16207;
}

.status-badge.ready {
    background: #ecfdf5;
    color: #059669;
}

.status-badge.ok {
    background: #ecfdf5;
    color: #059669;
}

.status-badge.warning {
    background: #fff7ed;
    color: #c2410c;
}

.status-badge.error {
    background: #fef2f2;
    color: #dc2626;
}

.status-badge.unavailable {
    background: #fef2f2;
    color: #dc2626;
}

/* ===== Small Buttons ===== */
.btn-sm {
    padding: 8px 12px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    line-height: 1.2;
    text-decoration: none;
}

.btn-sm.btn-primary {
    background: #eff6ff;
    color: #2563eb;
    border: 1px solid #bfdbfe;
}

.btn-sm.btn-primary:hover {
    background: #dbeafe;
}

.btn-sm.btn-danger {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.btn-sm.btn-danger:hover {
    background: #fee2e2;
}

.btn-sm.btn-success {
    background: #ecfdf5;
    color: #059669;
    border: 1px solid #a7f3d0;
}

.btn-sm.btn-success:hover {
    background: #d1fae5;
}

.btn-sm.btn-edit {
    background: #eff6ff;
    color: #2563eb;
    border: 1px solid #bfdbfe;
}

.btn-sm.btn-edit:hover {
    background: #dbeafe;
}

/* ===== Facts ===== */
.facts-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.fact-card {
    background: #ffffff;
    border-radius: 8px;
    padding: 14px;
    border: 1px solid #e5e7eb;
}

.fact-card.unverified {
    border-left: 3px solid #d97706;
}

.fact-card.verified {
    border-left: 3px solid #059669;
}

.fact-type {
    font-size: 11px;
    text-transform: uppercase;
    color: #6b7280;
    margin-bottom: 4px;
}

.fact-content {
    color: #374151;
    font-size: 14px;
    margin-bottom: 6px;
}

.fact-parts {
    font-size: 13px;
    color: #2563eb;
    margin-bottom: 8px;
}

.fact-actions {
    display: flex;
    gap: 8px;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    /* Navbar */
    .navbar {
        padding: 0 0.75rem;
        height: auto;
        min-height: 56px;
        flex-wrap: wrap;
        gap: 4px;
    }
    .navbar-brand {
        font-size: 0.95rem;
    }
    .navbar-right {
        gap: 0.5rem;
        font-size: 0.8rem;
    }
    .navbar-user {
        display: none;
    }
    .role-badge {
        font-size: 0.65rem;
        padding: 2px 6px;
    }

    /* Admin nav */
    .admin-nav {
        flex-wrap: wrap;
        gap: 2px;
        white-space: normal;
    }
    /* Admin tables scroll on mobile */
    .admin-table {
        display: table;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .admin-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -0.75rem;
        padding: 0 0.75rem;
    }
    /* Stats grid: 2 cols on very small */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .admin-nav a {
        font-size: 12px;
        padding: 8px 10px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    /* Container */
    .container {
        padding: 1rem 0.75rem;
    }

    /* Admin tables - small text on mobile */
    .admin-table {
        font-size: 12px;
    }
    .admin-table th,
    .admin-table td {
        padding: 6px 8px;
    }
    .stat-number {
        font-size: 22px;
    }
}

@media (max-width: 720px) {
    .btn,
    .btn-sm,
    .navbar-link,
    .navbar-logout-button {
        min-height: 44px;
    }

    .admin-table {
        display: block;
        width: 100%;
        border-collapse: separate;
        border-spacing: 0;
        font-size: 13px;
    }

    .admin-table thead {
        display: none;
    }

    .admin-table tbody,
    .admin-table tr,
    .admin-table td {
        display: block;
        width: 100%;
    }

    .admin-table tr {
        margin-bottom: 12px;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        background: #ffffff;
        overflow: hidden;
        box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    }

    .admin-table tr:hover td {
        background: #ffffff;
    }

    .admin-table td {
        display: grid;
        grid-template-columns: minmax(96px, 38%) minmax(0, 1fr);
        gap: 10px;
        align-items: start;
        padding: 10px 12px;
        border-bottom: 1px solid #f3f4f6;
        overflow-wrap: anywhere;
    }

    .admin-table td:last-child {
        border-bottom: 0;
    }

    .admin-table td::before {
        content: attr(data-label);
        color: #6b7280;
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }

    .admin-table td[colspan] {
        display: block;
    }

    .admin-table td[colspan]::before,
    .admin-table td:not([data-label])::before,
    .admin-table td[data-label=""]::before {
        content: none;
    }

    .admin-table td form {
        display: flex !important;
        flex-wrap: wrap;
        gap: 6px;
    }

    .admin-table td .btn-sm,
    .admin-table td button,
    .admin-table td a {
        margin: 2px 4px 2px 0;
    }

    .flash-container {
        margin-top: 0.75rem;
    }

    .flash-msg {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
    }
}
