:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --border-focus: #3b82f6;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    margin: 0;
    padding: 0;
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------------------
   Navigation
--------------------------------------------------------------------------- */
nav {
    background: #0f172a;
    padding: 0.85rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    border-bottom: 1px solid #1e293b;
}

.nav-links {
    display: flex;
    gap: 1.25rem;
    align-items: center;
}

nav a {
    color: #94a3b8;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: color 0.15s ease;
}

nav a:hover {
    color: #ffffff;
}

.nav-user {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    font-size: 0.875rem;
}

.nav-username {
    background: #1e293b;
    color: #f1f5f9;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    border: 1px solid #334155;
}

.nav-btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: #1e293b;
    color: #cbd5e1;
    border: 1px solid #334155;
    padding: 0.3rem 0.65rem;
    border-radius: var(--radius-sm);
    font-size: 0.825rem;
    text-decoration: none;
    transition: all 0.15s ease;
}

.nav-btn-secondary:hover {
    background: #334155;
    color: #ffffff;
}

.nav-btn-logout {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: #ef4444;
    color: white;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.825rem;
    text-decoration: none;
    font-weight: 500;
    transition: background 0.15s ease;
}

.nav-btn-logout:hover {
    background: #dc2626;
}

/* ---------------------------------------------------------------------------
   Main Layout & Headers
--------------------------------------------------------------------------- */
main {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 2rem;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.page-header {
    margin-bottom: 1.75rem;
}

h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0 0 0.25rem 0;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0 0 0.5rem 0;
}

h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0;
}

.text-muted {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin: 0;
}

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

/* ---------------------------------------------------------------------------
   Forms (Label Left, Input Right occupying full space)
--------------------------------------------------------------------------- */
.card {
    background: var(--surface);
    padding: 1.75rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.form-card {
    width: 100%;
    max-width: none;
}

.form-grid {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    width: 100%;
}

.form-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 1.5rem;
    width: 100%;
}

.form-group label {
    width: 200px;
    min-width: 150px;
    flex-shrink: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: #334155;
    margin: 0;
    text-align: left;
    text-transform: none;
    letter-spacing: normal;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="time"],
.form-group select {
    flex: 1;
    width: 100%;
    min-width: 0;
    max-width: none;
    padding: 0.65rem 0.85rem;
    font-size: 0.95rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #ffffff;
    color: var(--text-main);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--border-focus);
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-main);
    font-weight: 500;
    text-transform: none;
    letter-spacing: normal;
    margin-left: 200px;
}

@media (max-width: 640px) {
    .form-group {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.4rem;
    }
    .form-group label {
        width: 100%;
    }
    .checkbox-label {
        margin-left: 0;
    }
}

.checkbox-label input[type="checkbox"] {
    width: 1.15rem;
    height: 1.15rem;
    cursor: pointer;
    accent-color: var(--primary);
    margin: 0;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 0.75rem;
    padding-left: 200px;
}

@media (max-width: 640px) {
    .form-actions {
        padding-left: 0;
    }
}

/* ---------------------------------------------------------------------------
   Buttons & Tooltips
--------------------------------------------------------------------------- */
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    font-weight: 500;
    font-size: 0.9rem;
    padding: 0.6rem 1.15rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    position: relative;
}

button:active {
    transform: translateY(1px);
}

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

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

.btn-secondary {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.btn-danger {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fca5a5;
}

.btn-danger:hover {
    background: #fecaca;
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.825rem;
    gap: 0.35rem;
}

.btn-icon {
    width: 1.05em;
    height: 1.05em;
    flex-shrink: 0;
    stroke-width: 2.2;
    stroke: currentColor;
    fill: none;
    display: inline-block;
    vertical-align: middle;
}

button:disabled,
.btn-disabled {
    opacity: 0.55;
    cursor: not-allowed !important;
    pointer-events: auto;
    background: #e2e8f0 !important;
    color: #64748b !important;
    border-color: #cbd5e1 !important;
    box-shadow: none !important;
    transform: none !important;
}

/* Tooltip implementation */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::before {
    content: "";
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    border-width: 5px;
    border-style: solid;
    border-color: #0f172a transparent transparent transparent;
    opacity: 0;
    visibility: hidden;
    display: none;
    pointer-events: none;
    z-index: 1001;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: #0f172a;
    color: #f8fafc;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: normal;
    text-transform: none;
    white-space: nowrap;
    padding: 0.35rem 0.65rem;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    display: none;
    z-index: 1000;
}

[data-tooltip]:hover::before,
[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::before,
[data-tooltip]:focus-visible::after {
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Tooltips near right edge or in table last column */
td:last-child [data-tooltip]::after,
.data-table td:last-child [data-tooltip]::after,
.filter-actions [data-tooltip]:last-child::after {
    left: auto;
    right: 0;
    transform: translateY(4px);
}
td:last-child [data-tooltip]:hover::after,
.data-table td:last-child [data-tooltip]:hover::after,
.filter-actions [data-tooltip]:last-child:hover::after {
    transform: translateY(0);
}

td:last-child [data-tooltip]::before,
.data-table td:last-child [data-tooltip]::before,
.filter-actions [data-tooltip]:last-child::before {
    left: auto;
    right: 12px;
    transform: translateY(4px);
}
td:last-child [data-tooltip]:hover::before,
.data-table td:last-child [data-tooltip]:hover::before,
.filter-actions [data-tooltip]:last-child:hover::before {
    transform: translateY(0);
}

/* ---------------------------------------------------------------------------
   Tables
--------------------------------------------------------------------------- */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-top: 1rem;
    background: white;
    scrollbar-width: thin;
}

.data-table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    margin: 0;
}

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

.data-table th:last-child,
.data-table td:last-child {
    text-align: right;
    white-space: nowrap;
}

.data-table th {
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

.data-table td input[type="time"] {
    width: 110px;
    padding: 0.35rem 0.5rem;
    font-size: 0.875rem;
    text-align: center;
}

.font-mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-weight: 600;
}

/* ---------------------------------------------------------------------------
   Records Filter & Employee Tabs
--------------------------------------------------------------------------- */
.filter-card {
    width: 100%;
    max-width: none;
}

.records-filter-form {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 1.25rem;
    flex-wrap: wrap;
    width: 100%;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 130px;
}

.filter-group:nth-child(2) {
    min-width: 180px;
}

.filter-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    margin: 0;
}

.filter-group input,
.filter-group select {
    width: 100%;
    padding: 0.625rem 0.85rem;
    font-size: 0.95rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #ffffff;
    color: var(--text-main);
}

.filter-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 0;
    padding-left: 0;
}

@media (max-width: 768px) {
    .records-filter-form {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }
    .filter-group {
        width: 100%;
        min-width: 0;
    }
    .filter-actions {
        width: 100%;
        padding-left: 0;
    }
}

.records-section {
    margin-top: 1.75rem;
}

.worker-select-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.worker-select-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-main);
}

.worker-select-input {
    min-width: 280px;
    max-width: 400px;
    padding: 0.55rem 0.85rem;
    font-size: 0.95rem;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #ffffff;
    color: var(--text-main);
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.worker-select-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.tabs-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.tabs-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.tabs-list {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tab-btn {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.45rem 1rem;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.tab-btn:hover {
    background: #e2e8f0;
    color: var(--text-main);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.25);
}

.tab-content-card {
    padding: 1.5rem;
}

.worker-meta-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.25rem;
}

.worker-meta-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.meta-tag {
    background: #f1f5f9;
    color: #475569;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.825rem;
    font-weight: 500;
    border: 1px solid var(--border);
}

.worker-meta-actions {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.record-summary-bar {
    display: flex;
    gap: 1.5rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.summary-card {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.summary-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

.summary-value {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
}

.summary-value.highlight {
    color: #d97706;
}

/* ---------------------------------------------------------------------------
   Dashboard KPI & Stats
--------------------------------------------------------------------------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.2rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card:hover {
    box-shadow: var(--shadow-md);
}

.kpi-icon-wrapper {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-icon {
    width: 24px;
    height: 24px;
}

.kpi-icon-blue { background: #eff6ff; color: #2563eb; }
.kpi-icon-emerald { background: #ecfdf5; color: #059669; }
.kpi-icon-amber { background: #fffbeb; color: #d97706; }
.kpi-icon-purple { background: #f5f3ff; color: #7c3aed; }

.kpi-content {
    display: flex;
    flex-direction: column;
}

.kpi-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    margin-bottom: 0.2rem;
}

.kpi-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.1;
}

.kpi-value.highlight {
    color: #d97706;
}

.kpi-subtext {
    font-size: 0.775rem;
    color: #64748b;
    margin-top: 0.25rem;
}

.avatar-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.avatar-pill {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: #ffffff;
    font-weight: 700;
    font-size: 0.825rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    letter-spacing: 0.05em;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.progress-container {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 140px;
}

.progress-bar-bg {
    flex: 1;
    height: 8px;
    background: #e2e8f0;
    border-radius: 9999px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 9999px;
    transition: width 0.3s ease;
}

.progress-percent {
    font-size: 0.8rem;
    font-weight: 600;
    color: #475569;
    min-width: 38px;
    text-align: right;
}

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

/* ---------------------------------------------------------------------------
   Badges & Alerts
--------------------------------------------------------------------------- */
.badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.025em;
}

.badge-admin {
    background: #e0e7ff;
    color: #3730a3;
}

.badge-user {
    background: #f1f5f9;
    color: #475569;
}

.badge-warn {
    background: #fef3c7;
    color: #92400e;
}

.badge-ok {
    background: #dcfce7;
    color: #166534;
}

.error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin: 1rem 0;
    font-size: 0.9rem;
    width: 100%;
    max-width: none;
}

.success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #15803d;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin: 1rem 0;
    font-size: 0.9rem;
    width: 100%;
    max-width: none;
}

.error:empty,
.success:empty {
    display: none;
    margin: 0;
    padding: 0;
}

/* ---------------------------------------------------------------------------
   Auth pages
--------------------------------------------------------------------------- */
.auth-container {
    max-width: 480px;
    margin: 3rem auto;
}

.auth-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.auth-subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.auth-form .form-group label {
    width: 140px;
    min-width: 120px;
}

.notice-box {
    background: #eff6ff;
    border-left: 4px solid var(--primary);
    padding: 0.85rem 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    color: #1e40af;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.hidden {
    display: none !important;
}

/* Latest period badge / info */
.latest-period-badge,
.latest-period-info {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    background: #f1f5f9;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    margin-top: 0.75rem;
    border: 1px solid var(--border);
}

.latest-period-badge strong,
.latest-period-info strong {
    color: var(--text-main);
    font-weight: 600;
}

.latest-period-badge .badge-icon,
.latest-period-badge .period-icon,
.latest-period-info .period-icon {
    color: var(--primary);
    flex-shrink: 0;
}

.btn-link-action {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.8125rem;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
    margin-left: 0.5rem;
    transition: color 0.15s ease;
}

.btn-link-action:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* ---------------------------------------------------------------------------
   Modals
--------------------------------------------------------------------------- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 1.5rem;
}

.modal-card {
    background: #ffffff;
    border-radius: var(--radius-md);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-card.modal-lg {
    max-width: 850px;
}

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

.modal-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    padding: 0.25rem;
}

.modal-close:hover {
    color: #0f172a;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}
