/* Dashboard presentation layer. Keeps the existing markup and color system. */

body:has(#module-cards) .page > .page-header {
    position: relative;
    isolation: isolate;
    min-height: 190px;
    display: grid;
    align-content: end;
    align-items: start;
    justify-items: start;
    gap: 14px;
    overflow: hidden;
    border: 1px solid var(--brand-line);
    border-radius: 22px;
    background:
        linear-gradient(112deg, rgba(239, 246, 255, .98), rgba(255, 255, 255, .96) 54%, rgba(241, 245, 249, .96));
    box-shadow: 0 20px 55px rgba(23, 32, 51, .07);
    margin-bottom: 22px;
    padding: clamp(25px, 3.2vw, 42px);
}

body:has(#module-cards) .page > .page-header::before {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    border: 1px solid var(--brand-line);
    border-radius: 999px;
    background: rgba(255, 255, 255, .78);
    color: var(--brand);
    content: "Centrum pracy";
    font-size: .68rem;
    font-weight: 760;
    letter-spacing: .1em;
    padding: 6px 10px;
    text-transform: uppercase;
}

body:has(#module-cards) .page > .page-header::after {
    position: absolute;
    z-index: -1;
    top: -120px;
    right: -70px;
    width: 350px;
    height: 350px;
    border: 74px solid rgba(37, 99, 235, .055);
    border-radius: 50%;
    content: "";
}

body:has(#module-cards) .page > .page-header > div {
    max-width: 760px;
}

body:has(#module-cards) .page > .page-header h1 {
    font-size: clamp(2.15rem, 4vw, 3.35rem);
    letter-spacing: -.06em;
}

body:has(#module-cards) .page > .page-header .lead {
    max-width: 620px;
    font-size: clamp(.92rem, 1.2vw, 1.02rem);
}

.dashboard-system {
    margin-bottom: 18px;
}

.dashboard-system .dashboard-section-heading {
    align-items: center;
    margin-bottom: 10px;
}

.dashboard-system .dashboard-section-heading h2 {
    font-size: .98rem;
}

.dashboard-system .dashboard-section-heading p {
    font-size: .78rem;
}

.system-alert-grid {
    gap: 10px;
}

.system-alert,
.system-ok {
    position: relative;
    overflow: hidden;
    border-radius: 13px;
    padding: 13px 16px 13px 42px;
}

.system-alert::before,
.system-ok::before {
    position: absolute;
    top: 50%;
    left: 16px;
    display: grid;
    width: 18px;
    height: 18px;
    place-items: center;
    border-radius: 50%;
    background: currentColor;
    color: #fff;
    content: "!";
    font-size: 11px;
    font-weight: 800;
    transform: translateY(-50%);
}

.system-ok::before {
    content: "✓";
}

.system-ok > span {
    display: none;
}

.dashboard-metrics {
    gap: 14px;
}

.metric-card {
    --metric-accent: var(--brand);
    --metric-soft: var(--brand-soft);
    position: relative;
    isolation: isolate;
    min-height: 166px;
    overflow: hidden;
    border-color: transparent;
    border-radius: 17px;
    background:
        linear-gradient(145deg, var(--panel), var(--surface-hover));
    box-shadow: 0 12px 34px rgba(23, 32, 51, .065), inset 0 0 0 1px var(--line);
    padding: 20px 21px;
    transition: box-shadow 160ms ease, transform 160ms ease;
}

.metric-card:nth-child(2) {
    --metric-accent: var(--process);
    --metric-soft: var(--process-soft);
}

.metric-card:nth-child(3) {
    --metric-accent: var(--warning);
    --metric-soft: var(--warning-soft);
}

.metric-card:nth-child(4) {
    --metric-accent: var(--note);
    --metric-soft: var(--note-soft);
}

.metric-card::before {
    position: absolute;
    z-index: -1;
    top: -38px;
    right: -38px;
    width: 112px;
    height: 112px;
    border-radius: 50%;
    background: var(--metric-soft);
    content: "";
}

.metric-card::after {
    position: absolute;
    top: 18px;
    right: 18px;
    display: grid;
    width: 30px;
    height: 30px;
    place-items: center;
    border-radius: 10px;
    background: var(--metric-soft);
    color: var(--metric-accent);
    content: "→";
    font-size: 16px;
    font-weight: 760;
    transition: transform 160ms ease;
}

.metric-card:hover {
    border-color: transparent;
    box-shadow: 0 18px 42px rgba(23, 32, 51, .1), inset 0 0 0 1px var(--metric-accent);
    transform: translateY(-3px);
}

.metric-card:hover::after {
    transform: translateX(3px);
}

.metric-card.active {
    border-color: transparent;
    background: linear-gradient(145deg, var(--metric-soft), var(--panel));
    box-shadow: 0 14px 36px rgba(37, 99, 235, .1), inset 0 0 0 2px var(--metric-accent);
}

.metric-label {
    max-width: calc(100% - 44px);
    color: var(--muted-strong);
    font-size: .72rem;
    font-weight: 760;
    letter-spacing: .07em;
    text-transform: uppercase;
}

.metric-value {
    color: var(--ink);
    font-size: clamp(2.3rem, 3.6vw, 3rem);
    font-variant-numeric: tabular-nums;
    letter-spacing: -.055em;
    line-height: 1;
    margin-top: 17px;
}

.metric-value-time {
    max-width: 85%;
    font-size: clamp(1.55rem, 2.4vw, 2.1rem);
    line-height: 1.06;
}

.metric-detail {
    color: var(--muted);
    font-size: .76rem;
    line-height: 1.45;
    padding-top: 16px;
}

.dashboard-section {
    margin-top: 38px;
    scroll-margin-top: 92px;
}

.dashboard-section-heading {
    align-items: center;
    margin-bottom: 15px;
}

.dashboard-section-heading h2 {
    font-size: clamp(1.12rem, 1.5vw, 1.34rem);
    letter-spacing: -.03em;
}

.dashboard-section-heading p {
    font-size: .81rem;
    line-height: 1.5;
    margin-top: 5px;
}

.dashboard-section-heading > a {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    border: 1px solid var(--brand-line);
    border-radius: 10px;
    background: var(--brand-soft);
    font-size: .78rem;
    font-weight: 700;
    padding: 7px 11px;
}

.dashboard-section-heading > a:hover {
    border-color: var(--brand);
    background: var(--info-hover);
    text-decoration: none;
}

.dashboard-conversation-list {
    overflow: hidden;
    border-radius: 18px;
    box-shadow: 0 14px 40px rgba(23, 32, 51, .055);
}

.dashboard-conversation-item {
    position: relative;
    border-bottom-color: rgba(216, 225, 234, .82);
    background: var(--panel);
    transition: background-color 140ms ease, box-shadow 140ms ease;
}

.dashboard-conversation-item::before {
    position: absolute;
    z-index: 1;
    top: 12px;
    bottom: 12px;
    left: 0;
    width: 3px;
    border-radius: 0 5px 5px 0;
    background: transparent;
    content: "";
}

.dashboard-conversation-item:hover {
    z-index: 1;
    background: var(--surface-hover);
    box-shadow: inset 0 0 0 1px rgba(191, 219, 254, .5);
}

.dashboard-conversation-item.unread {
    background: linear-gradient(90deg, var(--info-soft), var(--panel) 62%);
}

.dashboard-conversation-item.unread::before {
    background: var(--brand);
}

.dashboard-conversation-main {
    gap: clamp(12px, 1.4vw, 21px);
    grid-template-columns: 10px minmax(270px, 1.7fr) minmax(140px, .65fr) minmax(105px, .45fr);
    padding: 17px 10px 17px 20px;
}

.dashboard-conversation-title {
    gap: 8px;
}

.dashboard-conversation-title strong {
    font-size: .88rem;
    font-weight: 730;
}

.dashboard-conversation-title > span:last-child {
    font-variant-numeric: tabular-nums;
}

.dashboard-conversation-subject {
    color: var(--ink-soft);
    font-size: .88rem;
    font-weight: 680;
    margin-top: 3px;
}

.dashboard-conversation-preview {
    color: var(--muted);
    font-size: .76rem;
    margin-top: 3px;
}

.dashboard-conversation-context {
    display: grid;
    align-content: center;
    justify-items: start;
    gap: 3px;
}

.dashboard-conversation-context strong {
    color: var(--ink-soft);
    font-size: .77rem;
}

.dashboard-conversation-context span {
    display: inline-flex;
    max-width: 100%;
    border-radius: 999px;
    background: var(--neutral-soft);
    color: var(--neutral-ink);
    font-size: .68rem;
    padding: 3px 8px;
}

.dashboard-waiting {
    display: grid;
    align-content: center;
    justify-items: end;
    gap: 3px;
}

.dashboard-waiting span {
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.dashboard-waiting strong {
    display: inline-flex;
    border: 1px solid var(--warning-line);
    border-radius: 999px;
    background: var(--warning-soft);
    font-size: .75rem;
    padding: 4px 8px;
}

.dashboard-conversation-actions {
    gap: 7px;
    border-left: 1px solid rgba(216, 225, 234, .64);
    padding: 12px 15px;
}

.dashboard-conversation-actions .button.compact {
    min-height: 36px;
    border-radius: 10px;
    font-size: .75rem;
    padding-inline: 11px;
}

.dashboard-empty {
    padding-block: 52px;
}

.dashboard-table-scroll {
    overflow: hidden auto;
    border-radius: 18px;
    box-shadow: 0 14px 40px rgba(23, 32, 51, .045);
}

.dashboard-table {
    font-variant-numeric: tabular-nums;
}

.dashboard-table th,
.dashboard-table td {
    border-bottom-color: rgba(216, 225, 234, .78);
    padding: 15px 18px;
}

.dashboard-table thead th {
    position: sticky;
    z-index: 2;
    top: 0;
    background: var(--panel-soft);
    color: var(--muted-strong);
    font-size: .66rem;
    letter-spacing: .075em;
}

.dashboard-table tbody tr {
    background: var(--panel);
    transition: background-color 130ms ease;
}

.dashboard-table tbody tr:hover {
    background: var(--surface-hover);
}

.dashboard-table tbody th > a {
    color: var(--ink);
    font-size: .86rem;
}

.dashboard-table tbody th > a:hover {
    color: var(--brand);
}

.dashboard-count-link {
    display: inline-grid;
    min-width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 10px;
    background: var(--brand-soft);
    font-size: 1rem;
}

.dashboard-count-link:hover {
    background: var(--info-hover);
    text-decoration: none;
}

.mail-status {
    min-height: 25px;
    font-size: .67rem;
    padding: 4px 8px;
}

.module-grid {
    gap: 13px;
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.module-card {
    position: relative;
    isolation: isolate;
    min-height: 178px;
    overflow: hidden;
    gap: 0;
    border-radius: 17px;
    padding: 19px;
}

.module-card::after {
    position: absolute;
    z-index: -1;
    right: -28px;
    bottom: -42px;
    width: 98px;
    height: 98px;
    border-radius: 50%;
    background: var(--brand-soft);
    content: "";
    opacity: .7;
    transition: transform 180ms ease;
}

.module-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
}

a.module-card:hover {
    border-color: var(--brand-line);
    box-shadow: 0 16px 38px rgba(23, 32, 51, .085);
    transform: translateY(-3px);
}

a.module-card:hover::after {
    transform: scale(1.35);
}

.module-card-product {
    margin-top: 15px;
    font-size: .63rem;
    letter-spacing: .08em;
}

.module-card-title {
    color: var(--ink);
    font-size: 1rem;
    margin-top: 4px;
}

.module-card-description {
    display: -webkit-box;
    overflow: hidden;
    color: var(--muted);
    font-size: .74rem;
    line-height: 1.45;
    margin-top: 5px;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.module-card-status {
    font-size: .72rem;
    padding-top: 14px;
}

.module-card.disabled {
    border-style: dashed;
    opacity: .68;
}

.module-card.disabled::after {
    background: var(--neutral-soft);
}

@media (max-width: 1440px) {
    .module-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 1180px) {
    .dashboard-metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .dashboard-conversation-main {
        grid-template-columns: 10px minmax(240px, 1fr) minmax(115px, .45fr) 105px;
    }

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

@media (max-width: 860px) {
    body:has(#module-cards) .page > .page-header {
        min-height: 170px;
        padding: 26px;
    }

    body:has(#module-cards) .page > .page-header::after {
        right: -130px;
    }

    .dashboard-section {
        margin-top: 32px;
        scroll-margin-top: 142px;
    }
}

@media (max-width: 700px) {
    .dashboard-conversation-item {
        grid-template-columns: 1fr;
    }

    .dashboard-conversation-main {
        grid-template-columns: 9px minmax(0, 1fr) auto;
        padding: 16px;
    }

    .dashboard-conversation-context {
        display: none;
    }

    .dashboard-conversation-actions {
        border-top: 1px solid var(--line);
        border-left: 0;
        justify-content: flex-end;
        padding: 9px 14px 11px;
    }

    .dashboard-table-scroll {
        overflow: visible;
        border: 0;
        background: transparent;
        box-shadow: none;
    }

    .dashboard-table,
    .dashboard-table tbody {
        display: block;
        min-width: 0;
    }

    .dashboard-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }

    .dashboard-table tbody {
        display: grid;
        gap: 12px;
    }

    .dashboard-table tbody tr {
        display: grid;
        overflow: hidden;
        border: 1px solid var(--line);
        border-radius: 15px;
        background: var(--panel);
        box-shadow: var(--shadow-xs);
    }

    .dashboard-table tbody th,
    .dashboard-table tbody td {
        display: flex;
        min-width: 0;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        border-bottom: 1px solid var(--line);
        padding: 12px 14px;
        text-align: right;
    }

    .dashboard-table tbody th {
        display: block;
        background: var(--panel-soft);
        text-align: left;
    }

    .dashboard-table tbody td:last-child {
        border-bottom: 0;
    }

    .dashboard-table tbody td::before {
        flex: 0 0 auto;
        color: var(--muted);
        content: "Wartość";
        font-size: .68rem;
        font-weight: 740;
        letter-spacing: .05em;
        text-transform: uppercase;
    }

    .dashboard-table tbody td:nth-child(2)::before {
        content: "Do odpowiedzi";
    }

    .dashboard-table tbody td:nth-child(3)::before {
        content: "Nieprzypisane";
    }

    .dashboard-table tbody td:nth-child(4)::before {
        content: "Najstarsza";
    }

    .dashboard-table tbody td:nth-child(5)::before {
        content: "Poczta";
    }

    .dashboard-table tbody td:nth-child(5) {
        display: block;
        text-align: left;
    }

    .dashboard-table tbody td:nth-child(5)::before {
        display: block;
        margin-bottom: 7px;
    }

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

@media (max-width: 540px) {
    body:has(#module-cards) .page > .page-header {
        min-height: 0;
        align-items: flex-start;
        border-radius: 18px;
        padding: 22px;
    }

    body:has(#module-cards) .page > .page-header::before {
        margin-bottom: 5px;
    }

    body:has(#module-cards) .page > .page-header::after {
        display: none;
    }

    .dashboard-metrics {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .metric-card {
        display: grid;
        min-height: 112px;
        align-items: center;
        gap: 3px 14px;
        grid-template-columns: 78px minmax(0, 1fr) 32px;
        grid-template-rows: auto auto;
        padding: 16px;
    }

    .metric-card::before {
        top: -56px;
        right: -56px;
    }

    .metric-card::after {
        position: static;
        grid-column: 3;
        grid-row: 1 / 3;
    }

    .metric-label {
        max-width: none;
        grid-column: 2;
        grid-row: 1;
    }

    .metric-value,
    .metric-value-time {
        max-width: none;
        grid-column: 1;
        grid-row: 1 / 3;
        font-size: 1.9rem;
        margin: 0;
    }

    .metric-value-time {
        font-size: 1.22rem;
    }

    .metric-detail {
        grid-column: 2;
        grid-row: 2;
        padding: 0;
    }

    .dashboard-section-heading {
        align-items: flex-start;
        gap: 12px;
    }

    .dashboard-section-heading > a {
        width: auto;
    }

    .dashboard-conversation-main {
        gap: 10px;
        grid-template-columns: 8px minmax(0, 1fr);
    }

    .dashboard-waiting {
        grid-column: 2;
        justify-items: start;
    }

    .dashboard-waiting span {
        display: none;
    }

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

    .module-card {
        min-height: 148px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .metric-card,
    .metric-card::after,
    .dashboard-conversation-item,
    .dashboard-table tbody tr,
    .module-card::after {
        transition: none;
    }
}
