:root {
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1c2333;
    --text-muted: #667085;
    --border: #e4e7ec;
    --primary: #4338ca;
    --primary-hover: #3730a3;
    --primary-light: #eef2ff;
    --success: #067647;
    --success-bg: #ecfdf3;
    --warning: #b54708;
    --warning-bg: #fffaeb;
    --danger: #b42318;
    --danger-bg: #fef3f2;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* ---------- Login page ---------- */

.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at 15% 20%, rgba(67, 56, 202, 0.16), transparent 45%),
        radial-gradient(circle at 85% 80%, rgba(6, 118, 71, 0.12), transparent 45%),
        var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 40px 36px;
    border: 1px solid var(--border);
}

.auth-logo {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), #6366f1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 20px;
    margin-bottom: 20px;
}

.auth-card h1 {
    font-size: 20px;
    margin: 0 0 6px;
}

.auth-card p.subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0 0 28px;
}

/* ---------- Shared form elements ---------- */

.field { margin-bottom: 18px; }

.field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.field .hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

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

textarea { resize: vertical; min-height: 70px; }

.field .check {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
}

.field .check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-top: 1px;
    accent-color: var(--primary);
    flex: 0 0 auto;
}

.field .check .check-desc {
    display: block;
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
    margin-top: 2px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 11px 16px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    width: auto;
}
.btn-secondary:hover { background: #f9fafb; }

/* ---------- Dashboard shell ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 20px;
    padding: 14px 28px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 15px;
}

.topbar .brand .badge {
    width: 32px; height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), #6366f1);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
}

.topbar .who {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 13px;
    color: var(--text-muted);
}

.navlinks {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1 1 auto;
    overflow-x: auto;
    order: 3;
    width: 100%;
}

@media (min-width: 900px) {
    .navlinks { order: 2; width: auto; }
}

.navlinks a {
    flex: 0 0 auto;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.navlinks a:hover { background: var(--primary-light); color: var(--primary); }
.navlinks a.active { background: var(--primary); color: #fff; }

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 32px 24px 80px;
}

.page-title {
    margin: 0 0 4px;
    font-size: 22px;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0 0 28px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card h2 {
    font-size: 15px;
    margin: 0 0 18px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px 18px;
}

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

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 14px 16px;
    align-items: end;
}

.filter-grid .field { margin-bottom: 0; }

.filter-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 18px;
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.btn-inline {
    width: auto;
    padding: 9px 16px;
}

.btn-sm {
    width: auto;
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 8px;
}

.btn-ghost {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary-light);
}
.btn-ghost:hover { background: var(--primary-light); }

/* ---------- Dropzone ---------- */

.dropzone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 28px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    background: #fafbfe;
}

.dropzone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.dropzone .icon { font-size: 28px; margin-bottom: 8px; }
.dropzone .main-text { font-weight: 600; font-size: 14px; }
.dropzone .sub-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.dropzone input[type="file"] { display: none; }

.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    padding: 6px 12px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
}

.file-chip button {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0;
}

/* ---------- Results ---------- */

.stat-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

@media (max-width: 640px) {
    .stat-row { grid-template-columns: repeat(2, 1fr); }
}

.stat {
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    border: 1px solid var(--border);
}

.stat .num { font-size: 24px; font-weight: 700; }
.stat .label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.stat.applied { background: var(--success-bg); }
.stat.applied .num { color: var(--success); }
.stat.skipped { background: var(--warning-bg); }
.stat.skipped .num { color: var(--warning); }
.stat.errors { background: var(--danger-bg); }
.stat.errors .num { color: var(--danger); }
.stat.total { background: var(--primary-light); }
.stat.total .num { color: var(--primary); }

table.result-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

table.result-table th {
    text-align: left;
    padding: 8px 10px;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}

table.result-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

.table-wrap {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-top: 10px;
}

.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.tag.ac { background: var(--success-bg); color: var(--success); }
.tag-success { background: var(--success-bg); color: var(--success); }
.tag-warning { background: var(--warning-bg); color: var(--warning); }
.tag-danger  { background: var(--danger-bg); color: var(--danger); }
.tag-info    { background: var(--primary-light); color: var(--primary); }
.tag-muted   { background: #f2f4f7; color: var(--text-muted); }

.empty-hint {
    color: var(--text-muted);
    font-size: 13px;
    padding: 10px 2px;
}

.error-banner {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #fda29b;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 16px;
}

.hint-banner {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid #c7d2fe;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 16px;
}

/* ---------- Pagination ---------- */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 16px;
    font-size: 13px;
    color: var(--text-muted);
}

/* ---------- Code / CSV template display ---------- */

.code-block {
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 10px;
    padding: 14px 16px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 12.5px;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre;
    margin: 0;
}

.code-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin: 14px 0 6px;
}
.code-label:first-child { margin-top: 0; }

/* ---------- Column spec list (upload format) ---------- */

.col-spec {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    margin-top: 10px;
}

.col-spec-row {
    display: flex;
    gap: 14px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    align-items: baseline;
}
.col-spec-row:last-child { border-bottom: none; }
.col-spec-row:nth-child(even) { background: #fafbfe; }

.col-spec-row .label { font-weight: 600; flex: 0 0 200px; }
.col-spec-row .desc { color: var(--text-muted); flex: 1 1 auto; }

/* ---------- Score breakdown row (results.php) ---------- */

.score-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12px;
}
.score-row .chip {
    padding: 2px 8px;
    border-radius: 6px;
    background: #f2f4f7;
    color: var(--text-muted);
}

/* ---------- Loading skeleton ---------- */

.loading-hint {
    color: var(--text-muted);
    font-size: 13px;
    padding: 20px 2px;
    text-align: center;
}

.mono { font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; }
.muted { color: var(--text-muted); }
