html,
body {
    min-height: 100%;
    overflow-x: hidden;
    background: #f4f7f8;
    color: #1d2730;
    font-family: Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.45;
}

* {
    box-sizing: border-box;
}

:root {
    --jah-primary: #0f5f7a;
    --jah-primary-dark: #0b4559;
    --jah-accent: #0f9f8f;
    --jah-success: #1f8f4d;
    --jah-ink: #1d2730;
    --jah-muted: #64727f;
    --jah-border: #d7e2e6;
    --jah-border-soft: #e8eef1;
    --jah-surface: #ffffff;
    --jah-bg: #f4f7f8;
    --jah-shadow: 0 10px 26px rgba(20, 56, 70, .07);
    --jah-shadow-soft: 0 6px 18px rgba(20, 56, 70, .045);
}

a {
    color: inherit;
}

.app-title {
    font-weight: 700;
    color: var(--jah-primary-dark);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-logo {
    width: 70px;
    height: auto;
    max-height: 32px;
    margin-left: 12px;
    object-fit: contain;
    flex: 0 0 auto;
}

.app-bar {
    min-height: 64px;
    border-bottom: 1px solid var(--jah-border);
    background: rgba(255, 255, 255, .96) !important;
    backdrop-filter: blur(10px);
}

.drawer-toggle-button {
    color: var(--jah-primary-dark) !important;
    background: #eaf5f7 !important;
    border: 1px solid var(--jah-border);
}

.drawer-toggle-button:hover {
    background: #dceff3 !important;
}

.app-drawer {
    top: 64px !important;
    height: calc(100vh - 64px) !important;
    max-height: calc(100vh - 64px) !important;
}

.app-drawer .mud-drawer-content {
    height: 100%;
    overflow-y: auto;
    padding-top: 8px;
    background: linear-gradient(180deg, #ffffff 0%, #f7fafb 100%);
}

.app-drawer .mud-navmenu {
    padding-bottom: 20px;
}

.app-drawer .mud-nav-link {
    margin: 2px 10px;
    border-radius: 8px;
    color: #334550;
}

.app-drawer .mud-nav-link.active,
.app-drawer .mud-nav-link:hover {
    background: #eaf5f7;
    color: var(--jah-primary-dark);
}

.main-content {
    padding: 92px 28px 36px;
    min-width: 0;
}

.content-shell {
    width: min(1360px, 100%);
    margin: 0 auto;
    min-width: 0;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
    min-width: 0;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--jah-border-soft);
}

.page-header > div:first-child {
    min-width: 0;
}

.page-header .mud-typography {
    overflow-wrap: anywhere;
}

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

.toolbar-surface,
.section-surface,
.metric-card,
.ranking-card {
    border: 1px solid var(--jah-border);
    border-radius: 8px;
    background: var(--jah-surface);
    box-shadow: var(--jah-shadow-soft);
}

.toolbar-surface {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 14px 16px;
    margin-bottom: 18px;
}

.section-surface {
    padding: 20px;
    margin-bottom: 20px;
}

.metric-card {
    min-height: 136px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    justify-content: center;
    transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}

.metric-card:hover {
    transform: translateY(-1px);
    border-color: #bdd5dd;
    box-shadow: var(--jah-shadow);
}

.metric-card .mud-icon-root {
    width: 34px;
    height: 34px;
    padding: 7px;
    border-radius: 8px;
    background: #eaf5f7;
}

.metric-card .mud-typography-caption {
    color: var(--jah-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0;
}

.metric-card .mud-typography-h4 {
    color: var(--jah-ink);
    font-weight: 700;
    font-size: clamp(1.55rem, 2.5vw, 2.05rem);
}

.metric-card.success {
    border-color: #c7e4d4;
    background: linear-gradient(180deg, #ffffff 0%, #f5fbf7 100%);
}

.metric-card.success .mud-icon-root {
    background: #e7f6ed;
}

.ranking-card {
    padding: 20px;
    min-height: 280px;
}

.section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.purchase-order-table .mud-table-cell {
    vertical-align: top;
}

.purchase-order-table textarea {
    min-height: 42px;
    resize: vertical;
}

.purchase-search {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
    margin: 10px 0 12px;
}

.purchase-list-item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
}

.purchase-list-item > div:first-child {
    min-width: 0;
}

.search-results {
    margin-top: 12px;
    border: 1px solid var(--jah-border-soft);
    border-radius: 8px;
    overflow: hidden;
}

.version-history {
    border-color: #bed9e1;
    background: linear-gradient(180deg, #ffffff 0%, #f7fbfc 100%);
}

.version-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.quote-detail-toolbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.quote-detail-toolbar .version-chip-list {
    margin-top: 0;
}

.quote-group-list {
    display: grid;
    gap: 16px;
}

.quote-group {
    border: 1px solid var(--jah-border);
    border-radius: 8px;
    background: var(--jah-surface);
    padding: 16px;
    box-shadow: var(--jah-shadow-soft);
}

.quote-group-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.quote-group-meta {
    display: flex;
    align-items: flex-end;
    flex-direction: column;
    gap: 6px;
    text-align: right;
}

.compact-quote-list {
    display: grid;
    gap: 10px;
}

.compact-quote {
    border: 1px solid var(--jah-border);
    border-radius: 8px;
    background: var(--jah-surface);
    overflow: hidden;
    box-shadow: var(--jah-shadow-soft);
}

.compact-quote-header {
    width: 100%;
    border: 0;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    color: inherit;
    background: #ffffff;
    cursor: pointer;
    text-align: left;
}

.compact-quote-header:hover {
    background: #f7fafb;
}

.compact-quote-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.compact-quote-title > div {
    min-width: 0;
}

.compact-quote-title .mud-typography {
    overflow-wrap: anywhere;
}

.compact-quote-summary {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    color: var(--jah-muted);
    text-align: right;
}

.compact-quote-summary strong {
    color: var(--jah-primary);
}

.compact-quote-body {
    padding: 0 16px 16px;
    border-top: 1px solid var(--jah-border-soft);
    background: #ffffff;
}

.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    padding: 12px 14px;
    border: 1px solid var(--jah-border);
    border-radius: 8px;
    background: var(--jah-surface);
}

.pagination-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.quote-lines {
    overflow: hidden;
}

.quote-lines-table {
    width: 100%;
}

.quote-lines-table .mud-table-container {
    max-height: 620px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
}

.quote-lines-table table {
    min-width: var(--quote-table-min-width, 1220px);
    table-layout: fixed;
}

.quote-lines-table .mud-input-control {
    margin-top: 0;
    margin-bottom: 0;
}

.quote-lines-table .mud-table-cell {
    padding: 5px 6px;
    vertical-align: top;
    white-space: normal;
    overflow-wrap: anywhere;
}

.quote-lines-table .mud-table-cell:nth-child(1) {
    width: var(--quote-col-linea, 52px);
}

.quote-lines-table .mud-table-cell:nth-child(2) {
    width: var(--quote-col-articulo, 230px);
}

.quote-lines-table .mud-table-cell:nth-child(3) {
    width: var(--quote-col-descripcion, 280px);
}

.quote-lines-table .mud-table-cell:nth-child(4) {
    width: var(--quote-col-categoria, 160px);
}

.quote-lines-table .mud-table-cell:nth-child(5) {
    width: var(--quote-col-cantidad, 96px);
}

.quote-lines-table .mud-table-cell:nth-child(6) {
    width: var(--quote-col-precio, 96px);
}

.quote-lines-table .mud-table-cell:nth-child(7) {
    width: var(--quote-col-descuento, 96px);
}

.quote-lines-table .mud-table-cell:nth-child(8) {
    width: var(--quote-col-total, 110px);
}

.quote-lines-table .mud-table-cell:nth-child(9) {
    width: var(--quote-col-acciones, 150px);
}

.quote-lines-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.quote-column-menu {
    width: min(330px, calc(100vw - 32px));
    padding: 14px;
}

.quote-column-control {
    display: grid;
    grid-template-columns: 92px 1fr;
    gap: 10px;
    align-items: center;
    margin-top: 8px;
}

.quote-column-control span {
    color: var(--jah-muted);
    font-size: .82rem;
    font-weight: 600;
}

.line-actions {
    display: grid;
    grid-template-columns: repeat(4, 30px);
    gap: 2px;
    align-items: center;
}

.line-actions .mud-icon-button {
    width: 30px;
    height: 30px;
    padding: 4px;
}

@media (min-width: 769px) and (max-width: 1400px) {
    .main-content {
        padding-left: 18px;
        padding-right: 18px;
    }

    .content-shell {
        width: 100%;
    }

    .quote-lines {
        padding-left: 14px;
        padding-right: 14px;
    }

    .quote-lines-table table {
        min-width: var(--quote-table-min-width, 1160px);
    }
}

.totals-panel {
    position: sticky;
    top: 82px;
    border-top: 3px solid var(--jah-accent);
}

.total-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--jah-border-soft);
}

.total-row.final {
    margin-top: 6px;
    padding-top: 14px;
    border-bottom: none;
    font-size: 1.1rem;
    color: var(--jah-primary);
}

.data-table {
    border: 1px solid var(--jah-border);
    border-radius: 8px;
    overflow-x: auto;
    background: var(--jah-surface);
    max-width: 100%;
}

.data-table .mud-table-head {
    background: #f7fafb;
}

.data-table .mud-table-cell {
    border-color: var(--jah-border-soft);
}

.quote-action-bar {
    position: sticky;
    bottom: 16px;
    z-index: 5;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 8px;
    padding: 14px;
    border: 1px solid #cfe0e6;
    border-radius: 8px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 12px 30px rgba(20, 56, 70, .14);
    backdrop-filter: blur(8px);
}

.logout-form {
    margin: 0;
    flex-shrink: 0;
}

.user-chip {
    max-width: min(260px, 34vw);
}

.user-chip .mud-chip-content {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mud-dialog {
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100vh - 24px);
}

.mud-dialog-content {
    overflow-y: auto;
}

.mud-table-container {
    overflow-x: auto;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, #f4f7f8 0%, #eef5f1 100%);
}

.login-shell {
    width: min(960px, 100%);
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 32px;
    align-items: center;
}

.login-brand {
    display: grid;
    gap: 14px;
    align-content: center;
}

.login-logo {
    width: min(220px, 70vw);
    height: auto;
    object-fit: contain;
}

.login-card {
    border: 1px solid var(--jah-border);
    border-radius: 8px;
    padding: 30px;
    background: rgba(255, 255, 255, .98);
    box-shadow: var(--jah-shadow);
}

.remember-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 14px 0 18px;
    color: var(--jah-muted);
    font-size: .92rem;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    color: var(--jah-muted);
    font-size: .85rem;
    font-weight: 500;
}

.login-input {
    width: 100%;
    height: 42px;
    border: 1px solid #cbd6da;
    border-radius: 6px;
    padding: 0 12px;
    color: #1f2933;
    background: #ffffff;
    outline: none;
}

.login-input:focus {
    border-color: var(--jah-primary);
    box-shadow: 0 0 0 3px rgba(15, 95, 122, .14);
}

.blazor-error-boundary {
    background: #b32121;
    color: white;
    padding: 1rem;
}

@media (max-width: 768px) {
    .app-drawer {
        width: min(320px, calc(100vw - 32px)) !important;
    }

    .main-content {
        padding: 80px 12px 24px;
    }

    .page-header,
    .section-title-row {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar-surface {
        grid-template-columns: 1fr;
    }

    .header-actions {
        justify-content: stretch;
        width: 100%;
    }

    .header-actions .mud-button-root {
        flex: 1;
        min-width: 0;
    }

    .totals-panel {
        position: static;
    }

    .quote-lines {
        overflow: visible;
    }

    .quote-lines-table {
        min-width: 0;
    }

    .quote-lines-table .mud-table-container {
        overflow-x: visible;
        max-height: none;
    }

    .quote-lines-table table {
        min-width: 0;
    }

    .quote-lines-actions {
        justify-content: stretch;
    }

    .quote-lines-actions .mud-button-root {
        flex: 1;
    }

    .quote-lines-table .mud-table-cell,
    .quote-lines-table .mud-table-cell:nth-child(n) {
        width: auto;
        padding: 8px 10px;
    }

    .quote-lines-table .mud-input-control {
        width: 100%;
    }

    .line-actions {
        grid-template-columns: repeat(4, 36px);
        justify-content: flex-start;
    }

    .line-actions .mud-icon-button {
        width: 36px;
        height: 36px;
    }

    .quote-action-bar {
        position: static;
        flex-direction: column-reverse;
    }

    .quote-action-bar .mud-button-root {
        width: 100%;
    }

    .login-shell {
        grid-template-columns: 1fr;
    }

    .quote-group-header {
        flex-direction: column;
    }

    .quote-group-meta {
        align-items: flex-start;
        text-align: left;
    }

    .compact-quote-header,
    .pagination-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .quote-detail-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .compact-quote-summary {
        justify-content: flex-start;
        text-align: left;
    }

    .pagination-actions .mud-button-root {
        flex: 1;
    }

    .app-title {
        max-width: 42vw;
    }

    .user-chip {
        max-width: 32vw;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 76px 8px 20px;
    }

    .page-header {
        gap: 12px;
        margin-bottom: 14px;
    }

    .section-surface,
    .ranking-card,
    .login-card {
        padding: 14px;
    }

    .metric-card {
        min-height: 118px;
        padding: 14px;
    }

    .app-title {
        max-width: 34vw;
        font-size: 1rem;
    }

    .app-logo {
        width: 58px;
        height: auto;
        max-height: 28px;
        margin-left: 8px;
    }

    .user-chip {
        display: none;
    }
}

.inline-option-field {
    display: flex;
    align-items: center;
    gap: 8px;
}

.inline-option-field .mud-input-control {
    flex: 1 1 auto;
    min-width: 0;
}

.duration-field {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 112px;
    gap: 8px;
    align-items: start;
}

.autocomplete-add-row {
    border-top: 1px solid #e5edf0;
    padding: 4px 8px 6px;
    background: #fbfdfe;
}
