:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --text: #1f2937;
    --heading: #111827;
    --muted: #6b7280;
    --line: #d9e0e7;
    --line-soft: #edf1f5;
    --panel: #f8fafc;
    --control-bg: #ffffff;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff5ff;
    --avatar-bg: #1e3a8a;
    --danger-bg: #fde8e8;
    --warning-bg: #fff4d6;
    --success-bg: #e5f6ed;
    --danger-text: #9b1c1c;
    --warning-text: #8a5a00;
    --success-text: #166534;
    --shadow: 0 14px 35px rgba(15, 23, 42, 0.08);
}

:root[data-theme="dark"] {
    --bg: #111827;
    --card: #1f2937;
    --text: #e5e7eb;
    --heading: #f9fafb;
    --muted: #a7b0bf;
    --line: #374151;
    --line-soft: #2f3a49;
    --panel: #172033;
    --control-bg: #111827;
    --danger-bg: #4a1f24;
    --warning-bg: #483715;
    --success-bg: #173b2a;
    --danger-text: #fecaca;
    --warning-text: #fde68a;
    --success-text: #bbf7d0;
    --shadow: 0 14px 35px rgba(0, 0, 0, 0.28);
}

:root[data-accent="green"] {
    --primary: #16a34a;
    --primary-dark: #15803d;
    --primary-soft: #ecfdf3;
    --avatar-bg: #166534;
}

:root[data-accent="orange"] {
    --primary: #ea580c;
    --primary-dark: #c2410c;
    --primary-soft: #fff7ed;
    --avatar-bg: #9a3412;
}

:root[data-accent="purple"] {
    --primary: #7c3aed;
    --primary-dark: #6d28d9;
    --primary-soft: #f5f3ff;
    --avatar-bg: #5b21b6;
}

:root[data-accent="grey"] {
    --primary: #475569;
    --primary-dark: #334155;
    --primary-soft: #f1f5f9;
    --avatar-bg: #334155;
}

:root[data-theme="dark"][data-accent="blue"] {
    --primary-soft: #172554;
}

:root[data-theme="dark"][data-accent="green"] {
    --primary-soft: #14532d;
}

:root[data-theme="dark"][data-accent="orange"] {
    --primary-soft: #7c2d12;
}

:root[data-theme="dark"][data-accent="purple"] {
    --primary-soft: #3b0764;
}

:root[data-theme="dark"][data-accent="grey"] {
    --primary-soft: #334155;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    color: var(--primary-dark);
}

.page {
    width: min(95vw, 1600px);
    margin: 0 auto;
    padding: 32px 0 48px;
}

.form-page {
    width: min(92vw, 900px);
}

.page-header {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(0, auto) minmax(260px, 1fr);
    align-items: start;
    gap: 24px;
    margin-bottom: 24px;
}

.brand-block {
    grid-column: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 7px;
    min-width: 0;
    text-decoration: none;
}

.brand-block:hover .brand-title {
    color: var(--primary-dark);
}

.company-logo-wrap {
    grid-column: 2;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    min-width: 0;
    text-decoration: none;
}

.company-logo-wrap[hidden] {
    display: none;
}

.company-logo {
    display: block;
    width: auto;
    max-width: min(240px, 24vw);
    max-height: 70px;
    object-fit: contain;
}

.company-logo-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 118px;
    height: 54px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--muted);
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0;
}

.logo-settings-preview {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    min-height: 64px;
    margin: 0 0 18px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.logo-settings-preview img {
    display: block;
    width: auto;
    max-width: min(280px, 80vw);
    max-height: 64px;
    object-fit: contain;
}

h1,
h2 {
    margin: 0;
    color: var(--heading);
    font-weight: 700;
}

h1 {
    font-size: 32px;
    line-height: 1.15;
}

h2 {
    font-size: 20px;
}

.muted {
    margin: 0;
    color: var(--muted);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.page-action-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 10px;
    margin: 0 0 18px;
}

.header-controls {
    grid-column: 3;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 12px;
    min-width: 0;
}

.user-menu {
    position: relative;
}

.avatar-button {
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    border: 1px solid var(--primary);
    border-radius: 50%;
    background: var(--avatar-bg);
    color: #ffffff;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0;
    box-shadow: 0 8px 18px rgba(30, 58, 138, 0.18);
}

.avatar-button:hover {
    background: var(--primary-dark);
    border-color: var(--primary);
}

.user-menu-card {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 20;
    width: 300px;
    max-height: min(78vh, 620px);
    overflow-y: auto;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
}

.user-menu-card[hidden] {
    display: none;
}

.menu-list[hidden],
.title-menu-panel[hidden],
.profile-menu-panel[hidden],
.theme-menu-panel[hidden],
.favourites-menu-panel[hidden],
.email-menu-panel[hidden] {
    display: none;
}

.menu-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.menu-item {
    width: 100%;
    min-height: 42px;
    justify-content: flex-start;
    padding: 9px 12px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text);
    box-shadow: none;
    font-weight: 650;
}

.menu-item:hover {
    background: var(--panel);
    color: var(--primary-dark);
    box-shadow: none;
}

.menu-item.active {
    background: var(--primary-soft);
    color: var(--primary);
}

.menu-item:disabled {
    cursor: default;
    color: var(--muted);
    opacity: 0.62;
}

.menu-item:disabled:hover {
    background: transparent;
    color: var(--muted);
}

.title-menu-panel,
.profile-menu-panel,
.theme-menu-panel,
.favourites-menu-panel,
.email-menu-panel {
    padding: 10px;
}

.favourites-settings-form {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.favourite-option {
    min-height: 36px;
}

.submenu-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.submenu-heading h2 {
    margin: 0;
    font-size: 18px;
}

.back-menu-button {
    min-height: 32px;
    padding: 6px 10px;
    border-color: var(--line);
    background: var(--panel);
    color: var(--muted);
    box-shadow: none;
    font-size: 13px;
}

.back-menu-button:hover {
    background: var(--primary-soft);
    border-color: var(--line);
    color: var(--primary-dark);
    box-shadow: none;
}

.settings-group {
    margin-bottom: 14px;
}

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

.settings-label {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.field-help {
    margin: -2px 0 2px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.user-menu-card .field {
    margin-bottom: 12px;
}

.user-menu-card .button {
    width: 100%;
    margin-top: 2px;
}

.profile-settings-form input[type="file"] {
    padding: 8px;
}

.logo-preview-panel {
    margin: 0 0 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.logo-preview-panel[hidden] {
    display: none;
}

.logo-preview {
    display: block;
    max-width: 100%;
    max-height: 90px;
    margin: 0 auto 10px;
    object-fit: contain;
}

.logo-quality-message {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.remove-logo-button {
    margin-top: 4px;
}

.tabs {
    display: inline-flex;
    gap: 4px;
    margin-bottom: 18px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.tab-button {
    min-height: 36px;
    padding: 7px 14px;
    border-color: transparent;
    background: transparent;
    color: var(--muted);
    box-shadow: none;
    font-weight: 650;
}

.tab-button:hover {
    background: var(--card);
    border-color: transparent;
    color: var(--primary-dark);
    box-shadow: none;
}

.tab-button.active {
    background: var(--card);
    color: var(--primary);
    border-color: var(--line);
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.06);
}

.module-tab-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 8px;
    font: inherit;
    font-weight: inherit;
    text-decoration: none;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 16px;
    border: 1px solid var(--primary);
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    cursor: pointer;
    font: inherit;
    font-weight: 650;
    text-decoration: none;
    transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.button:hover,
button:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: #ffffff;
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
}

.button.secondary {
    background: var(--card);
    color: var(--primary);
    border-color: var(--line);
}

.button.secondary:hover {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.compact-button {
    min-height: 30px;
    padding: 5px 9px;
    font-size: 12px;
}

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

.tab-panel[hidden] {
    display: none;
}

.form-card {
    max-width: 680px;
}

.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.page-intro {
    display: grid;
    gap: 8px;
    margin: 0 0 16px;
}

.page-intro h2 {
    font-size: 26px;
    line-height: 1.2;
}

.read-only-note {
    width: fit-content;
    margin: 0;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.po-confirmation-page {
    padding-top: 22px;
}

.po-confirmation-page .page-header {
    align-items: center;
    margin-bottom: 18px;
}

.po-confirmation-page .brand-block,
.po-confirmation-page .company-logo-wrap,
.po-confirmation-page .header-controls {
    align-items: center;
}

.po-confirmation-page .company-logo {
    max-width: min(210px, 22vw);
    max-height: 54px;
}

.po-confirmation-page .company-logo-placeholder {
    height: 46px;
}

.welcome-card {
    min-height: 360px;
}

.module-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.module-card {
    display: flex;
    min-height: 150px;
    flex-direction: column;
    gap: 10px;
    justify-content: space-between;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    text-decoration: none;
}

.module-card:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--text);
}

.module-card h3 {
    margin: 0;
    color: var(--heading);
    font-size: 18px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.summary-grid > div {
    display: grid;
    gap: 5px;
    padding: 12px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: var(--panel);
}

.comparison-table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.comparison-table {
    min-width: 760px;
    table-layout: fixed;
}

.comparison-table th,
.comparison-table td {
    white-space: normal;
    vertical-align: top;
}

.comparison-table thead th:first-child,
.comparison-table tbody th {
    width: 30%;
}

.comparison-table thead th:nth-child(2),
.comparison-table thead th:nth-child(3) {
    width: 35%;
}

.comparison-table tbody th {
    background: var(--panel);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.parsed-lines-details {
    margin-top: 16px;
}

.parsed-lines-details summary {
    width: fit-content;
    list-style: none;
}

.parsed-lines-details summary::-webkit-details-marker {
    display: none;
}

.parsed-lines-details[open] summary {
    margin-bottom: 12px;
}

.filter-bar {
    display: grid;
    grid-template-columns: minmax(220px, 1.5fr) minmax(160px, 1fr) minmax(190px, 1fr) auto;
    align-items: end;
    gap: 14px;
    margin-bottom: 18px;
    padding: 14px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: var(--panel);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-bottom: 16px;
}

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

label {
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

input,
select,
textarea,
.ts-control {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--control-bg);
    color: var(--text);
    font: inherit;
}

input,
select,
textarea {
    padding: 8px 10px;
}

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

textarea {
    resize: vertical;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
}

th,
td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line-soft);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

th {
    background: var(--panel);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

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

tr:hover td {
    background: rgba(37, 99, 235, 0.04);
}

td form {
    margin: 0;
}

td input,
td select {
    min-width: 150px;
}

.po-table {
    table-layout: fixed;
    font-size: 13px;
}

.po-table-wrap {
    overflow-x: hidden;
}

.po-table th,
.po-table td {
    padding: 9px 8px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.po-table th {
    font-size: 11px;
}

.po-table .col-po-number {
    width: 7%;
}

.po-table .col-supplier {
    width: 8%;
}

.po-table .col-supplier-code {
    width: 6%;
}

.po-table .col-email {
    width: 10%;
}

.po-table .col-status {
    width: 5%;
}

.po-table .col-date {
    width: 8%;
}

.po-table .col-followup-date {
    width: 9%;
}

.po-table .col-priority {
    width: 7%;
}

.po-table .col-followup-status {
    width: 11%;
}

.po-table .col-followup-action {
    width: 9%;
}

.po-table .col-more-actions {
    width: 12%;
}

.po-table td input,
.po-table td select,
.po-table .ts-control {
    min-width: 0;
    min-height: 34px;
    padding: 6px 8px;
    font-size: 13px;
}

.po-table input[type="date"] {
    max-width: 100%;
}

.po-table .ts-wrapper {
    width: 100%;
    min-width: 0;
}

.po-table td form {
    max-width: 100%;
    overflow: hidden;
}

.po-table .priority-pill {
    min-height: 24px;
    padding: 3px 8px;
    font-size: 12px;
}

.users-table input[type="text"],
.users-table select {
    min-width: 0;
    width: 100%;
}

.add-user-form {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
    align-items: end;
    gap: 12px;
    margin-bottom: 18px;
}

.add-user-active {
    min-height: 38px;
}

.checkbox-field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
}

.checkbox-field input {
    width: auto;
    min-height: auto;
}

.module-assignment-list {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
}

.module-assignment-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.module-assignment-item span {
    display: grid;
    gap: 4px;
}

.module-assignment-item input {
    width: auto;
    min-height: auto;
}

.module-assignment-item.locked {
    background: var(--line-soft);
}

.user-action-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.user-action-stack form {
    margin: 0;
}

.form-actions {
    justify-content: flex-start;
}

@media (max-width: 1000px) {
    .add-user-form {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.followup-needed {
    display: block;
    margin-bottom: 6px;
    color: var(--danger-text);
    font-size: 12px;
    font-weight: 800;
}

.more-actions-cell {
    overflow: visible !important;
}

.more-actions {
    display: inline-block;
}

.more-actions-button {
    width: 34px;
    min-width: 34px;
    min-height: 30px;
    padding: 0;
    border-color: var(--line);
    background: var(--card);
    color: var(--text);
    box-shadow: none;
    font-weight: 800;
}

.more-actions-button:hover {
    background: var(--primary-soft);
    border-color: var(--line);
    color: var(--primary);
    box-shadow: none;
}

.more-actions-menu {
    margin-top: 6px;
    min-width: 150px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
}

.more-actions-menu[hidden] {
    display: none;
}

.activity-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(15, 23, 42, 0.45);
}

.activity-modal-backdrop[hidden] {
    display: none;
}

.activity-modal {
    width: min(620px, 92vw);
    max-height: min(680px, 86vh);
    overflow-y: auto;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--card);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
}

.activity-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.activity-list {
    display: grid;
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.activity-item {
    padding: 12px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: var(--panel);
}

.activity-meta {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.activity-type {
    margin-bottom: 4px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.priority-overdue {
    background-color: var(--danger-bg) !important;
}

.priority-due-today {
    background-color: var(--warning-bg) !important;
}

.priority-completed {
    background-color: var(--success-bg) !important;
}

.priority-pill {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--panel);
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.priority-overdue .priority-pill {
    background: #fbd5d5;
    color: var(--danger-text);
}

.priority-due-today .priority-pill {
    background: #ffe8a3;
    color: var(--warning-text);
}

.priority-completed .priority-pill {
    background: #cceedd;
    color: var(--success-text);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--panel);
    color: var(--text);
    font-size: 13px;
    font-weight: 750;
}

.status-matched {
    background: var(--success-bg);
    color: var(--success-text);
}

.status-review-required {
    background: var(--warning-bg);
    color: var(--warning-text);
}

.status-failed {
    background: var(--danger-bg);
    color: var(--danger-text);
}

.alert {
    margin: 0 0 18px;
    padding: 12px 14px;
    border: 1px solid #f5b8b8;
    border-radius: 8px;
    background: var(--danger-bg);
    color: var(--danger-text);
    font-weight: 650;
}

.notice {
    margin: 0 0 18px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--success-bg);
    color: var(--success-text);
    font-weight: 650;
}

.ts-wrapper.single .ts-control {
    padding: 7px 10px;
}

.ts-dropdown {
    border-color: var(--line);
    background: var(--card);
    color: var(--text);
    border-radius: 8px;
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.12);
    font: inherit;
}

@media (max-width: 820px) {
    .page,
    .form-page {
        width: min(94vw, 100% - 24px);
    }

    .page-header {
        grid-template-columns: 1fr;
    }

    .brand-block {
        grid-column: 1;
        width: 100%;
    }

    .company-logo-wrap {
        grid-column: 1;
        justify-content: flex-start;
    }

    .company-logo {
        max-width: min(240px, 75vw);
    }

    .header-controls {
        grid-column: 1;
        width: 100%;
        justify-content: space-between;
    }

    .user-menu-card {
        right: 0;
        width: min(300px, 86vw);
    }

    .actions {
        justify-content: flex-start;
    }

    .filter-bar {
        grid-template-columns: 1fr;
    }

    .po-table-wrap {
        overflow-x: auto;
    }

    .po-confirmation-page .company-logo-wrap,
    .po-confirmation-page .header-controls {
        align-items: flex-start;
    }
}
