:root {
    color-scheme: light dark;
    --brand: #47634A;
    --brand-strong: #314A35;
    --brand-soft: #DDE9DE;
    --background: #F6F7F3;
    --surface: #FFFFFF;
    --surface-alt: #EEF1EC;
    --text: #172019;
    --muted: #5E685F;
    --border: #D5DDD5;
    --danger: #B74343;
    --danger-soft: #FBEAEA;
    --warning: #A66A18;
    --warning-soft: #FFF0D7;
    --success: #397A4B;
    --success-soft: #E3F3E7;
    --shadow: 0 10px 34px rgba(29, 48, 35, .08);
    --radius: 18px;
    --topbar: 72px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --background: #0D120F;
        --surface: #18201B;
        --surface-alt: #253029;
        --text: #FAFCFA;
        --muted: #C4CEC6;
        --border: #46544A;
        --brand-soft: #304237;
        --danger-soft: #3B2323;
        --warning-soft: #3C3020;
        --success-soft: #213C29;
        --shadow: 0 12px 38px rgba(0, 0, 0, .26);
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--background); color: var(--text); }
body { min-height: 100vh; min-height: 100dvh; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }

.boot-screen { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); }
.boot-screen img { border-radius: 22px; box-shadow: var(--shadow); }
.boot-screen strong { color: var(--text); font-size: 24px; }
#blazor-error-ui { display: none; position: fixed; inset: auto 16px 16px 16px; z-index: 200; padding: 14px 18px; border-radius: 14px; background: var(--danger); color: white; box-shadow: var(--shadow); }
#blazor-error-ui .reload { margin-left: 12px; font-weight: 700; }
#blazor-error-ui .dismiss { float: right; border: 0; background: transparent; color: white; font-size: 20px; }

.public-shell { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom)); background: radial-gradient(circle at 10% 0%, color-mix(in srgb, var(--brand-soft) 75%, transparent), transparent 42%), var(--background); }
.public-brand { width: min(520px, 100%); margin: 0 auto 24px; display: flex; align-items: center; gap: 14px; }
.public-brand img { border-radius: 16px; }
.public-brand strong, .public-brand span { display: block; }
.public-brand strong { font-size: 20px; }
.public-brand span { color: var(--muted); font-size: 14px; margin-top: 2px; }
.public-content { display: grid; place-items: start center; }
.auth-card { width: min(520px, 100%); }
.auth-card h1 { font-size: clamp(32px, 8vw, 46px); margin-bottom: 8px; }
.install-hint { margin-top: 22px; padding: 16px; border-radius: 14px; background: var(--surface-alt); display: grid; gap: 4px; }
.install-hint span { color: var(--muted); font-size: 14px; line-height: 1.45; }

.app-shell { min-height: 100vh; min-height: 100dvh; }
.drawer { position: fixed; z-index: 80; inset: 0 auto 0 0; width: 292px; padding: max(26px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom)); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto; }
.drawer-profile { display: flex; align-items: center; gap: 13px; padding: 10px 8px 20px; }
.avatar, .topbar-avatar, .profile-avatar { display: grid; place-items: center; border-radius: 50%; background: var(--brand-soft); color: var(--brand-strong); font-weight: 800; flex: 0 0 auto; }
.avatar { width: 52px; height: 52px; font-size: 17px; }
.drawer-profile-text { min-width: 0; }
.drawer-profile-text strong, .drawer-profile-text span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-profile-text span { margin-top: 3px; color: var(--muted); font-size: 13px; }
.drawer-nav { display: flex; flex-direction: column; gap: 5px; }
.nav-group-title { margin: 20px 12px 6px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .13em; }
.nav-item { min-height: 50px; display: flex; align-items: center; padding: 0 14px; border-radius: 14px; color: var(--text); text-decoration: none; font-weight: 650; }
.nav-item:hover { background: var(--surface-alt); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-strong); }
.drawer-footer { margin-top: auto; padding-top: 22px; display: grid; gap: 9px; }
.drawer-footer small { color: var(--muted); line-height: 1.4; }
.drawer-overlay { display: none; }
.app-main { min-height: 100vh; margin-left: 292px; }
.topbar { height: var(--topbar); position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 14px; padding: 0 max(22px, env(safe-area-inset-right)) 0 max(22px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--surface) 92%, transparent); border-bottom: 1px solid var(--border); backdrop-filter: blur(18px); }
.menu-button { display: none; width: 44px; height: 44px; border: 0; border-radius: 13px; background: var(--surface-alt); color: var(--text); font-size: 22px; }
.topbar-brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 800; }
.topbar-brand img { border-radius: 10px; }
.topbar-avatar { margin-left: auto; width: 42px; height: 42px; text-decoration: none; border: 1px solid var(--border); }
.page-content { width: min(1180px, 100%); margin: 0 auto; padding: 30px 30px max(64px, env(safe-area-inset-bottom)); }
.offline-only { display: none; position: sticky; top: var(--topbar); z-index: 45; padding: 10px 24px; background: var(--warning-soft); color: var(--text); border-bottom: 1px solid var(--border); font-size: 14px; font-weight: 650; }
html.offline .offline-only { display: block; }

.page-section { display: grid; gap: 20px; }
.narrow-page { max-width: 780px; margin: 0 auto; }
.page-header { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 2px; }
.page-header h1, .card h1, .card h2, .card h3 { margin-top: 0; }
.page-header h1 { margin: 2px 0 5px; font-size: clamp(30px, 5vw, 42px); letter-spacing: -.025em; }
.page-header p, .section-heading p, .card p { color: var(--muted); line-height: 1.5; }
.page-header p { margin: 0; }
.eyebrow { color: var(--brand); font-size: 12px; font-weight: 850; letter-spacing: .14em; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.section-heading h2 { margin: 0 0 4px; }
.section-heading p { margin: 0; }

.card { padding: 19px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 1px 0 rgba(0,0,0,.01); }
.card h2 { font-size: 20px; }
.card h3 { margin-bottom: 6px; }
.card-list, .notification-list, .plan-days, .workflow-section { display: grid; gap: 13px; }
.empty-card { text-align: center; padding: 42px 20px; }
.empty-card h2 { margin-bottom: 6px; }
.empty-card p { margin: 0 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1 1 auto; }

.button { min-height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px; border: 1px solid transparent; border-radius: 14px; text-decoration: none; font-weight: 750; transition: transform .12s ease, background .12s ease; }
.button:active:not(:disabled) { transform: translateY(1px); }
.button.primary { background: var(--brand); color: white; }
.button.subtle { background: var(--brand-soft); color: var(--brand-strong); }
.button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.button.danger { background: var(--danger); color: white; }
.button.full { width: 100%; }
.icon-button { width: 46px; height: 46px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); font-size: 28px; line-height: 1; }
.text-link { color: var(--brand); font-weight: 750; text-decoration: none; }
.text-link:hover { text-decoration: underline; }
.card-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 14px; }
.month-controls { display: flex; gap: 8px; align-items: center; }

.form-stack { display: grid; gap: 16px; }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: 7px; }
.field label { font-size: 14px; font-weight: 750; }
.field small { color: var(--muted); }
input:not([type="checkbox"]):not([type="color"]), select, textarea { width: 100%; min-height: 48px; padding: 11px 13px; border: 1px solid var(--border); border-radius: 13px; background: var(--brand-soft); color: var(--text); outline: none; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.validation-message { color: var(--danger); font-size: 13px; font-weight: 650; }
.color-field { display: grid; grid-template-columns: 52px 1fr; gap: 8px; }
.color-field input[type="color"] { width: 52px; height: 48px; padding: 3px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.inline-form-card { display: flex; align-items: end; gap: 12px; }
.compact-field { min-width: 180px; }

.status { padding: 13px 15px; border-radius: 13px; border: 1px solid var(--border); font-size: 14px; line-height: 1.45; }
.status.error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.status.success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 42%, var(--border)); }
.status.info { background: var(--surface-alt); }
.badge { display: inline-flex; align-items: center; min-height: 26px; padding: 2px 9px; border-radius: 999px; background: var(--surface-alt); color: var(--muted); font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge.brand { background: var(--brand-soft); color: var(--brand-strong); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.muted-badge, .muted-badge { background: var(--surface-alt); color: var(--muted); }

.loading-state { min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.plan-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.plan-summary div { display: grid; gap: 3px; }
.plan-summary span { color: var(--muted); font-size: 13px; }
.day-card { padding: 16px; }
.day-heading { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 13px; }
.day-heading strong, .day-heading span { display: block; }
.day-heading strong { text-transform: capitalize; }
.day-heading div > span { color: var(--muted); font-size: 13px; margin-top: 2px; }
.slot-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.slot { min-height: 116px; padding: 14px; border-radius: 15px; background: var(--surface-alt); display: grid; align-content: start; gap: 8px; border: 1px solid transparent; }
.slot.mine { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 34%, transparent); }
.slot.free { border-style: dashed; border-color: var(--border); }
.slot-topline { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.duty-kind { color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.slot small { color: var(--muted); }

.settings-card { display: grid; gap: 4px; }
.switch-row { min-height: 66px; display: flex; justify-content: space-between; align-items: center; gap: 16px; border-top: 1px solid var(--border); padding: 12px 2px; }
.switch-row span strong, .switch-row span small { display: block; }
.switch-row span small { color: var(--muted); margin-top: 3px; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--brand); }
.notification-card.unread { border-left: 4px solid var(--brand); }
.notification-meta, .workflow-card-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 10px; }
.notification-meta time, .workflow-card-head time { color: var(--muted); font-size: 12px; }
.notification-card h2 { margin-bottom: 7px; }
.notification-card p { margin-top: 0; }

.horse-row, .user-row { display: flex; align-items: center; gap: 14px; }
.horse-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-strong); font-size: 24px; }
.user-row h3, .user-row p { margin: 0; }
.user-row p { color: var(--muted); }
.user-row small { color: var(--muted); display: block; margin-top: 4px; }
.profile-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 14px; }
.profile-card { display: flex; align-items: center; gap: 16px; }
.profile-avatar { width: 66px; height: 66px; font-size: 21px; }
.small-avatar { width: 48px; height: 48px; font-size: 15px; }
.profile-card h2, .profile-card p { margin: 0; }
.profile-card p { margin: 4px 0 8px; }
.metric-card { display: grid; align-content: center; gap: 5px; }
.metric-card span, .metric-card small { color: var(--muted); }
.metric-card strong { font-size: 22px; }
.security-card { border-style: dashed; }

.workflow-create-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.workflow-create-grid .card { display: grid; align-content: start; gap: 13px; }
.workflow-create-grid h2, .workflow-create-grid p { margin: 0; }
.workflow-card h3 { margin-bottom: 7px; }
.workflow-card p { margin: 5px 0; }
.quote { padding: 12px 14px; background: var(--surface-alt); border-left: 3px solid var(--brand); border-radius: 0 10px 10px 0; }

@media (max-width: 960px) {
    .drawer { transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow); }
    .drawer.open { transform: translateX(0); }
    .drawer-overlay { display: block; position: fixed; z-index: 70; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(0,0,0,.34); }
    .app-main { margin-left: 0; }
    .menu-button { display: grid; place-items: center; }
    .page-content { padding: 24px 18px max(52px, env(safe-area-inset-bottom)); }
    .profile-grid { grid-template-columns: 1fr 1fr; }
    .profile-card { grid-column: 1 / -1; }
    .form-grid.three { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
    :root { --topbar: 64px; --radius: 16px; }
    .topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
    .topbar-brand span { display: none; }
    .page-content { padding: 20px 14px max(48px, env(safe-area-inset-bottom)); }
    .page-header { align-items: stretch; flex-direction: column; }
    .page-header .button { align-self: flex-start; }
    .month-controls { width: 100%; }
    .month-controls .button { flex: 1; }
    .card { padding: 16px; }
    .slot-grid, .workflow-create-grid, .form-grid.two, .plan-summary, .profile-grid { grid-template-columns: 1fr; }
    .profile-card { grid-column: auto; }
    .inline-form-card, .horse-row, .user-row { align-items: stretch; flex-direction: column; }
    .horse-icon, .small-avatar { align-self: flex-start; }
    .notification-meta, .workflow-card-head { align-items: flex-start; flex-direction: column; }
    .card-actions .button { flex: 1 1 140px; }
    .drawer { width: min(88vw, 320px); }
}
