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

:root {
    --brand:    #1a56db;
    --brand-dk: #1341a8;
    --bg:       #f4f6f9;
    --surface:  #ffffff;
    --border:   #dde1e9;
    --text:     #1e2330;
    --muted:    #6b7280;
    --success:  #16a34a;
    --warning:  #d97706;
    --danger:   #dc2626;
    --radius:   6px;
    --shadow:   0 1px 4px rgba(0,0,0,.10);
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ── */
.site-header {
    background: var(--text);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 0;
    height: 48px;
    padding: 0 1rem;
}

.brand {
    display: flex;
    align-items: center;
    white-space: nowrap;
    margin-right: 1.25rem;
    text-decoration: none;
}
.brand-logo {
    height: 32px;
    width: auto;
    display: block;
}

/* ── Nav ── */
.main-nav {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 2px;
    height: 100%;
}

.nav-divider {
    width: 1px;
    height: 24px;
    background: rgba(255,255,255,.2);
    margin: 0 8px;
}

.nav-link {
    color: rgba(255,255,255,.85);
    font-size: 13px;
    padding: 0 10px;
    height: 48px;
    display: flex;
    align-items: center;
    white-space: nowrap;
    text-decoration: none;
    transition: background .15s;
}
.nav-link:hover { background: rgba(255,255,255,.1); text-decoration: none; }

.nav-action {
    background: var(--brand);
    border-radius: var(--radius);
    height: 32px;
    margin-left: 4px;
    padding: 0 14px;
    font-weight: 600;
    color: #fff;
}
.nav-action:hover { background: var(--brand-dk); }

/* ── Dropdown ── */
.dropdown {
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
}

.dropbtn {
    background: none;
    border: none;
    color: rgba(255,255,255,.85);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    padding: 0 12px;
    height: 48px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background .15s;
    white-space: nowrap;
}
.dropbtn:hover, .dropdown:hover .dropbtn {
    background: rgba(255,255,255,.1);
}

.dropdown-content {
    display: none;
    position: absolute;
    top: 48px;
    left: 0;
    min-width: 180px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 200;
}
.dropdown:hover .dropdown-content { display: block; }

.dropdown-content a {
    display: block;
    padding: 9px 14px;
    color: var(--text);
    font-size: 13px;
    text-decoration: none;
    border-bottom: 1px solid var(--border);
}
.dropdown-content a:last-child { border-bottom: none; }
.dropdown-content a:hover { background: var(--bg); }

/* ── Header user area ── */
.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    white-space: nowrap;
    font-size: 12px;
    color: rgba(255,255,255,.75);
}

.btn-logout {
    color: rgba(255,255,255,.75);
    border: 1px solid rgba(255,255,255,.25);
    border-radius: var(--radius);
    padding: 4px 10px;
    font-size: 12px;
    text-decoration: none;
    transition: border-color .15s, color .15s;
}
.btn-logout:hover { color: #fff; border-color: rgba(255,255,255,.6); text-decoration: none; }

/* ── User menu (clickable name → dropdown) ── */
.user-menu { position: relative; }
.user-menu-trigger {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    color: rgba(255,255,255,.78);
    padding: 4px 8px;
    border-radius: var(--radius);
    white-space: nowrap;
    transition: background .15s, color .15s;
}
.user-menu-trigger:hover { background: rgba(255,255,255,.12); color: #fff; }
.user-menu-trigger small { color: rgba(255,255,255,.55); }
.user-menu-caret { font-size: 9px; transition: transform .15s; }
.user-menu.open .user-menu-caret { transform: rotate(180deg); }

.user-menu-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 210px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 6px 18px rgba(0,0,0,.18);
    z-index: 200;
    padding: 4px;
}
.user-menu.open .user-menu-dropdown { display: block; }
.user-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-radius: calc(var(--radius) - 1px);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    color: var(--text);
    padding: 9px 12px;
    text-decoration: none;
    transition: background .12s, color .12s;
}
.user-menu-item:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.user-menu-item-danger { color: var(--danger); }
.user-menu-item-danger:hover { background: rgba(220,38,38,.1); color: var(--danger); }

/* ── Messages ── */
.messages { padding: .5rem 1.5rem; }
.message {
    padding: .6rem 1rem;
    border-radius: var(--radius);
    margin-bottom: .4rem;
    font-size: 13px;
}
.message-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.message-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.message-warning { background: #fef9c3; color: #854d0e; border: 1px solid #fef08a; }
.message-info    { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }

/* ── Main content ── */
.main-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.75rem 1.5rem 3rem;
}

.page-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.page-header h2 { font-size: 20px; font-weight: 700; }
.page-header-actions { margin-left: auto; display: flex; align-items: center; gap: .75rem; }

.role-badge {
    background: var(--brand);
    color: #fff;
    border-radius: 999px;
    padding: 2px 12px;
    font-size: 12px;
    font-weight: 600;
}

/* ── Stats row ── */
.stats-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    box-shadow: var(--shadow);
}
.stat-number { font-size: 32px; font-weight: 700; }
.stat-label  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-pending  .stat-number { color: var(--warning); }
.stat-progress .stat-number { color: var(--brand); }
.stat-done     .stat-number { color: var(--success); }

/* ── Section ── */
.section { margin-bottom: 2rem; }
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .75rem;
}
.section-header h3 { font-size: 15px; font-weight: 600; }
.link-all { font-size: 13px; }

/* ── Tables ── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.data-table th {
    background: #f8f9fc;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--muted);
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafbfc; }
.empty-cell { color: var(--muted); text-align: center; }
.link-view { font-size: 12px; color: var(--brand); }
.address-link { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; }
.address-link:hover { color: var(--brand-dk); }

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
}
.badge-pending     { background: #fef9c3; color: #854d0e; }
.badge-in_progress { background: #dbeafe; color: #1d4ed8; }
.badge-completed   { background: #dcfce7; color: #166534; }
.badge-overdue     { background: #fee2e2; color: #991b1b; }
.badge-lg { font-size: 13px; padding: 4px 14px; }

/* ── Certification cards ── */
.cert-card { margin-bottom: 1.25rem; }
.cert-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: .75rem;
}
.cert-card-header h3 { font-size: 15px; font-weight: 700; color: var(--text); text-transform: none; letter-spacing: normal; margin: 0; }
.cert-files { font-size: 13px; margin-bottom: .75rem; display: flex; flex-wrap: wrap; gap: .3rem .6rem; align-items: center; }

/* ── Filter bar ── */
.filter-bar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.filter-tag {
    padding: 4px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 12px;
    color: var(--text);
    text-decoration: none;
    transition: background .15s;
}
.filter-tag:hover, .filter-tag.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
    text-decoration: none;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, border-color .15s;
}
.btn-primary   { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dk); text-decoration: none; color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); text-decoration: none; }

/* ── Forms ── */
.field-group { margin-bottom: 1rem; }
.field-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text);
}
.field-hint { font-weight: 400; font-size: 12px; color: var(--muted); }
.logo-clear-checkbox { margin: 0 .4rem .5rem 0; vertical-align: middle; }

.field-group input[type="text"],
.field-group input[type="email"],
.field-group input[type="password"],
.field-group input[type="url"],
.field-group input[type="date"],
.field-group select,
.field-group textarea {
    width: 100%;
    min-height: 38px;           /* uniform height for all single-line inputs */
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.field-group input[type="date"] {
    cursor: pointer;
    line-height: 1.3;
}
/* The dd/mm/yyyy edit fields */
.field-group input[type="date"]::-webkit-datetime-edit {
    color: var(--text);
}
.field-group input[type="date"]::-webkit-datetime-edit-fields-wrapper { padding: 0; }
.field-group input[type="date"]:not(:focus)::-webkit-datetime-edit-text,
.field-group input[type="date"]:not(:focus)::-webkit-datetime-edit-month-field,
.field-group input[type="date"]:not(:focus)::-webkit-datetime-edit-day-field,
.field-group input[type="date"]:not(:focus)::-webkit-datetime-edit-year-field {
    color: var(--muted);
}
/* Calendar button — a themed, clearly clickable control */
.field-group input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: .6;
    padding: 3px;
    margin-left: 4px;
    border-radius: 5px;
    transition: opacity .15s, background .15s;
}
.field-group input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
    background: rgba(26, 86, 219, .12);
}
.field-group input[type="date"]:focus::-webkit-calendar-picker-indicator { opacity: 1; }

/* Custom file upload */
.file-upload-wrap {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 7px 10px 7px 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: border-color .15s;
}
.file-upload-wrap:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(26,86,219,.15); }
.file-upload-btn {
    flex-shrink: 0;
    padding: 5px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 1px);
    font-size: 12px;
    font-family: inherit;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: background .15s, border-color .15s;
    white-space: nowrap;
}
.file-upload-btn:hover { background: #e5e7eb; border-color: #b8bfc9; }
.file-upload-name {
    font-size: 13px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(26,86,219,.15);
}
.field-group input[type="date"]:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(26,86,219,.15);
}
.field-error { font-size: 12px; color: var(--danger); margin-top: 3px; display: block; }
.field-help  { font-size: 12px; color: var(--muted); margin-top: 3px; display: block; }

.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem;
    max-width: 640px;
    box-shadow: var(--shadow);
}
.form-actions {
    display: flex;
    gap: .75rem;
    margin-top: 1.5rem;
}

/* ── Detail layout ── */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 1.25rem;
    align-items: start;
}
.detail-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}
.detail-card h3 { font-size: 14px; font-weight: 700; margin-bottom: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

.info-list { display: grid; grid-template-columns: 140px 1fr; gap: .4rem .75rem; font-size: 13px; }
.info-list dt { font-weight: 600; color: var(--muted); }
.info-list dd { color: var(--text); }

.description-text { font-size: 14px; line-height: 1.7; white-space: pre-wrap; }

.back-link { font-size: 13px; display: inline-block; margin-top: 1rem; }

/* ── Search ── */
.search-form { margin-bottom: 1rem; }
.search-row { display: flex; gap: .5rem; max-width: 540px; }
.search-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
}
.search-input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(26,86,219,.15);
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 3rem 1rem;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    font-size: 14px;
}

/* ── Login page ── */
.login-page {
    background: linear-gradient(135deg, #1e2330 0%, #1a56db 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-wrapper { width: 100%; max-width: 400px; padding: 1rem; }
.login-card {
    background: var(--surface);
    border-radius: 10px;
    padding: 2.5rem 2rem;
    box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.login-logo-wrap {
    text-align: center;
    margin-bottom: 1rem;
}
.login-logo {
    height: 64px;
    width: auto;
}
.login-title {
    font-size: 22px;
    font-weight: 800;
    text-align: center;
    margin-bottom: .25rem;
    color: var(--text);
}
.login-subtitle {
    text-align: center;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 1.75rem;
}
.login-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: .6rem 1rem;
    font-size: 13px;
    margin-bottom: 1rem;
}
.login-form .field-group { margin-bottom: .9rem; }
.btn-login {
    width: 100%;
    padding: 10px;
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    margin-top: .5rem;
    transition: background .15s;
}
.btn-login:hover { background: var(--brand-dk); }

/* ── Status action buttons (T3/T4) ── */
.btn-start  { background: #2563eb; color: #fff; }
.btn-start:hover  { background: #1d4ed8; text-decoration: none; color: #fff; }
.btn-finish { background: #16a34a; color: #fff; }
.btn-finish:hover { background: #15803d; text-decoration: none; color: #fff; }

/* ── Modals ── */
.cms-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    border: none;
    border-radius: 14px;
    padding: 0;
    max-width: 580px;
    width: calc(100% - 2rem);
    box-shadow: none;
    background: var(--surface);
    animation: modal-in .18s ease;
}
@keyframes modal-in {
    from { opacity: 0; transform: translate(-50%, -48%) scale(.97); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.cms-modal::backdrop {
    background: rgba(15,20,35,.55);
    backdrop-filter: blur(3px);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: #f8f9fc;
    border-radius: 14px 14px 0 0;
}
.modal-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.1px;
}
.modal-close {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 50%;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s;
}
.modal-close:hover { background: #e5e7eb; color: var(--text); }

.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: #f8f9fc;
}
.modal-tab {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: .75rem 1rem;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    color: var(--muted);
    transition: color .15s, border-color .15s;
    font-family: inherit;
}
.modal-tab.active { color: var(--brand); border-bottom-color: var(--brand); background: none; }
.modal-tab:hover  { color: var(--text); }

.modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
}
.modal-pane { }

.modal-footer {
    display: flex;
    gap: .75rem;
    justify-content: flex-end;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    background: #f8f9fc;
    border-radius: 0 0 14px 14px;
}

/* Checkbox list in modal */
.checkbox-list { display: flex; flex-direction: column; gap: 6px; }
.checkbox-list label { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.checkbox-list input[type=checkbox] { width: 15px; height: 15px; cursor: pointer; }
.worker-empty-msg { font-size: 13px; color: var(--muted); font-style: italic; margin-top: 2px; }

/* nav button (no <a>, it's a <button>) */
.nav-link.nav-action { border: none; cursor: pointer; font-family: inherit; height: 32px; }

/* Utility */
.muted { color: var(--muted); }

/* ── Theme switch ── */
.theme-switch {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    margin-left: 10px;
    padding-left: 12px;
    border-left: 1px solid rgba(255,255,255,.18);
}
.theme-switch-input { display: none; }
.theme-icon {
    font-size: 13px;
    line-height: 1;
    color: rgba(255,255,255,.65);
}
.theme-track {
    position: relative;
    width: 34px;
    height: 18px;
    background: rgba(255,255,255,.22);
    border-radius: 9px;
    transition: background .2s;
    flex-shrink: 0;
}
.theme-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    transition: transform .2s;
    box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.theme-switch-input:checked ~ .theme-track { background: rgba(255,255,255,.38); }
.theme-switch-input:checked ~ .theme-track .theme-thumb { transform: translateX(16px); }

/* ── Dark mode ── */
body.dark {
    --bg:      #111827;
    --surface: #1f2937;
    --border:  #374151;
    --text:    #f3f4f6;
    --muted:   #9ca3af;
    --shadow:  0 1px 4px rgba(0,0,0,.5);
}

body.dark .site-header         { background: #0d1117; }
body.dark .dropbtn             { color: rgba(255,255,255,.8); }
body.dark .nav-divider         { background: rgba(255,255,255,.15); }
body.dark .dropdown-content    { background: #1f2937; border-color: #374151; }
body.dark .dropdown-content a  { color: #f3f4f6; border-color: #374151; }
body.dark .dropdown-content a:hover { background: #374151; }

body.dark .data-table th           { background: #1a2233; color: #9ca3af; }
body.dark .data-table tbody tr:hover { background: #243044; }

body.dark .stat-card               { background: var(--surface); border-color: var(--border); }

body.dark .modal-header,
body.dark .modal-tabs,
body.dark .modal-footer            { background: #1a2233; }

body.dark .modal-close             { background: #253047; border-color: #374151; color: #9ca3af; }
body.dark .modal-close:hover       { background: #2d3a50; color: #f3f4f6; }

body.dark .field-group input[type="text"],
body.dark .field-group input[type="email"],
body.dark .field-group input[type="password"],
body.dark .field-group input[type="date"],
body.dark .field-group select,
body.dark .field-group textarea    { background: #253047; border-color: #374151; color: #f3f4f6; }

body.dark .file-upload-wrap        { background: #253047; border-color: #374151; }
body.dark .file-upload-btn         { background: #1f2937; border-color: #374151; color: #f3f4f6; }
body.dark .file-upload-btn:hover   { background: #2d3a50; border-color: #4b5563; }

body.dark .btn-secondary           { background: #253047; border-color: #374151; color: #f3f4f6; }
body.dark .btn-secondary:hover     { background: #2d3a50; }

body.dark .filter-tag              { background: var(--surface); border-color: var(--border); color: var(--text); }
body.dark .filter-tag:hover,
body.dark .filter-tag.active       { background: var(--brand); border-color: var(--brand); color: #fff; }
body.dark .detail-card             { background: var(--surface); border-color: var(--border); }
body.dark .form-card               { background: var(--surface); border-color: var(--border); }
body.dark .empty-state             { background: var(--surface); border-color: var(--border); }

body.dark .message-success { background: #052e16; color: #86efac; border-color: #166534; }
body.dark .message-error   { background: #450a0a; color: #fca5a5; border-color: #991b1b; }
body.dark .message-warning { background: #422006; color: #fde68a; border-color: #854d0e; }
body.dark .message-info    { background: #0c1a3d; color: #93c5fd; border-color: #1e40af; }

/* ── Target checklist ── */
.progress-wrap { margin-bottom: 1.25rem; }
.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 5px;
}
.progress-bar-bg {
    background: var(--border);
    border-radius: 999px;
    height: 8px;
    overflow: hidden;
}
.progress-bar-fill {
    background: var(--brand);
    height: 100%;
    border-radius: 999px;
    transition: width .3s ease;
    min-width: 0;
}
.progress-bar-fill.full { background: var(--success); }

.target-list { list-style: none; padding: 0; margin: 0; }
.target-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .55rem 0;
    border-bottom: 1px solid var(--border);
}
.target-item:last-child { border-bottom: none; }
.target-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: var(--brand);
}
.target-label {
    font-size: 13px;
    flex: 1;
    cursor: pointer;
    color: var(--text);
    transition: color .15s;
}
.target-label.done {
    text-decoration: line-through;
    color: var(--muted);
}

body.dark .progress-bar-bg { background: #374151; }
body.dark .target-item      { border-color: var(--border); }

/* ── Document categories ── */
.doc-category {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}
.doc-category:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}
.doc-cat-header {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: .75rem;
}
.doc-cat-title {
    font-weight: 600;
    font-size: .95rem;
    color: var(--text);
}
.doc-optional-badge {
    font-size: .7rem;
    font-weight: 500;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
}
.doc-count-badge {
    margin-left: auto;
    font-size: .75rem;
    font-weight: 600;
    color: var(--brand);
    background: color-mix(in srgb, var(--brand) 12%, transparent);
    border-radius: 10px;
    padding: 1px 8px;
    min-width: 22px;
    text-align: center;
}

/* Document list */
.doc-list {
    list-style: none;
    margin: 0 0 .75rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .4rem;
}
.doc-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .45rem .6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}
.doc-link {
    display: flex;
    align-items: center;
    gap: .4rem;
    text-decoration: none;
    color: var(--brand);
    flex: 1;
    min-width: 0;
}
.doc-link:hover .doc-name { text-decoration: underline; }
.doc-icon { font-size: .95rem; flex-shrink: 0; }
.doc-name {
    font-size: .85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.doc-meta {
    font-size: .75rem;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}
.btn-icon-danger {
    background: none;
    border: none;
    cursor: pointer;
    color: #ef4444;
    font-size: .85rem;
    padding: 2px 5px;
    border-radius: 4px;
    line-height: 1;
    flex-shrink: 0;
    transition: background .15s;
}
.btn-icon-danger:hover { background: rgba(239,68,68,.1); }

/* Upload form */
.doc-upload-form { display: flex; align-items: center; gap: .5rem; }
.doc-upload-label { cursor: pointer; }
.doc-file-input { display: none; }
.doc-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font-size: .8rem;
    font-weight: 500;
    color: var(--brand);
    border: 1px dashed var(--brand);
    border-radius: 6px;
    padding: .3rem .75rem;
    transition: background .15s;
}
.doc-upload-label:hover .doc-upload-btn {
    background: color-mix(in srgb, var(--brand) 8%, transparent);
}

/* ── Notes ── */
.note-form { margin-bottom: 1rem; }
.note-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .6rem;
}
.note-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--brand);
    border-radius: 6px;
    padding: .65rem .85rem;
}
.note-text {
    margin: 0 0 .3rem;
    font-size: .9rem;
    color: var(--text);
    white-space: pre-wrap;
}
.note-meta {
    font-size: .75rem;
    color: var(--muted);
}

/* ── History timeline ── */
.history-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.history-item {
    display: flex;
    gap: .75rem;
    align-items: flex-start;
    padding: .6rem 0;
    border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }
.history-icon {
    font-size: 1rem;
    width: 1.6rem;
    text-align: center;
    flex-shrink: 0;
    margin-top: .05rem;
}
.history-body {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    min-width: 0;
}
.history-action {
    font-size: .875rem;
    font-weight: 600;
    color: var(--text);
}
.history-detail {
    font-size: .8rem;
    color: var(--muted);
}
.history-meta {
    font-size: .75rem;
    color: var(--muted);
}
.muted-text { color: var(--muted); font-size: .9rem; }

/* btn-sm */
.btn.btn-sm { font-size: .8rem; padding: .35rem .85rem; }

/* Dark mode additions */
body.dark .doc-item      { background: #1f2937; border-color: var(--border); }
body.dark .note-item     { background: #1f2937; border-color: var(--border); }
body.dark .doc-upload-btn { border-color: var(--brand); }
body.dark .doc-count-badge { background: rgba(99,102,241,.18); }

/* ── Client display ── */
.client-logo-placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--brand) 15%, transparent);
    color: var(--brand);
    font-weight: 700;
    font-size: .9rem;
    flex-shrink: 0;
}
.client-logo-lg {
    width: 52px;
    height: 52px;
    font-size: 1.3rem;
}
.client-logo-xl {
    width: 72px;
    height: 72px;
    font-size: 1.9rem;
}

/* Clickable client name/logo (links to the profile) */
.client-link { color: inherit; text-decoration: none; }
.client-link:hover .client-link-name,
.client-link:hover { color: var(--brand); }
.client-link:hover { text-decoration: underline; }

/* Client card on task detail */
.client-card {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.client-card-logo {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.client-card-info {
    display: flex;
    flex-direction: column;
    gap: .2rem;
}
.client-card-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text);
}
.client-card-meta {
    font-size: .83rem;
    color: var(--muted);
}

/* Client cell in task list */
.client-cell {
    display: flex;
    align-items: center;
    gap: .5rem;
    white-space: nowrap;
}
.client-cell-logo {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.client-cell .client-logo-placeholder {
    width: 26px;
    height: 26px;
    font-size: .7rem;
}

/* History header with clear-all action */
.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .75rem;
}
.history-header h3 { margin-bottom: 0; }

/* History item delete button */
.history-item { position: relative; }
.history-delete-form {
    display: flex;
    align-items: center;
    margin-left: auto;
    flex-shrink: 0;
}

/* Danger outline button */
.btn-danger-outline {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: .25rem .6rem;
    border-radius: var(--radius);
    font-size: .75rem;
    cursor: pointer;
    line-height: 1.4;
}
.btn-danger-outline:hover {
    background: var(--danger);
    color: #fff;
}

@media (prefers-color-scheme: dark) {
    .btn-danger-outline { border-color: #f87171; color: #f87171; }
    .btn-danger-outline:hover { background: #f87171; color: #111; }
}

/* ── Deadline banner ── */
.deadline-banner {
    padding: .6rem 1rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.deadline-banner-card {
    display: flex;
    align-items: flex-start;
    gap: .875rem;
    max-width: 1200px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid #fca5a5;
    border-left: 4px solid var(--danger);
    border-radius: var(--radius);
    padding: .75rem 1rem;
    box-shadow: var(--shadow);
}
.deadline-banner-icon {
    font-size: 1.2rem;
    color: var(--danger);
    flex-shrink: 0;
    line-height: 1.35;
}
.deadline-banner-body {
    flex: 1;
    min-width: 0;
}
.deadline-banner-title {
    font-weight: 700;
    font-size: .8125rem;
    color: var(--danger);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: .35rem;
}
.deadline-banner-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: .3rem;
}
.deadline-banner-list li {
    font-size: .875rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}
.deadline-banner-list a {
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}
.deadline-banner-list a:hover { text-decoration: underline; }
.deadline-tag {
    display: inline-flex;
    align-items: center;
    padding: .1rem .45rem;
    border-radius: 99px;
    font-size: .75rem;
    font-weight: 600;
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}
.deadline-tag-overdue {
    background: #fef2f2;
    color: var(--danger);
    border-color: #fca5a5;
}
.deadline-banner-close {
    background: none;
    border: 1px solid transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: .85rem;
    padding: .2rem .4rem;
    border-radius: var(--radius);
    flex-shrink: 0;
    line-height: 1;
    transition: background .12s, border-color .12s, color .12s;
}
.deadline-banner-close:hover {
    background: #fef2f2;
    border-color: #fca5a5;
    color: var(--danger);
}

/* Overdue date label in task detail */
.deadline-overdue {
    color: var(--danger);
    font-weight: 600;
}

/* Dark mode deadline banner */
body.dark .deadline-banner { background: #0f172a; border-color: #1e293b; }
body.dark .deadline-banner-card {
    background: #1e293b;
    border-color: #7f1d1d;
    border-left-color: #ef4444;
    box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
body.dark .deadline-banner-icon { color: #f87171; }
body.dark .deadline-banner-title { color: #f87171; }
body.dark .deadline-banner-list li { color: #e2e8f0; }
body.dark .deadline-banner-list a { color: #e2e8f0; }
body.dark .deadline-tag { background: #451a03; color: #fbbf24; border-color: #78350f; }
body.dark .deadline-tag-overdue { background: #450a0a; color: #f87171; border-color: #7f1d1d; }
body.dark .deadline-banner-close { color: #94a3b8; }
body.dark .deadline-banner-close:hover { background: #450a0a; border-color: #7f1d1d; color: #f87171; }

/* Dark mode date picker icon */
body.dark .field-group input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1) brightness(.8);
}

/* ════════════════════════════════════════════════════════
   RESPONSIVE  —  desktop (>1024px) keeps the original layout
   ════════════════════════════════════════════════════════ */

/* Horizontal-scroll wrapper for wide tables on mid-size screens */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* The nav wrapper is invisible on desktop (children act as before) */
.nav-collapse { display: contents; }

/* Hamburger button — hidden on desktop, shown on tablets/phones */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 40px;
    height: 40px;
    padding: 9px 8px;
    background: none;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
}
.nav-toggle-bar {
    display: block;
    width: 100%;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: transform .2s ease, opacity .2s ease;
}
.site-header.nav-open .nav-toggle-bar:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.site-header.nav-open .nav-toggle-bar:nth-child(2) { opacity: 0; }
.site-header.nav-open .nav-toggle-bar:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ── Tablets & below: collapse the navigation into a menu ── */
@media (max-width: 1024px) {
    .nav-toggle { display: flex; margin-left: auto; }

    .nav-collapse {
        display: none;
        position: absolute;
        top: 48px;
        left: 0;
        right: 0;
        flex-direction: column;
        background: #1e2330;
        max-height: calc(100vh - 48px);
        overflow-y: auto;
        box-shadow: 0 10px 22px rgba(0,0,0,.38);
        border-top: 1px solid rgba(255,255,255,.12);
    }
    .site-header.nav-open .nav-collapse { display: flex; }

    .nav-collapse .main-nav {
        flex-direction: column;
        align-items: stretch;
        height: auto;
        width: 100%;
        gap: 0;
        padding: .3rem 0;
    }

    /* Dropdowns become stacked, always-expanded groups */
    .nav-collapse .dropdown { display: block; height: auto; }
    .nav-collapse .dropbtn {
        width: 100%;
        height: auto;
        justify-content: flex-start;
        padding: .7rem 1.1rem;
        font-size: 14px;
        font-weight: 600;
        color: #fff;
    }
    .nav-collapse .dropdown-content {
        position: static;
        display: block;
        min-width: 0;
        background: transparent;
        border: none;
        border-radius: 0;
        box-shadow: none;
        padding: 0 0 .3rem;
    }
    .nav-collapse .dropdown-content a {
        color: rgba(255,255,255,.68);
        border: none;
        padding: .5rem 1.1rem .5rem 2rem;
        font-size: 13px;
    }
    .nav-collapse .dropdown-content a:hover { background: rgba(255,255,255,.08); }

    .nav-collapse .nav-divider {
        width: auto;
        height: 1px;
        margin: .3rem 1.1rem;
        background: rgba(255,255,255,.15);
    }

    .nav-collapse .nav-link {
        height: auto;
        width: 100%;
        padding: .7rem 1.1rem;
        font-size: 14px;
        color: #fff;
    }
    .nav-collapse .nav-link.nav-action {
        width: calc(100% - 2.2rem);
        height: 40px;
        margin: .5rem 1.1rem;
        justify-content: center;
        color: #fff;
    }

    .nav-collapse .header-user {
        flex-wrap: wrap;
        width: 100%;
        margin-left: 0;
        padding: .5rem 1.1rem .85rem;
        gap: 12px;
        border-top: 1px solid rgba(255,255,255,.12);
        font-size: 13px;
    }

    /* User menu expands inline within the mobile panel */
    .nav-collapse .user-menu { width: 100%; }
    .nav-collapse .user-menu-trigger {
        width: 100%;
        justify-content: space-between;
        color: #fff;
        font-size: 14px;
        padding: .65rem 0;
    }
    .nav-collapse .user-menu-dropdown {
        position: static;
        min-width: 0;
        width: 100%;
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0;
    }
    .nav-collapse .user-menu-item { color: rgba(255,255,255,.85); padding: .6rem .25rem; }
    .nav-collapse .user-menu-item:hover { background: rgba(255,255,255,.08); color: #fff; }
    .nav-collapse .user-menu-item-danger { color: #fca5a5; }
    .nav-collapse .user-menu-item-danger:hover { background: rgba(248,113,113,.12); color: #fca5a5; }

    /* Task-detail two-column grid → single column */
    .detail-grid { grid-template-columns: 1fr; }

    /* Tighter outer spacing */
    .main-content { padding: 1.25rem 1rem 2.5rem; }
    .messages     { padding: .5rem 1rem; }
    .header-inner { padding: 0 .85rem; }
}

body.dark .nav-collapse { background: #0d1117; }

/* ── Phones: stack content, turn tables into cards ── */
@media (max-width: 640px) {
    .page-header { flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
    .page-header h2 { font-size: 18px; }

    /* Compact stat tiles, still side by side */
    .stats-row   { gap: .55rem; }
    .stat-card   { padding: .8rem .7rem; }
    .stat-number { font-size: 24px; }
    .stat-label  { font-size: 11px; }

    /* Data tables → stacked cards */
    .table-wrap { overflow-x: visible; }
    .data-table {
        display: block;
        width: 100%;
        border: none;
        box-shadow: none;
        background: transparent;
    }
    .data-table thead {
        position: absolute;
        width: 1px; height: 1px;
        padding: 0; margin: -1px;
        overflow: hidden; clip: rect(0,0,0,0);
        white-space: nowrap; border: 0;
    }
    .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table tr {
        margin-bottom: .8rem;
        padding: .3rem .9rem;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: var(--surface);
        box-shadow: var(--shadow);
        overflow: hidden;
    }
    .data-table tbody tr:hover { background: var(--surface); }
    .data-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        text-align: right;
        padding: .5rem 0;
        border-bottom: 1px solid var(--border);
        font-size: 13px;
    }
    .data-table tr td:last-child { border-bottom: none; }
    .data-table td::before {
        content: attr(data-label);
        flex-shrink: 0;
        text-align: left;
        font-size: 10px;
        font-weight: 700;
        letter-spacing: .4px;
        text-transform: uppercase;
        color: var(--muted);
        white-space: nowrap;
    }
    .data-table td[data-label=""] { justify-content: center; padding-top: .65rem; }
    .data-table td[data-label=""]::before { content: none; }
    .data-table td.empty-cell { justify-content: center; text-align: center; }
    .data-table td.empty-cell::before { content: none; }
    /* Let long values wrap rather than push the card wider than the screen */
    .data-table td { overflow-wrap: anywhere; }
    .data-table td > * { min-width: 0; }
    .data-table td .client-cell { white-space: normal; }

    /* Detail info list → single column */
    .info-list { grid-template-columns: 1fr; gap: .1rem .5rem; }
    .info-list dt { margin-top: .55rem; }
    .info-list dt:first-of-type { margin-top: 0; }

    .detail-card { padding: 1rem 1.05rem; }
    .form-card   { padding: 1.25rem 1.05rem; }

    /* Modal fits small screens */
    .cms-modal     { width: calc(100% - 1.5rem); border-radius: 12px; }
    .modal-header,
    .modal-footer  { padding: .85rem 1.05rem; }
    .modal-body    { padding: 1.1rem; max-height: 66vh; }
    .modal-footer .btn { flex: 1; justify-content: center; }

    /* Search bar stacks */
    .search-row { flex-direction: column; max-width: none; }
    .search-row .btn { justify-content: center; }

    /* Document rows wrap their meta onto a second line */
    .doc-item { flex-wrap: wrap; }
    .doc-meta { width: 100%; order: 3; text-align: left; }
}
