:root {
    color-scheme: light;
    --bg: #f8faf9;
    --surface: #ffffff;
    --surface-soft: #eef7f4;
    --ink: #18211f;
    --muted: #66736e;
    --line: #d9e2de;
    --primary: #0f766e;
    --primary-strong: #0b5f58;
    --accent: #b7791f;
    --danger: #b42318;
    --success: #166534;
    --shadow: 0 10px 24px rgba(24, 33, 31, 0.08);
}

* {
    box-sizing: border-box;
}

html,
body,
#app {
    min-height: 100%;
    width: 100%;
    overflow-x: hidden;
}

html {
    direction: rtl;
}

body {
    margin: 0;
    direction: rtl;
    background: var(--bg);
    color: var(--ink);
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 16px;
    letter-spacing: 0;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    direction: rtl;
    width: 100%;
    min-height: 100dvh;
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
    overflow-x: hidden;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
    background: rgba(248, 250, 249, 0.96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
    width: 100%;
    max-width: 100vw;
}

.app-header h1,
.page-heading h2,
.section-title h3,
.item-card h4,
.placeholder-panel h3 {
    margin: 0;
    letter-spacing: 0;
    overflow-wrap: anywhere;
}

.app-header h1 {
    font-size: 1.2rem;
}

.app-kicker,
.eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 0.78rem;
}

.app-badge,
.count-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--primary-strong);
    font-size: 0.86rem;
    white-space: nowrap;
}

.app-badge-button {
    cursor: pointer;
    font-weight: 700;
}

.app-main {
    width: 100%;
    max-width: 980px;
    margin: 0 auto;
    padding: 18px 14px 28px;
    overflow-x: hidden;
}

.page-stack {
    display: grid;
    gap: 14px;
    width: 100%;
    min-width: 0;
}

.page-heading,
.section-title,
.item-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
}

.page-heading > div:first-child,
.app-header > div:first-child,
.item-topline > div:first-child {
    flex: 1 1 auto;
    min-width: 0;
    text-align: right;
}

.app-badge,
.count-chip {
    flex: 0 0 auto;
}

.page-heading h2 {
    font-size: 1.45rem;
}

.section-title h3 {
    font-size: 1.04rem;
}

.panel,
.placeholder-panel {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    box-shadow: var(--shadow);
}

.section-block {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.form-grid,
.compact-grid,
.import-grid {
    display: grid;
    gap: 12px;
}

.field-group {
    display: grid;
    gap: 6px;
    min-width: 0;
}

label,
dt {
    color: var(--muted);
    font-size: 0.88rem;
}

.field {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 52px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    padding: 10px 12px;
    outline: none;
}

.field:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.readonly-field {
    background: var(--surface-soft);
    color: var(--primary-strong);
    font-weight: 700;
}

.two-columns {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
}

.primary-action,
.secondary-action,
.danger-link {
    min-height: 48px;
    border-radius: 8px;
    border: 1px solid transparent;
    padding: 10px 14px;
    font-weight: 700;
}

.primary-action {
    width: 100%;
    margin-top: 14px;
    background: var(--primary);
    color: #fff;
}

.primary-action:active {
    background: var(--primary-strong);
}

.secondary-action {
    background: var(--surface-soft);
    color: var(--primary-strong);
    border-color: #c8ded8;
}

.danger-link {
    background: #fff5f5;
    color: var(--danger);
    border-color: #f0c7c3;
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.action-row > * {
    flex: 1 1 150px;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.notice {
    margin-top: 12px;
    border-radius: 8px;
    padding: 10px 12px;
    line-height: 1.8;
}

.notice p {
    margin: 0;
}

.notice.danger {
    background: #fff1f0;
    color: var(--danger);
    border: 1px solid #f0c7c3;
}

.notice.success {
    background: #effaf1;
    color: var(--success);
    border: 1px solid #c9e8cf;
}

.suggestion-panel {
    display: grid;
    gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.suggestion-title {
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 700;
}

.suggestion-list {
    display: grid;
    gap: 8px;
}

.suggestion-button {
    display: grid;
    gap: 3px;
    width: 100%;
    min-height: 58px;
    padding: 10px 12px;
    border: 1px solid #c8ded8;
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--ink);
    text-align: right;
}

.suggestion-button span,
.suggestion-button small {
    overflow-wrap: anywhere;
}

.suggestion-button span {
    font-weight: 700;
}

.suggestion-button small {
    color: var(--muted);
    line-height: 1.5;
}

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

.item-card {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.item-card.detailed {
    display: grid;
}

.item-card h4 {
    font-size: 1rem;
    overflow-wrap: anywhere;
}

.item-card p,
.price-stack small,
.placeholder-panel p {
    margin: 4px 0 0;
    color: var(--muted);
    line-height: 1.7;
}

.price-stack {
    display: grid;
    justify-items: end;
    gap: 2px;
    min-width: max-content;
    color: var(--primary-strong);
    font-weight: 700;
}

.fact-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 10px 0 0;
}

.fact-grid div {
    min-width: 0;
    padding: 10px;
    border-radius: 8px;
    background: #fbfcfc;
    border: 1px solid var(--line);
}

.fact-grid dt,
.fact-grid dd {
    margin: 0;
}

.fact-grid dd {
    margin-top: 4px;
    overflow-wrap: anywhere;
    font-weight: 700;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.metric-card {
    display: grid;
    gap: 4px;
    min-height: 126px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.metric-card span,
.metric-card small {
    color: var(--muted);
}

.metric-card strong {
    align-self: end;
    font-size: clamp(1.18rem, 4vw, 1.65rem);
    overflow-wrap: anywhere;
}

.metric-card.accent {
    border-color: #e5d2ad;
    background: #fffaf0;
}

.file-picker {
    display: grid;
    align-items: center;
    min-height: 54px;
    padding: 10px 12px;
    border: 1px dashed var(--primary);
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--primary-strong);
    font-weight: 700;
}

.file-picker input {
    margin-top: 8px;
    max-width: 100%;
}

.empty-state {
    display: grid;
    place-items: center;
    min-height: 220px;
    padding: 24px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.empty-state.compact {
    min-height: 96px;
    color: var(--muted);
}

.placeholder-panel {
    display: grid;
    place-items: center;
    min-height: 320px;
    text-align: center;
}

.placeholder-mark {
    display: grid;
    place-items: center;
    width: 72px;
    height: 72px;
    margin-bottom: 12px;
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--primary);
    font-size: 2rem;
}

.bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(14px);
    width: 100%;
    max-width: 100vw;
}

.nav-item {
    display: grid;
    place-items: center;
    gap: 3px;
    min-height: 58px;
    color: var(--muted);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 700;
}

.nav-item.active {
    background: var(--surface-soft);
    color: var(--primary-strong);
}

.nav-icon {
    font-size: 1.18rem;
    line-height: 1;
}

.boot-screen {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 12px;
    min-height: 100dvh;
    color: var(--primary-strong);
}

.boot-mark {
    display: grid;
    place-items: center;
    width: 96px;
    height: 96px;
    border-radius: 8px;
    background: var(--surface-soft);
    border: 1px solid #c8ded8;
    font-weight: 800;
}

.boot-text {
    color: var(--muted);
}

.auth-shell {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding: calc(18px + env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom));
    background: var(--bg);
}

.auth-panel {
    display: grid;
    gap: 14px;
    width: min(100%, 420px);
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.auth-brand h1 {
    margin: 0;
    font-size: 1.35rem;
    letter-spacing: 0;
}

.auth-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

#blazor-error-ui {
    color-scheme: light only;
    display: none;
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1000;
    padding: 0.8rem 1rem;
    background: #fff4d6;
    border-top: 1px solid #e5d2ad;
    color: #4b3713;
}

#blazor-error-ui .reload {
    color: var(--primary-strong);
    font-weight: 700;
}

#blazor-error-ui .dismiss {
    position: absolute;
    left: 0.75rem;
    top: 0.5rem;
    cursor: pointer;
    font-size: 1.2rem;
}

.validation-message {
    color: var(--danger);
}

@media (min-width: 720px) {
    .app-main {
        padding: 24px 18px 36px;
    }

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

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

    .import-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        align-items: stretch;
    }

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

@media (max-width: 380px) {
    .fact-grid,
    .metric-grid {
        grid-template-columns: 1fr;
    }

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