/* Market analysis workspace styling */

.ma-shell {
    --ma-ink: rgb(15, 23, 42);
    --ma-muted: rgb(100, 116, 139);
    --ma-soft: rgb(148, 163, 184);
    --ma-surface: rgba(255, 255, 255, 0.96);
    --ma-surface-soft: rgba(248, 250, 252, 0.92);
    --ma-border: rgba(15, 23, 42, 0.08);
    --ma-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
    --ma-shadow-soft: 0 12px 28px rgba(15, 23, 42, 0.06);
    --ma-blue: rgb(37, 99, 235);
    --ma-green: rgb(22, 163, 74);
    --ma-amber: rgb(217, 119, 6);
    --ma-red: rgb(220, 38, 38);
    position: relative;
    width: min(1280px, calc(100% - 3rem));
    margin: 0 auto;
    padding: 0.55rem 0 1.35rem;
    display: grid;
    gap: 1rem;
    color: var(--ma-ink);
}

html.dark-mode .ma-shell {
    --ma-ink: rgb(241, 245, 249);
    --ma-muted: rgb(148, 163, 184);
    --ma-soft: rgb(125, 143, 167);
    --ma-surface: rgba(23, 23, 23, 0.92);
    --ma-surface-soft: rgba(15, 15, 15, 0.98);
    --ma-border: rgba(148, 163, 184, 0.12);
    --ma-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
    --ma-shadow-soft: 0 16px 34px rgba(0, 0, 0, 0.2);
}

.ma-shell *,
.ma-shell *::before,
.ma-shell *::after {
    box-sizing: border-box;
}

.ma-shell .space-y-6 > :not([hidden]) ~ :not([hidden]) {
    margin-top: 0;
}

.ma-topbar,
.ma-panel,
.ma-kpi,
.ma-tab-shell,
.ma-empty-state,
.ma-hero {
    border: 1px solid var(--ma-border);
    background: var(--ma-surface);
    box-shadow: var(--ma-shadow-soft);
    backdrop-filter: blur(16px);
}

.ma-topbar {
    position: sticky;
    top: var(--topbar-height, 0);
    z-index: 30;
    border-radius: 1rem;
    overflow: hidden;
}

.ma-topbar__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 64px;
    padding: 0.95rem 1.15rem;
}

.ma-topbar__brand,
.ma-topbar__actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.ma-back-link,
.ma-icon-badge {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ma-back-link {
    color: var(--ma-muted);
    border: 1px solid var(--ma-border);
    background: rgba(255, 255, 255, 0.04);
}

.ma-icon-badge {
    color: white;
    background: rgb(22, 163, 74);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.ma-topbar__divider {
    width: 1px;
    height: 22px;
    background: var(--ma-border);
}

.ma-topbar__eyebrow {
    display: block;
    font-size: 0.72rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--ma-soft);
    margin-bottom: 0.2rem;
}

.ma-topbar__title {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--ma-ink);
}

.ma-status-dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 999px;
    background: rgb(34, 197, 94);
    box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.12);
}

.ma-topbar__subtitle {
    font-size: 0.85rem;
    color: var(--ma-muted);
}

.ma-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    min-height: auto;
    padding: 7px 14px;
    border-radius: 6px;
    border: 1px solid var(--ma-border);
    font-size: 13px;
    font-weight: 500;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
    white-space: nowrap;
    line-height: 1.2;
}

.ma-btn:hover {
    transform: none;
}

.ma-btn--primary {
    color: white;
    background: rgb(22, 163, 74);
    border-color: rgb(22, 163, 74);
    box-shadow: 0 1px 2px rgba(0,0,0,.12);
}

.ma-btn--primary:hover {
    background: rgb(21, 128, 61);
    border-color: rgb(21, 128, 61);
}

.ma-btn--ghost {
    color: var(--ma-ink);
    background: transparent;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

html.dark-mode .ma-btn--ghost,
html.dark-mode .ma-back-link {
    background: transparent;
}

.ma-hero {
    position: relative;
    overflow: hidden;
    padding: 1.2rem;
    border-radius: 1rem;
    background: linear-gradient(145deg, rgba(15, 15, 15, 0.98), rgba(23, 23, 23, 0.96));
    box-shadow: var(--ma-shadow);
}

html.dark-mode .ma-hero {
    background: linear-gradient(145deg, rgba(15, 15, 15, 0.98), rgba(23, 23, 23, 0.96));
}

.ma-hero__grid {
    display: grid;
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
    gap: 0.8rem;
    align-items: start;
}

.ma-hero__headline {
    max-width: 27rem;
    padding-right: 0.25rem;
}

.ma-hero__headline h1 {
    margin: 0;
    font-size: clamp(1.35rem, 2.2vw, 1.9rem);
    line-height: 1.06;
    letter-spacing: -0.035em;
    font-weight: 700;
    color: rgb(248, 250, 252);
}

.ma-hero__headline p {
    margin: 0.75rem 0 0;
    max-width: 26rem;
    font-size: 0.9rem;
    line-height: 1.45;
    color: rgb(166, 181, 203);
}

.ma-hero__pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.8rem;
}

.ma-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.38rem 0.68rem;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 600;
    color: rgb(226, 232, 240);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(148, 163, 184, 0.18);
}

html.dark-mode .ma-pill {
    background: rgba(255, 255, 255, 0.04);
}

.ma-filters {
    display: grid;
    gap: 0.75rem;
}

.ma-filter-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.ma-field,
.ma-date-card {
    padding: 0.75rem;
    border-radius: 1rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(148, 163, 184, 0.14);
}

html.dark-mode .ma-field,
html.dark-mode .ma-date-card {
    background: rgba(255, 255, 255, 0.02);
}

.ma-field label,
.ma-date-card label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: rgb(128, 148, 177);
    text-transform: uppercase;
}

.ma-shell select,
.ma-shell input[type="date"],
.ma-shell input[type="email"],
.ma-shell input[type="number"] {
    width: 100%;
    min-height: 2.55rem;
    border-radius: 8px;
    border: 1px solid var(--ma-border);
    background: rgba(255, 255, 255, 0.03);
    color: rgb(241, 245, 249);
    box-shadow: none;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.25;
}

html.dark-mode .ma-shell select,
html.dark-mode .ma-shell input[type="date"],
html.dark-mode .ma-shell input[type="email"],
html.dark-mode .ma-shell input[type="number"] {
    background: rgba(255, 255, 255, 0.03);
}

.ma-shell select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding: 0.68rem 2.35rem 0.68rem 0.9rem;
    background-image:
        linear-gradient(45deg, transparent 50%, rgba(226, 232, 240, 0.88) 50%),
        linear-gradient(135deg, rgba(226, 232, 240, 0.88) 50%, transparent 50%);
    background-position:
        calc(100% - 16px) calc(50% - 3px),
        calc(100% - 10px) calc(50% - 3px);
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    -webkit-text-fill-color: currentColor;
}

.ma-shell select option {
    color: rgb(15, 23, 42);
    background: rgb(255, 255, 255);
}

html.dark-mode .ma-shell select option {
    color: rgb(241, 245, 249);
    background: rgb(15, 23, 42);
}

.ma-field {
    min-width: 0;
}

.ma-field select,
.ma-date-card input {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ma-shell input[type="date"] {
    padding: 0.65rem 0.85rem;
}

.ma-shell input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1) brightness(1.4);
}

.ma-date-card {
    display: grid;
    gap: 0.7rem;
}

.ma-date-card__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}

.ma-date-card__title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ma-ink);
}

.ma-date-card__copy {
    font-size: 0.84rem;
    color: rgb(160, 174, 195);
}

.ma-date-card__grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 0.65rem;
    align-items: end;
}

.ma-date-card__presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.ma-date-card .date-preset {
    border: 1px solid var(--ma-border);
    background: rgba(255, 255, 255, 0.04);
    color: rgb(212, 220, 231);
    border-radius: 999px;
    padding: 0.48rem 0.7rem;
    font-size: 0.76rem;
    font-weight: 600;
}

html.dark-mode .ma-date-card .date-preset {
    background: rgba(255, 255, 255, 0.05);
}

.ma-alert {
    display: flex;
    gap: 0.9rem;
    align-items: flex-start;
    padding: 0.85rem 1rem;
    border-radius: 0.9rem;
    border: 1px solid;
    box-shadow: var(--ma-shadow-soft);
}

.ma-alert__icon {
    flex-shrink: 0;
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ma-alert__title {
    display: block;
    margin-bottom: 0.2rem;
    font-weight: 700;
}

.ma-alert--info {
    color: rgb(30, 64, 175);
    background: rgba(239, 246, 255, 0.9);
    border-color: rgba(59, 130, 246, 0.18);
}

html.dark-mode .ma-alert--info {
    color: rgb(226, 232, 240);
    background: rgba(23, 23, 23, 0.96);
    border-color: rgba(148, 163, 184, 0.12);
}

.ma-alert--info .ma-alert__icon {
    background: rgba(22, 163, 74, 0.12);
}

.ma-alert--warning {
    color: rgb(146, 64, 14);
    background: rgba(255, 247, 237, 0.94);
    border-color: rgba(245, 158, 11, 0.2);
}

.ma-alert--warning .ma-alert__icon {
    background: rgba(245, 158, 11, 0.14);
}

.ma-alert--error {
    color: rgb(153, 27, 27);
    background: rgba(254, 242, 242, 0.94);
    border-color: rgba(239, 68, 68, 0.2);
}

.ma-alert--error .ma-alert__icon {
    background: rgba(239, 68, 68, 0.12);
}

.ma-alert ul {
    margin: 0.5rem 0 0;
    padding-left: 1rem;
}

.ma-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
}

.ma-kpi {
    position: relative;
    overflow: hidden;
    padding: 0.95rem;
    border-radius: 1rem;
    min-height: 10.5rem;
}

.ma-kpi::after {
    content: "";
    position: absolute;
    inset: auto -12% -30% auto;
    width: 7rem;
    height: 7rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
}

.ma-kpi--blue {
    background:
        radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.24), transparent 35%),
        linear-gradient(160deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.94));
    color: white;
    border-color: rgba(59, 130, 246, 0.28);
}

.ma-kpi--green {
    background:
        radial-gradient(circle at bottom right, rgba(34, 197, 94, 0.22), transparent 35%),
        linear-gradient(160deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.94));
    color: white;
    border-color: rgba(34, 197, 94, 0.24);
}

.ma-kpi--red {
    background:
        radial-gradient(circle at bottom right, rgba(239, 68, 68, 0.22), transparent 35%),
        linear-gradient(160deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.94));
    color: white;
    border-color: rgba(239, 68, 68, 0.24);
}

.ma-kpi--amber {
    background:
        radial-gradient(circle at bottom right, rgba(245, 158, 11, 0.22), transparent 35%),
        linear-gradient(160deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.94));
    color: white;
    border-color: rgba(245, 158, 11, 0.24);
}

.ma-kpi__head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.8rem;
}

.ma-kpi__icon {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ma-kpi__label {
    display: block;
    font-size: 0.76rem;
    color: rgb(148, 163, 184);
}

.ma-kpi__value {
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.3rem;
    font-size: 1.55rem;
    line-height: 1;
    letter-spacing: -0.04em;
    font-weight: 700;
}

.ma-kpi__unit {
    font-size: 0.82rem;
    color: rgb(148, 163, 184);
}

.ma-kpi__meta {
    margin-top: 0.65rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: rgb(203, 213, 225);
}

.ma-kpi__meta--positive {
    color: rgb(187, 247, 208);
}

.ma-kpi__meta--negative {
    color: rgb(254, 202, 202);
}

.ma-kpi__meta--neutral {
    color: rgba(255, 255, 255, 0.8);
}

.ma-tab-shell {
    overflow: hidden;
    border-radius: 1rem;
}

.ma-tab-shell__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1rem 0;
}

.ma-tab-shell__title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--ma-ink);
}

.ma-tab-shell__copy {
    margin-top: 0.2rem;
    font-size: 0.84rem;
    color: var(--ma-muted);
}

.ma-tab-nav {
    display: flex;
    gap: 0.45rem;
    padding: 0.75rem 1rem 0;
    overflow-x: auto;
}

.tab-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ma-muted);
    background: transparent;
    transition: all 0.2s ease;
}

.tab-button.active {
    color: rgb(240, 253, 244);
    background: rgba(22, 163, 74, 0.16);
    border-color: rgba(22, 163, 74, 0.36);
}

html.dark-mode .tab-button.active {
    color: rgb(240, 253, 244);
    background: rgba(22, 163, 74, 0.16);
}

.tab-button:hover:not(.active) {
    color: var(--ma-ink);
    background: rgba(148, 163, 184, 0.08);
}

.tab-content {
    padding: 1.05rem;
}

.ma-panel {
    padding: 1.05rem;
    border-radius: 1rem;
}

.ma-panel__header,
.ma-shell .preferences-section > .flex,
.ma-shell .chart-container > .flex:first-child {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.ma-panel__title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0;
    font-size: 0.96rem;
    font-weight: 700;
    color: var(--ma-ink);
}

.ma-source {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.72rem;
    color: var(--ma-soft);
}

.ma-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 0.28rem 0.55rem;
    font-size: 0.72rem;
    font-weight: 700;
    background: rgba(245, 158, 11, 0.12);
    color: rgb(180, 83, 9);
}

.chart-container,
.ma-shell .bg-gradient-to-br.from-blue-50,
.ma-shell .bg-gradient-to-br.from-gray-50,
.ma-shell .bg-gray-50,
.ma-shell .bg-gray-100 {
    background: var(--ma-surface-soft) !important;
    border-radius: 1rem;
    border: 1px solid var(--ma-border);
    box-shadow: none;
}

.chart-container {
    height: 360px;
    padding: 0.95rem;
}

.chart-container canvas,
.ma-shell canvas {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
}

.chart-container canvas {
    height: calc(100% - 4rem) !important;
}

.ma-shell .overflow-x-auto.bg-white,
.ma-shell table.min-w-full,
.ma-shell .market-table {
    border-radius: 1rem;
}

.market-table,
.ma-shell table.min-w-full {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.market-table th,
.ma-shell table.min-w-full th {
    padding: 0.75rem 0.85rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ma-soft) !important;
    background: rgba(148, 163, 184, 0.08) !important;
    border-bottom: 1px solid var(--ma-border) !important;
}

.market-table td,
.ma-shell table.min-w-full td {
    padding: 0.8rem 0.85rem;
    font-size: 0.86rem;
    border-bottom: 1px solid var(--ma-border) !important;
    color: var(--ma-ink);
    background: transparent !important;
}

.market-table tbody tr:hover td,
.ma-shell table.min-w-full tbody tr:hover td {
    background: rgba(59, 130, 246, 0.04) !important;
}

.pagination-controls {
    padding: 0.5rem 0 0;
}

.page-button {
    min-width: 2.25rem;
    min-height: 2.25rem;
    border-radius: 6px;
    border: 1px solid var(--ma-border);
    background: rgba(255, 255, 255, 0.82);
    color: var(--ma-muted);
}

.page-button.active {
    background: rgb(37, 99, 235);
    border-color: rgb(37, 99, 235);
    color: white;
}

html.dark-mode .page-button {
    background: rgba(15, 23, 42, 0.78);
}

.preferences-section {
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
}

.ma-preferences-actions {
    display: flex;
    gap: 0.75rem;
}

.ma-preferences-actions .ma-btn {
    min-height: auto;
    padding-inline: 14px;
}

.favorite-crop-tag {
    background: rgba(219, 234, 254, 0.92);
    color: rgb(30, 64, 175);
    border: 1px solid rgba(96, 165, 250, 0.22);
}

html.dark-mode .favorite-crop-tag {
    background: rgba(30, 64, 175, 0.28);
    color: rgb(191, 219, 254);
}

.ma-modal {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 50;
}

.ma-modal.hidden {
    display: none !important;
}

.ma-modal__dialog {
    width: 100%;
    max-width: 32rem;
    border-radius: 1.25rem;
    overflow: hidden;
    border: 1px solid var(--ma-border);
    background: var(--ma-surface);
    box-shadow: var(--ma-shadow);
}

.ma-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1rem;
    background: linear-gradient(135deg, rgb(29, 78, 216), rgb(37, 99, 235));
    color: white;
}

.ma-modal__body {
    padding: 1rem;
}

.ma-modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-top: 1rem;
}

.ma-inline-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

@media (max-width: 1024px) {
    .ma-hero__grid,
    .ma-filter-grid,
    .ma-kpi-grid,
    .ma-date-card__grid,
    .ma-inline-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .ma-date-card__grid > :last-child {
        grid-column: span 2;
    }

    .ma-hero__headline {
        max-width: none;
        padding-right: 0;
    }
}

@media (max-width: 768px) {
    .ma-shell {
        gap: 1rem;
        width: min(1240px, calc(100% - 1.5rem));
    }

    .ma-topbar {
        position: static;
    }

    .ma-topbar__inner,
    .ma-topbar__actions,
    .ma-hero__grid,
    .ma-filter-grid,
    .ma-kpi-grid,
    .ma-date-card__grid,
    .ma-inline-grid,
    .ma-shell .preferences-section > .flex,
    .ma-shell .chart-container > .flex:first-child {
        grid-template-columns: 1fr;
        flex-direction: column;
        align-items: stretch;
    }

    .ma-topbar__brand {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .ma-topbar__actions {
        width: 100%;
    }

    .ma-btn {
        width: 100%;
    }

    .ma-field,
    .ma-date-card {
        padding: 0.85rem;
    }

    .tab-content,
    .ma-panel,
    .ma-hero {
        padding: 0.9rem;
    }

    .chart-container {
        height: 300px;
    }
}
