﻿:root {
    --app-sidebar-width: clamp(140px, 14vw, 268px);
    --green-950: #003c2c;
    --green-900: #004735;
    --green-800: #075a43;
    --green-700: #0b6b4f;
    --green-100: #e7f4ed;
    --green-50: #f4faf6;
    --line: #d8e7de;
    --line-strong: #bad8c8;
    --text: #11231d;
    --muted: #64766f;
    --surface: #ffffff;
    --page: #f5f8f6;
    --danger: #9d2d20;
    --shadow: 0 18px 40px rgba(0, 60, 44, 0.08);
    --shadow-soft: 0 10px 28px rgba(0, 60, 44, 0.07);
    /*
     * Shared visual contract. CRM is the reference implementation for every
     * business module; module and page styles should consume these values
     * instead of inventing slightly different spacing and control sizes.
     */
    --ui-panel-radius: 10px;
    --ui-panel-head-padding: 18px 20px;
    --ui-panel-body-padding: 16px 20px;
    --ui-filter-padding: 16px 20px;
    --ui-field-height: 36px;
    --ui-field-radius: 6px;
    --ui-field-border: #c9ddd2;
    --ui-table-control-height: 34px;
    --ui-control-gap: 8px;
    --ui-section-gap: 14px;
    /* MES is the reference: desktop pages stop growing at this width and
     * only reflow once the available content area becomes narrower. */
    --ui-page-max-width: 1480px;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(11, 107, 79, 0.08), transparent 28%),
        var(--page);
    font-family: Arial, "Microsoft YaHei", "PingFang SC", sans-serif;
    font-size: 14px;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

.mobile-menu-button,
.sidebar-backdrop {
    display: none;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--app-sidebar-width) minmax(0, 1fr);
    grid-template-rows: 64px minmax(0, 1fr);
}

.topbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 24px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 3px 18px rgba(0, 60, 44, 0.04);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 0 0 var(--app-sidebar-width);
    width: var(--app-sidebar-width);
    min-width: var(--app-sidebar-width);
    color: var(--green-950);
    font-weight: 700;
}

.topbar-brand img {
    width: 136px;
    height: auto;
    display: block;
}

.topbar-brand span {
    white-space: nowrap;
}

.module-nav > a > .work-order-reminder-dot {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #e5484d;
    box-shadow: 0 0 0 2px #fff;
}

.module-nav {
    display: flex;
    flex: 1 1 auto;
    gap: 4px;
    height: 100%;
    min-width: 0;
    align-items: center;
}

.module-nav a {
    display: inline-flex;
    flex: 0 0 auto;
    position: relative;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 3px;
    height: 48px;
    padding: 0 14px;
    color: #33574b;
    border-radius: 6px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}

.module-nav-label {
    display: block;
    width: 100%;
    font: inherit;
    line-height: 1;
    text-align: center;
}

.module-nav-copy {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 0;
    text-align: center;
    line-height: 1;
    white-space: nowrap;
}

.module-nav-copy br {
    display: none;
}

.module-nav-summary {
    color: #8a9691;
    font-size: 9px;
    font-weight: 400;
    letter-spacing: 0.02em;
    line-height: 1;
}

.module-nav a.active,
.module-nav a:hover {
    color: #fff;
    background: var(--green-900);
}

.user-box {
    margin-left: auto;
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 10px;
    color: #315248;
    white-space: nowrap;
}

.topbar-current-company {
    display: inline-block;
    max-width: 12em;
    overflow: hidden;
    padding-right: 10px;
    border-right: 1px solid var(--line);
    color: var(--green-900);
    font-size: 13px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.module-nav a.active .module-nav-summary,
.module-nav a:hover .module-nav-summary {
    color: #c2ccc8;
    font-weight: 400;
}

.module-nav > a > .nav-badge {
    position: absolute;
    top: 2px;
    right: 2px;
}

@media (min-width: 981px) {
    .module-nav {
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-inline: contain;
        scrollbar-width: none;
    }

    .module-nav::-webkit-scrollbar {
        display: none;
    }
}

.user-avatar {
    display: grid;
    width: 30px;
    height: 30px;
    place-items: center;
    color: #fff;
    background: var(--green-900);
    border-radius: 50%;
    font-weight: 700;
}

.logout-link {
    padding-left: 10px;
    color: var(--muted);
    border-left: 1px solid var(--line);
    border-top: 0;
    border-right: 0;
    border-bottom: 0;
    background: transparent;
    font: inherit;
    cursor: pointer;
    white-space: nowrap;
}

.user-profile-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: inherit;
    border-radius: 999px;
    white-space: nowrap;
}

.user-name {
    max-width: 8em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-profile-link:focus-visible {
    outline: 2px solid var(--green-700);
    outline-offset: 3px;
}


.sidebar {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 64px);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(246, 252, 248, 0.98));
    border-right: 1px solid var(--line);
    box-shadow: 8px 0 28px rgba(0, 60, 44, 0.05);
}

.sidebar-menu {
    display: grid;
    gap: 10px;
    padding: 6px 16px 18px;
}

.sidebar-drawer-header {
    display: none;
}

.sidebar-section {
    display: grid;
    gap: 6px;
    padding: 4px 0 8px;
    border-bottom: 1px solid rgba(216, 231, 222, 0.72);
}

.sidebar-section:last-child {
    border-bottom: 0;
}

.sidebar-group {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 28px;
    margin: 0;
    padding: 6px 8px 6px 16px;
    color: #567168;
    background: transparent;
    border: 0;
    font-size: 12px;
    font-weight: 800;
    text-align: left;
    cursor: pointer;
    letter-spacing: 0;
    position: relative;
}

.sidebar-group::before {
    content: "";
    position: absolute;
    left: 6px;
    top: 50%;
    width: 4px;
    height: 4px;
    background: var(--green-700);
    border-radius: 50%;
    transform: translateY(-50%);
}

.sidebar-group:hover {
    color: var(--green-950);
}

.sidebar-group[aria-expanded="true"] {
    color: var(--green-950);
}

.sidebar-group span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-section.collapsed .sidebar-group-items {
    display: none;
}

.sidebar-group-items {
    display: grid;
    gap: 5px;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 42px;
    padding: 0 12px 0 16px;
    color: #365a4f;
    border-radius: 8px;
    border: 1px solid transparent;
    position: relative;
    transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.sidebar-menu a span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-menu a.sidebar-primary-link {
    color: var(--green-950);
    font-weight: 700;
}

.sidebar-menu a.active {
    color: var(--green-950);
    background: #ffffff;
    border-color: var(--line-strong);
    font-weight: 700;
    box-shadow: 0 9px 20px rgba(0, 60, 44, 0.08);
}

.sidebar-menu a.active::before {
    content: "";
    position: absolute;
    left: -1px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    background: var(--green-800);
    border-radius: 0 6px 6px 0;
}

.sidebar-menu a:hover {
    color: var(--green-950);
    background: #fff;
    border-color: var(--line);
    transform: translateX(2px);
}

.company-switcher {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid var(--line);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(245, 251, 247, 0.96));
    position: relative;
}

.nav-badge {
    display: inline-grid;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    place-items: center;
    color: #fff;
    background: #d93025;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
}

.work-order-reminder-badge {
    flex: 0 0 auto;
    margin-inline-start: 6px;
}

.finance-due-dot {
    display: inline-block;
    flex: 0 0 8px;
    width: 8px;
    height: 8px;
    margin-inline-start: 6px;
    vertical-align: middle;
    border-radius: 50%;
    background: #d93025;
}

.company-trigger {
    position: relative;
    display: grid;
    gap: 5px;
    width: 100%;
    min-height: 58px;
    padding: 11px 12px;
    text-align: left;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(0, 60, 44, 0.06);
    cursor: pointer;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.company-trigger:hover,
.company-switcher.open .company-trigger {
    border-color: var(--line-strong);
    box-shadow: 0 10px 24px rgba(0, 60, 44, 0.1);
    transform: translateY(-1px);
}

.company-trigger span {
    color: var(--muted);
    font-size: 12px;
}

.company-trigger strong {
    color: var(--green-950);
    word-break: keep-all;
}

.company-options {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: calc(100% + 10px);
    z-index: 30;
    display: none;
    gap: 7px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    box-shadow: 0 20px 48px rgba(0, 60, 44, 0.18);
}

.company-switcher.open .company-options {
    display: grid;
}

.company-menu-title {
    padding: 2px 2px 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.company-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #34594d;
    min-height: 34px;
    padding: 0 10px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.company-options label:hover,
.company-options label.active {
    color: var(--green-950);
    background: #fff;
    border-color: var(--line-strong);
}

.company-options input {
    accent-color: var(--green-800);
}

.company-reminder-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    margin-left: auto;
    border-radius: 999px;
    background: #dc302b;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
}

.company-reminder-badge[hidden] { display: none; }
.company-reminder-alert { position: absolute; top: 10px; right: 10px; }
.company-trigger:has(.company-reminder-alert:not([hidden])) { padding-right: 38px; }

.content {
    min-width: 0;
    padding: 28px;
}

.page-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 14px;
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--green-700);
    font-size: 12px;
    font-weight: 800;
}

.page-heading h1 {
    margin: 0;
    color: var(--green-950);
    font-size: 24px;
    line-height: 1.25;
}

.page-heading p {
    margin: 6px 0 0;
    color: var(--muted);
    line-height: 1.5;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.stat-card {
    min-height: 62px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 60, 44, 0.035);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: var(--green-800);
}

.stat-card span {
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 12px;
}

.stat-card strong {
    color: var(--green-950);
    font-size: 18px;
    line-height: 1.2;
}

.work-surface {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--ui-panel-radius);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}

.surface-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: var(--ui-panel-head-padding);
    border-bottom: 1px solid var(--line);
}

.surface-header h2 {
    margin: 0;
    color: var(--green-950);
    font-size: 18px;
}

.surface-header p {
    margin: 4px 0 0;
    color: var(--muted);
}

.primary-action {
    display: inline-flex;
    align-items: center;
    min-height: var(--ui-field-height);
    padding: 0 13px;
    color: #fff;
    background: var(--green-900);
    border-radius: 6px;
    font-weight: 700;
    border: 0;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(0, 60, 44, 0.16);
}

/* Action labels are atomic UI commands.  Let the action cell scroll or grow;
 * never split a command into overlapping lines. */
.primary-action,
.secondary-action,
.table-action,
.workflow-inline-action {
    white-space: nowrap;
}

/* Compact table workflow actions are shared across modules.  CRM established
 * this contract; ERP/OA reuse the same class instead of recreating local
 * button colors, spacing and interaction states. */
.workflow-inline-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 5px 10px;
    color: #fff;
    background: var(--green-900);
    border: 1px solid var(--green-900);
    border-radius: 6px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
}

.workflow-inline-action:hover,
.workflow-inline-action:focus-visible {
    color: #fff;
    background: var(--green-950);
    border-color: var(--green-950);
}

.workflow-inline-action:focus-visible {
    outline: 3px solid rgba(11, 107, 79, 0.16);
    outline-offset: 2px;
}

.workflow-inline-action.is-disabled {
    color: var(--muted);
    background: #f2f5f3;
    border-color: #d8e0dc;
    cursor: not-allowed;
    opacity: 0.78;
}

/* Shared action controls.  Templates in OA, CRM, ERP and System all use
 * these semantic classes, so their visual contract must live in the shared
 * stylesheet rather than depending on a different module's CSS. */
.secondary-action,
.secondary-button,
.danger-outline-button,
.danger-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 13px;
    border-radius: var(--ui-field-radius);
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.secondary-action,
.secondary-button {
    color: var(--green-900);
    background: #fff;
    border: 1px solid var(--line-strong);
}

.danger-outline-button {
    color: #a43c30;
    background: #fff;
    border: 1px solid #e2a59d;
}

.danger-button {
    color: #fff;
    background: #b84b3e;
    border: 1px solid #b84b3e;
}

.secondary-action:hover,
.secondary-button:hover,
.secondary-action:focus-visible,
.secondary-button:focus-visible {
    color: var(--green-950);
    background: #f1f8f4;
    border-color: var(--green-700);
}

.danger-outline-button:hover,
.danger-outline-button:focus-visible {
    color: #8d2f25;
    background: #fff4f2;
    border-color: #c96b60;
}

.danger-button:hover,
.danger-button:focus-visible {
    background: #a33d32;
    border-color: #a33d32;
}

.secondary-action:focus-visible,
.secondary-button:focus-visible,
.danger-outline-button:focus-visible,
.danger-button:focus-visible,
.primary-action:focus-visible {
    outline: 3px solid rgba(11, 107, 79, 0.16);
    outline-offset: 2px;
}

.secondary-action[disabled],
.secondary-button[disabled],
.danger-outline-button[disabled],
.danger-button[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}

.compact-action,
.compact-button {
    min-height: 30px;
    padding: 0 10px;
    font-size: 12px;
    box-shadow: none;
}

.table-wrap {
    overflow-x: auto;
    scrollbar-color: var(--line-strong) transparent;
}

.data-table {
    width: 100%;
    min-width: 820px;
    border-collapse: collapse;
}

.data-table-wide {
    min-width: 2100px;
}

.data-table th,
.data-table td {
    padding: 9px 14px;
    border-bottom: 1px solid #e8f0eb;
    text-align: left;
    white-space: nowrap;
}

.data-table th {
    color: #436258;
    background: #f5faf7;
    font-size: 13px;
    font-weight: 800;
}

.data-table td {
    color: #203c34;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.data-table tbody tr:hover {
    background: #fbfdfc;
}

.data-table tr:last-child td {
    border-bottom: 0;
}

.pagination-bar {
    display: grid;
    grid-template-columns: auto minmax(160px, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 14px 20px 18px;
    border-top: 1px solid var(--line);
    background: #fbfdfc;
}

.page-size-form {
    margin: 0;
}

.page-size-form label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
}

.page-size-form select {
    min-width: 92px;
    height: 34px;
    padding: 0 9px;
    color: var(--text);
    background: #fff;
    border: 1px solid #c9ddd2;
    border-radius: 6px;
    font-weight: 700;
}

.page-range-info {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-align: center;
}

.page-links {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.page-link {
    min-width: 36px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 11px;
    color: var(--green-900);
    background: #fff;
    border: 1px solid #c9ddd2;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
}

.page-link:hover {
    border-color: var(--green-700);
    background: #f1faf5;
}

.page-link.active {
    color: #fff;
    background: var(--green-900);
    border-color: var(--green-900);
}

.page-jump-form {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 8px;
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.page-jump-form label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    white-space: nowrap;
}

.page-jump-form input[type="number"] {
    width: 64px;
    min-width: 64px;
    height: 34px;
    padding: 0 6px;
    border: 1px solid #c9ddd2;
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    font: inherit;
    text-align: center;
}

.page-jump-form button { cursor: pointer; }
.page-jump-total { white-space: nowrap; }

.page-link.disabled {
    color: #9aa9a1;
    background: #f4f7f5;
    cursor: not-allowed;
}

.empty-state {
    margin: 20px;
    padding: 34px;
    background: var(--green-50);
    border: 1px dashed var(--line-strong);
    border-radius: 8px;
    text-align: center;
}

.empty-state h2 {
    margin: 0 0 8px;
    color: var(--green-950);
}

.empty-state p {
    margin: 0;
    color: var(--muted);
}

.status-page-body {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at 15% 18%, rgba(10, 117, 82, 0.1), transparent 32%),
        var(--page);
}

.status-page-layout {
    width: min(680px, calc(100% - 32px));
    min-height: 100vh;
    margin: 0 auto;
    display: grid;
    align-content: center;
    gap: 22px;
}

.status-page-brand {
    width: fit-content;
    display: inline-flex;
    align-items: center;
    gap: 14px;
    color: var(--green-950);
    font-size: 18px;
    font-weight: 800;
    text-decoration: none;
}

.status-page-brand img {
    width: 162px;
    height: 46px;
    object-fit: contain;
    object-position: left center;
}

.status-page-card {
    padding: 40px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.status-page-code {
    margin: 0 0 6px;
    color: var(--green-700);
    font-size: 42px;
    font-weight: 900;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.status-page-card h1 {
    margin: 0;
    color: var(--green-950);
    font-size: 28px;
}

.status-page-card > p:not(.status-page-code) {
    max-width: 520px;
    margin: 14px 0 0;
    color: var(--muted);
    line-height: 1.75;
}

.status-page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 28px;
}

@media (max-width: 640px) {
    .status-page-layout {
        width: min(100% - 24px, 680px);
    }

    .status-page-brand {
        gap: 10px;
        font-size: 15px;
    }

    .status-page-brand img {
        width: 132px;
        height: 40px;
    }

    .status-page-card {
        padding: 28px 22px;
    }

    .status-page-card h1 {
        font-size: 24px;
    }
}

.message-stack {
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.message {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: #fff;
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.message.is-hiding {
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
}

.message-text {
    min-width: 0;
    flex: 1 1 auto;
    overflow-wrap: anywhere;
}

.message-dismiss {
    width: 30px;
    min-width: 30px;
    height: 30px;
    padding: 0;
    display: inline-grid;
    place-items: center;
    color: currentColor;
    background: transparent;
    border: 0;
    border-radius: 6px;
    box-shadow: none;
    font: inherit;
    font-size: 18px;
    line-height: 1;
}

.message-dismiss:hover {
    background: rgba(0, 60, 44, 0.08);
    box-shadow: none;
    transform: none;
}

.message-dismiss:focus-visible {
    outline: 3px solid rgba(11, 107, 79, 0.2);
    outline-offset: 1px;
}

@media (prefers-reduced-motion: reduce) {
    .message {
        transition: none;
    }
}

.message.success {
    color: var(--green-950);
    background: var(--green-50);
    border-color: var(--line-strong);
}

.message.error {
    color: var(--danger);
    background: #fff4f2;
    border-color: #f0c6bf;
}

/*
 * Compact desktop header
 * ----------------------
 * Edge commonly runs at 125% display scaling, which leaves roughly
 * 1000-1200 CSS pixels in an otherwise desktop-sized window. Keep the shell
 * in desktop mode at that width, but remove optional brand copy and tighten
 * navigation spacing so module labels and account controls never collapse
 * into vertical text.
 */
@media (min-width: 981px) and (max-width: 1200px) {
    .topbar {
        gap: 12px;
        padding-right: 14px;
        padding-left: 14px;
    }

    .topbar-brand {
        flex-basis: var(--app-sidebar-width);
        width: var(--app-sidebar-width);
        min-width: var(--app-sidebar-width);
    }

    .topbar-brand img {
        width: 126px;
    }

    .topbar-brand span {
        display: none;
    }

    .module-nav {
        gap: 1px;
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-inline: contain;
        scrollbar-width: none;
    }

    .module-nav::-webkit-scrollbar {
        display: none;
    }

    .module-nav a {
        height: 44px;
        padding-right: 8px;
        padding-left: 8px;
        font-size: 13px;
    }

    .module-nav-summary {
        font-size: 8px;
    }

    .user-box {
        gap: 8px;
    }

    .user-profile-link {
        gap: 6px;
    }

    .logout-link {
        padding-left: 8px;
        font-size: 13px;
    }
}

@media (min-width: 981px) and (max-width: 1160px) {
    .sidebar-menu {
        padding-right: 10px;
        padding-left: 10px;
    }

    .sidebar-group {
        padding-left: 12px;
    }

    .sidebar-group::before {
        left: 3px;
    }

    .sidebar-menu a {
        gap: 5px;
        padding-right: 8px;
        padding-left: 12px;
    }

    .company-switcher {
        padding: 10px;
    }
}


@media (min-width: 1201px) and (max-width: 1700px) {
    .topbar-brand span {
        display: none;
    }
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }

    .topbar {
        position: sticky;
        top: 0;
        z-index: 40;
        display: grid;
        grid-template-columns: 38px minmax(0, 1fr) auto;
        grid-template-areas:
            "menu brand user"
            "nav nav nav";
        align-items: center;
        height: auto;
        gap: 10px 12px;
        padding: 10px 16px 12px;
    }


    .mobile-menu-button {
        grid-area: menu;
        display: grid;
        gap: 4px;
        width: 38px;
        height: 38px;
        place-content: center;
        background: #fff;
        border: 1px solid var(--line);
        border-radius: 8px;
        cursor: pointer;
    }

    .mobile-menu-button span {
        display: block;
        width: 18px;
        height: 2px;
        background: var(--green-900);
        border-radius: 999px;
    }

    .topbar-brand {
        grid-area: brand;
        width: auto;
        min-width: 0;
        gap: 10px;
        overflow: hidden;
    }

    .topbar-brand img {
        width: 118px;
    }

    .topbar-brand span {
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 13px;
    }

    .module-nav {
        grid-area: nav;
        width: 100%;
        height: auto;
        min-width: 0;
        overflow-x: auto;
        padding: 2px 0 0;
        scrollbar-width: thin;
    }

    .module-nav a {
        flex: 0 0 auto;
        height: 44px;
    }

    .user-box {
        grid-area: user;
        margin-left: 0;
        min-width: 0;
        justify-self: end;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 60;
        width: min(320px, calc(100vw - 44px));
        min-height: 100dvh;
        transform: translateX(-104%);
        transition: transform 0.2s ease;
        border-right: 1px solid var(--line);
        border-bottom: 0;
        box-shadow: 18px 0 42px rgba(0, 60, 44, 0.18);
    }

    .sidebar-drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-height: 60px;
        padding: 10px 16px;
        border-bottom: 1px solid var(--line);
        color: var(--green-950);
        font-weight: 700;
    }

    .sidebar-close-button {
        display: grid;
        width: 36px;
        height: 36px;
        place-items: center;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: #fff;
        color: var(--green-950);
        cursor: pointer;
        font-size: 22px;
        line-height: 1;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 55;
        background: rgba(0, 60, 44, 0.28);
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    .sidebar-menu {
        display: grid;
        gap: 10px;
        overflow-y: auto;
        padding: 8px 16px 14px;
    }

    .sidebar-section {
        min-width: 0;
        padding: 4px 0 8px;
        background: transparent;
        border: 0;
        border-bottom: 1px solid rgba(216, 231, 222, 0.72);
        border-radius: 0;
    }

    .sidebar-group {
        margin-top: 0;
    }

    .company-switcher {
        margin-top: 0;
        padding: 12px 16px 16px;
    }

    .company-options {
        left: 16px;
        right: auto;
        bottom: calc(100% + 8px);
        width: min(320px, calc(100vw - 32px));
    }

    .company-options label {
        justify-content: flex-start;
    }

    .content {
        padding: 20px 16px 28px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .page-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .page-heading h1 {
        font-size: 24px;
    }

    .surface-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .table-wrap {
        margin: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .data-table {
        min-width: 720px;
    }

    .pagination-bar {
        grid-template-columns: 1fr;
        align-items: flex-start;
    }

    .page-range-info {
        text-align: left;
    }

    .page-links {
        justify-content: flex-start;
        width: 100%;
    }
}

@media (max-width: 640px) {
    body {
        font-size: 14px;
    }

    .topbar {
        grid-template-columns: 36px minmax(0, 1fr) auto;
        gap: 8px 10px;
        padding: 9px 12px 10px;
    }

    .mobile-menu-button {
        width: 36px;
        height: 36px;
    }

    .topbar-brand img {
        width: 106px;
    }

    .topbar-brand span {
        display: none;
    }

    .module-nav {
        width: 100%;
        padding-bottom: 2px;
    }

    .module-nav a {
        flex: 0 0 auto;
        height: 44px;
        padding: 0 12px;
        min-width: 56px;
        justify-content: center;
    }

    .user-box {
        gap: 8px;
    }

    .user-name {
        display: none;
    }

    .logout-link {
        padding-left: 8px;
        font-size: 13px;
    }

    .sidebar-menu {
        padding: 8px 12px 12px;
    }

    .sidebar-section {
        min-width: 172px;
    }

    .sidebar-menu a {
        min-height: 38px;
        padding-left: 12px;
    }

    .company-switcher {
        padding: 12px;
    }

    .company-options {
        left: 12px;
        width: calc(100vw - 24px);
    }

    .company-options label {
        justify-content: flex-start;
    }

    .content {
        padding: 16px 12px 24px;
    }

    .page-heading {
        gap: 10px;
        margin-bottom: 14px;
    }

    .page-heading h1 {
        font-size: 22px;
    }

    .page-heading p {
        line-height: 1.5;
    }

    .stat-card {
        padding: 10px 12px;
    }

    .work-surface {
        border-radius: 8px;
    }

    .surface-header {
        padding: 14px 16px;
    }

    .data-table {
        min-width: 680px;
    }

    .data-table th,
    .data-table td {
        padding: 11px 12px;
    }

    .pagination-bar {
        padding: 12px 14px 16px;
    }

    .page-size-form,
    .page-size-form label,
    .page-size-form select {
        width: 100%;
    }

    .page-link {
        flex: 1 1 auto;
        min-width: 44px;
    }

    .empty-state {
        margin: 14px;
        padding: 24px 16px;
    }
}

@media (max-width: 380px) {
    .topbar {
        grid-template-columns: 34px minmax(0, 1fr) auto;
        padding-left: 10px;
        padding-right: 10px;
    }

    .mobile-menu-button {
        width: 34px;
        height: 34px;
    }

    .topbar-brand img {
        width: 94px;
    }

    .user-avatar {
        width: 28px;
        height: 28px;
    }

    .topbar-current-company {
        max-width: 5.5em;
        padding-right: 6px;
        font-size: 12px;
    }

    .logout-link {
        font-size: 12px;
    }

    .module-nav a {
        min-width: 52px;
        padding: 0 10px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/*
 * Shared mobile contract
 * ----------------------
 * Page styles keep their desktop-specific density, while these rules provide
 * a safe phone fallback for every module. Page CSS may still refine its own
 * component, but it should not need to rebuild navigation, scrolling or
 * single-column form behavior.
 */
@media (max-width: 720px) {
    html,
    body {
        max-width: 100%;
        overflow-x: hidden;
    }

    .topbar {
        padding-top: max(9px, env(safe-area-inset-top));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-left: max(12px, env(safe-area-inset-left));
    }

    .sidebar {
        padding-left: env(safe-area-inset-left);
    }

    .content {
        min-width: 0;
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(24px, env(safe-area-inset-bottom));
        padding-left: max(12px, env(safe-area-inset-left));
    }

    .content :where(
        [class$="-grid"],
        [class*="-grid "],
        form[class*="filter"],
        [class$="-filter"],
        [class*="-filter "]
    ) {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .content :where(
        [class$="-actions"],
        [class*="-actions "],
        [class$="-toolbar"],
        [class*="-toolbar "]
    ) {
        flex-wrap: wrap;
        max-width: 100%;
    }

    .content :where(input, select, textarea, button) {
        min-width: 0;
        max-width: 100%;
    }

    .content :where(img, video, svg) {
        max-width: 100%;
    }

    .content :where(button, .primary-action, .secondary-button, .compact-action) {
        min-height: 40px;
        touch-action: manipulation;
    }

    .table-wrap {
        max-width: 100%;
        overscroll-behavior-inline: contain;
    }
}

.team-task-filter {
    display: grid;
    grid-template-columns: minmax(300px, 1fr) minmax(180px, 260px) auto;
    gap: 12px;
    align-items: end;
    padding: 14px 16px;
}

.team-task-filter label {
    min-width: 0;
}

.team-task-table td strong,
.team-task-table td small {
    display: block;
}

.team-task-table td small {
    margin-top: 3px;
    color: #687c76;
}

@media (max-width: 980px) {
    .team-task-filter {
        grid-template-columns: 1fr;
    }
}
