.panel { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.panel-wide { min-width: 0; }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.panel-header h2 { margin: 3px 0 0; font-size: 17px; letter-spacing: -0.015em; }
.panel-header p:not(.eyebrow) { margin: 6px 0 0; color: var(--text-muted); font-size: 11px; }

.button { min-height: 39px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 14px; border: 1px solid transparent; border-radius: 8px; font-weight: 600; font-size: 12px; text-decoration: none; cursor: pointer; transition: background 0.15s, border-color 0.15s, color 0.15s; }
.button svg { width: 17px; height: 17px; }
.button-primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.button-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.button-secondary { color: var(--text); background: var(--surface); border-color: var(--border-strong); }
.button-secondary:hover { background: var(--surface-muted); }
.button-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.button-block { width: 100%; }
.button:disabled { opacity: 0.55; cursor: not-allowed; }
.icon-button { width: 36px; height: 36px; display: inline-grid; place-items: center; flex: 0 0 auto; color: var(--text-soft); background: transparent; border: 1px solid transparent; border-radius: 8px; text-decoration: none; cursor: pointer; }
.icon-button:hover { color: var(--text); background: var(--surface-strong); border-color: var(--border); }
.icon-button.danger { color: var(--danger); }
.icon-button svg { width: 18px; height: 18px; }
.text-link { color: var(--primary); font-weight: 600; font-size: 11px; text-decoration: none; }
.text-link:hover { text-decoration: underline; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 22px; }
.form-stack { display: grid; gap: 15px; }
.form-panel > .form-stack, .crud-form > .form-stack { padding: 20px 22px 24px; }
.form-grid label, .form-stack label { min-width: 0; display: grid; gap: 6px; color: var(--text-soft); font-size: 11px; font-weight: 500; }
.form-grid label > span, .form-stack label > span { color: var(--text-soft); }
.field-span-2 { grid-column: span 2; }
input, select, textarea { width: 100%; min-height: 40px; padding: 9px 11px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; outline: none; transition: border-color 0.15s, box-shadow 0.15s; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type='checkbox'], input[type='radio'] { width: auto; min-height: auto; box-shadow: none; }
input[readonly] { color: var(--text-soft); background: var(--surface-muted); }
label small, .form-stack small { color: var(--text-muted); font-size: 11px; font-weight: 400; }
label em { color: var(--danger); font-size: 11px; font-style: normal; }
.form-actions { display: flex; justify-content: flex-end; padding-top: 4px; }
.form-status { min-height: 20px; margin: 8px 0 0; color: var(--text-muted); font-size: 12px; text-align: center; }
.form-status.error { color: var(--danger); }
.form-status.success { color: var(--success); }
fieldset { margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 8px; color: var(--text-soft); font-size: 11px; font-weight: 500; }

.filter-bar { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.filter-bar select { width: auto; min-width: 150px; }
.search-field { min-width: 220px; flex: 1; position: relative; }
.search-field svg { position: absolute; z-index: 1; top: 10px; left: 11px; width: 18px; height: 18px; color: var(--text-muted); }
.search-field input { padding-left: 37px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 14px; color: var(--text-muted); background: var(--surface-muted); border-bottom: 1px solid var(--border); font-size: 11px; font-weight: 600; text-align: left; text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap; }
td { padding: 13px 14px; border-bottom: 1px solid var(--border); color: var(--text-soft); font-size: 11px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-muted); }
td strong, td small { display: block; }
td strong { color: var(--text); font-size: 11px; }
td small { margin-top: 2px; color: var(--text-muted); font-size: 11px; }
.align-right { text-align: right; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 2px; }
.row-actions form { margin: 0; }

.status-badge { display: inline-flex; align-items: center; min-height: 23px; padding: 3px 8px; color: var(--text-soft); background: var(--surface-strong); border: 1px solid var(--border); border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.status-badge.draft, .status-badge.not-started, .status-badge.neutral { color: var(--text-soft); background: var(--surface-muted); }
.status-badge.sent, .status-badge.in-progress, .status-badge.assigned, .status-badge.issued { color: var(--info); background: var(--info-soft); border-color: var(--info-border); }
.status-badge.accepted, .status-badge.completed, .status-badge.paid, .status-badge.available { color: var(--success); background: var(--success-soft); border-color: var(--success-border); }
.status-badge.rejected, .status-badge.expired, .status-badge.cancelled, .status-badge.damaged, .status-badge.retired { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-border); }
.status-badge.blocked, .status-badge.waiting, .status-badge.maintenance { color: var(--warning); background: var(--warning-soft); border-color: var(--warning-border); }
.status-dot { width: 8px; height: 8px; display: inline-block; border-radius: 50%; background: var(--success); }
.muted-dot { background: var(--text-muted); }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric-card { min-width: 0; display: flex; align-items: flex-start; gap: 13px; padding: 17px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.metric-icon { width: 36px; height: 36px; display: grid; place-items: center; flex: 0 0 auto; color: var(--primary); background: var(--primary-soft); border-radius: 9px; }
.metric-icon svg { width: 18px; height: 18px; }
.metric-card small, .metric-card strong, .metric-card p { display: block; margin: 0; }
.metric-card small { color: var(--text-muted); font-size: 11px; }
.metric-card strong { margin-top: 5px; font-size: 18px; line-height: 1.2; letter-spacing: -0.025em; overflow-wrap: anywhere; }
.metric-card p { margin-top: 4px; color: var(--text-muted); font-size: 11px; }

.empty-state { padding: 44px 20px; text-align: center; color: var(--text-muted); }
.empty-state h3 { margin: 0 0 6px; color: var(--text); font-size: 15px; }
.empty-state p { margin: 0; font-size: 12px; }
.empty-state.compact { padding: 24px 12px; }
.grid-empty { grid-column: 1 / -1; }

.progress-track { height: 5px; overflow: hidden; background: var(--surface-strong); border-radius: 999px; }
.progress-track span { display: block; height: 100%; background: var(--primary); border-radius: inherit; }
.priority-dot { width: 7px; height: 7px; display: inline-block; flex: 0 0 auto; border-radius: 50%; background: #9ca3af; }
.priority-dot.p2 { background: #457cba; }
.priority-dot.p3 { background: #d17800; }
.priority-dot.p4 { background: #c43227; }

.segmented-control { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--border-strong); border-radius: 9px; overflow: hidden; }
.segmented-control label { display: block; }
.segmented-control input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-control span { min-height: 38px; display: grid; place-items: center; padding: 8px; color: var(--text-soft); background: var(--surface); border-right: 1px solid var(--border); font-size: 12px; cursor: pointer; }
.segmented-control label:last-child span { border-right: 0; }
.segmented-control input:checked + span { color: var(--primary); background: var(--primary-soft); font-weight: 600; }

.agent-panel { position: fixed; z-index: 90; top: 0; right: 0; bottom: 0; width: var(--agent-width); display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--border); transform: translateX(100%); transition: transform 0.2s ease; }
body.agent-open .agent-panel { transform: translateX(0); }
.agent-header { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.agent-header h2 { margin: 2px 0 0; font-size: 16px; }
.agent-header-actions { display: flex; gap: 3px; }
.agent-scope { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 8px; padding: 10px 16px; background: var(--surface-muted); border-bottom: 1px solid var(--border); font-size: 12px; }
.agent-scope small { grid-column: 2; color: var(--text-muted); font-size: 11px; }

.agent-scope small { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.agent-scope-policy { flex: 0 0 auto; color: var(--success); font-weight: 700; letter-spacing: .03em; text-transform: uppercase; }
.agent-quick-prompts { display: flex; gap: 7px; padding: 10px 16px; overflow-x: auto; border-bottom: 1px solid var(--border); background: var(--surface); scrollbar-width: thin; }
.agent-quick-prompt { min-height: 30px; flex: 0 0 auto; max-width: 220px; padding: 6px 10px; color: var(--text-soft); background: var(--surface-muted); border: 1px solid var(--border); border-radius: 999px; font: inherit; font-size: 11px; font-weight: 650; cursor: pointer; white-space: nowrap; transition: border-color .16s ease, color .16s ease, background .16s ease; }
.agent-quick-prompt:hover, .agent-quick-prompt:focus-visible { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); outline: none; }

.agent-messages { flex: 1; overflow-y: auto; padding: 16px; }
.agent-welcome { max-width: 290px; margin: 60px auto; text-align: center; }
.agent-orb { width: 48px; height: 48px; display: grid; place-items: center; margin: 0 auto 14px; color: var(--primary); background: var(--primary-soft); border: 1px solid var(--info-border); border-radius: 50%; }
.agent-welcome h3 { margin: 0 0 8px; font-size: 15px; }
.agent-welcome p { margin: 0; color: var(--text-muted); font-size: 12px; }
.agent-message { max-width: 92%; margin-bottom: 14px; }
.agent-message.user { margin-left: auto; }
.agent-bubble { padding: 10px 12px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-muted); font-size: 11px; white-space: pre-wrap; overflow-wrap: anywhere; }
.agent-message.user .agent-bubble { color: #fff; background: var(--primary); border-color: var(--primary); border-bottom-right-radius: 4px; }
.agent-message.assistant .agent-bubble { border-bottom-left-radius: 4px; }
.agent-message-meta { margin-top: 4px; color: var(--text-muted); font-size: 11px; }
.agent-block { margin-top: 8px; padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; }
.agent-block h4 { margin: 0 0 8px; font-size: 11px; }
.agent-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.agent-metric { padding: 8px; background: var(--surface-muted); border-radius: 7px; }
.agent-metric small, .agent-metric strong { display: block; }
.agent-metric small { color: var(--text-muted); font-size: 11px; }
.agent-metric strong { margin-top: 3px; font-size: 11px; overflow-wrap: anywhere; }
.agent-table { overflow-x: auto; }
.agent-table table { min-width: 320px; }
.agent-table th, .agent-table td { padding: 7px; font-size: 11px; }
.agent-chart { min-height: 160px; }
.agent-chart svg { width: 100%; height: 150px; overflow: visible; }
.agent-diagram { display: grid; gap: 7px; }
.agent-diagram-node { padding: 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-muted); font-size: 11px; }
.agent-notice { color: var(--info); background: var(--info-soft); border-color: var(--info-border); }
.agent-notice.warning { color: var(--warning); background: var(--warning-soft); border-color: var(--warning-border); }
.agent-notice.danger { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-border); }
.agent-notice.success { color: var(--success); background: var(--success-soft); border-color: var(--success-border); }
.agent-record { display: grid; gap: 10px; }
.agent-record-head { display: flex; align-items: center; gap: 9px; }
.agent-record-mark { width: 32px; height: 32px; flex: 0 0 auto; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); border: 1px solid var(--info-border); border-radius: 9px; font-size: 13px; font-weight: 700; text-transform: uppercase; }
.agent-record-headtext { min-width: 0; flex: 1 1 auto; }
.agent-record-headtext small, .agent-record-headtext strong { display: block; }
.agent-record-headtext small { color: var(--text-muted); font-size: 11px; text-transform: capitalize; }
.agent-record-headtext strong { font-size: 12px; overflow-wrap: anywhere; }
.agent-record-badge { flex: 0 0 auto; padding: 3px 8px; color: var(--info); background: var(--info-soft); border-radius: 999px; font-size: 11px; font-weight: 600; }
.agent-record-badge.success { color: var(--success); background: var(--success-soft); }
.agent-record-badge.warning { color: var(--warning); background: var(--warning-soft); }
.agent-record-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.agent-record-field { min-width: 0; padding: 7px 8px; background: var(--surface-muted); border-radius: 7px; }
.agent-record-field small, .agent-record-field span { display: block; }
.agent-record-field small { color: var(--text-muted); font-size: 11px; }
.agent-record-field span { margin-top: 2px; font-size: 11px; overflow-wrap: anywhere; }
.agent-record-link { color: var(--primary); font-size: 11px; font-weight: 600; text-decoration: none; }
.agent-record-link:hover { text-decoration: underline; }
.agent-approval { border-color: #e6bd72; background: #fffaf0; }
.agent-approval pre { max-height: 140px; overflow: auto; margin: 8px 0; padding: 8px; background: #fff; border: 1px solid #ead9b8; border-radius: 6px; font-size: 11px; white-space: pre-wrap; }
[data-theme="dark"] .agent-approval { border-color: #8a6a2f; background: #211a0e; }
[data-theme="dark"] .agent-approval pre { background: #0f141a; border-color: #3a2f18; }
.agent-approval-actions { display: flex; gap: 7px; }
.agent-composer { padding: 12px; border-top: 1px solid var(--border); background: var(--surface); }
.agent-composer textarea { min-height: 66px; max-height: 160px; }
.agent-composer > div { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.agent-hint { color: var(--text-muted); font-size: 11px; }
.agent-loading { display: inline-flex; gap: 4px; padding: 10px 12px; }
.agent-loading i { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); animation: agentPulse 1s infinite alternate; }
.agent-loading i:nth-child(2) { animation-delay: 0.2s; }
.agent-loading i:nth-child(3) { animation-delay: 0.4s; }
@keyframes agentPulse { to { opacity: 0.25; transform: translateY(-2px); } }

@media (max-width: 1180px) {
    .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
    .agent-panel { top: auto; width: 100%; height: min(88vh, 760px); border: 1px solid var(--border); border-radius: 18px 18px 0 0; transform: translateY(105%); }
    body.agent-open .agent-panel { transform: translateY(0); }
    body.agent-open .modal-overlay { display: block; }
    .agent-header { min-height: 64px; }
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid { grid-template-columns: 1fr; }
    .field-span-2 { grid-column: auto; }
    .filter-bar { align-items: stretch; flex-wrap: wrap; }
    .filter-bar select, .filter-bar .button { flex: 1 1 140px; }
    .search-field { flex: 1 1 100%; }
}
@media (max-width: 520px) {
    .metric-grid { grid-template-columns: 1fr; }
    .segmented-control { grid-template-columns: repeat(2, 1fr); }
    .segmented-control label:nth-child(2) span { border-right: 0; }
    .segmented-control label:nth-child(-n+2) span { border-bottom: 1px solid var(--border); }
    .agent-hint { display: none; }
}

/* Custom application controls */
select.select-native { position: absolute !important; width: 1px !important; height: 1px !important; min-height: 1px !important; padding: 0 !important; margin: 0 !important; opacity: 0; pointer-events: none; }
.custom-select { position: relative; width: 100%; min-width: 0; }
.filter-bar .custom-select { width: auto; min-width: 170px; }
.custom-select-trigger { width: 100%; min-height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 11px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; text-align: left; cursor: pointer; outline: none; transition: border-color .15s, box-shadow .15s, background .15s; }
.custom-select-trigger:hover { background: var(--surface-muted); }
.custom-select-trigger:focus, .custom-select.open .custom-select-trigger { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.custom-select-trigger > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-select-trigger svg { width: 16px; height: 16px; flex: 0 0 auto; color: var(--text-muted); transition: transform .15s; }
.custom-select.open .custom-select-trigger svg { transform: rotate(180deg); }
.custom-select.disabled { opacity: .6; pointer-events: none; }
.custom-select-menu { position: fixed; z-index: 130; top: calc(100% + 6px); left: 0; right: 0; display: none; min-width: 220px; max-height: 300px; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 16px 40px rgba(15, 23, 42, .14); }
.custom-select.open .custom-select-menu { display: block; animation: selectIn .12s ease-out; }
.custom-select-search { position: relative; display: block; padding: 9px; border-bottom: 1px solid var(--border); }
.custom-select-search svg { position: absolute; top: 19px; left: 20px; width: 15px; height: 15px; color: var(--text-muted); }
.custom-select-search input { min-height: 36px; padding-left: 34px; background: var(--surface-muted); }
.custom-select-options { max-height: 244px; overflow-y: auto; padding: 5px; scrollbar-width: thin; }
.custom-select-option { width: 100%; min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 9px; color: var(--text-soft); background: transparent; border: 0; border-radius: 7px; text-align: left; cursor: pointer; }
.custom-select-option:hover, .custom-select-option:focus { color: var(--text); background: var(--surface-muted); outline: none; }
.custom-select-option.selected { color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.custom-select-option svg { width: 15px; height: 15px; opacity: 0; }
.custom-select-option.selected svg { opacity: 1; }
.custom-select-option[hidden] { display: none; }
@keyframes selectIn { from { opacity: 0; transform: translateY(-4px); } }

input[type='checkbox'], input[type='radio'] { appearance: none; width: 18px; height: 18px; min-height: 18px; padding: 0; display: inline-grid; place-content: center; flex: 0 0 auto; background: var(--surface); border: 1px solid var(--border-strong); cursor: pointer; }
input[type='checkbox'] { border-radius: 5px; }
input[type='radio'] { border-radius: 50%; }
input[type='checkbox']::before { content: ''; width: 9px; height: 5px; border: solid #fff; border-width: 0 0 2px 2px; transform: rotate(-45deg) scale(0); transition: transform .12s; }
input[type='radio']::before { content: ''; width: 8px; height: 8px; background: #fff; border-radius: 50%; transform: scale(0); transition: transform .12s; }
input[type='checkbox']:checked, input[type='radio']:checked { background: var(--primary); border-color: var(--primary); }
input[type='checkbox']:checked::before, input[type='radio']:checked::before { transform: rotate(-45deg) scale(1); }
input[type='radio']:checked::before { transform: scale(1); }
input[type='checkbox']:focus-visible, input[type='radio']:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
input[type='range'] { appearance: none; height: 4px; padding: 0; background: var(--surface-strong); border: 0; border-radius: 999px; }
input[type='range']::-webkit-slider-thumb { appearance: none; width: 16px; height: 16px; background: var(--primary); border: 3px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px var(--primary); cursor: pointer; }
input[type='range']::-moz-range-thumb { width: 12px; height: 12px; background: var(--primary); border: 3px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px var(--primary); cursor: pointer; }

.file-input-native { position: absolute !important; width: 1px !important; height: 1px !important; opacity: 0; pointer-events: none; }
.file-picker { min-height: 74px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 12px; background: var(--surface-muted); border: 1px dashed var(--border-strong); border-radius: 10px; cursor: pointer; outline: none; transition: border-color .15s, background .15s, box-shadow .15s; }
.file-picker:hover, .file-picker:focus, .file-picker.dragging { background: var(--primary-soft); border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.file-picker.has-file { background: var(--success-soft); border-style: solid; border-color: var(--success-border); }
.file-picker-icon { width: 38px; height: 38px; display: grid; place-items: center; color: var(--primary); background: var(--surface); border: 1px solid var(--border); border-radius: 9px; }
.file-picker-icon svg { width: 18px; height: 18px; }
.file-picker-copy strong, .file-picker-copy small { display: block; overflow-wrap: anywhere; }
.file-picker-copy strong { color: var(--text); font-size: 12px; }
.file-picker-copy small { margin-top: 3px; color: var(--text-muted); font-size: 11px; }

/* Custom application dialogs */
.ui-dialog { position: fixed; inset: 0; z-index: 120; display: none; align-items: center; justify-content: center; padding: 22px; }
.ui-dialog.open { display: flex; }
.ui-dialog-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .48); backdrop-filter: blur(2px); animation: dialogFade .16s ease-out; }
.ui-dialog-shell { position: relative; width: min(560px, 100%); max-height: min(88vh, 820px); display: flex; flex-direction: column; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: 15px; box-shadow: 0 24px 70px rgba(15, 23, 42, .22); animation: dialogIn .18s ease-out; outline: none; }
.ui-dialog-wide { width: min(820px, 100%); }
.ui-dialog-header { min-height: 74px; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.ui-dialog-header h2 { margin: 3px 0 0; font-size: 18px; letter-spacing: -.02em; }
.ui-dialog-header p:not(.eyebrow) { margin: 5px 0 0; color: var(--text-muted); font-size: 12px; }
.ui-dialog-body { overflow-y: auto; padding: 20px; }
.ui-dialog-body.form-grid { padding: 20px; }
.ui-dialog-footer { display: flex; align-items: center; justify-content: flex-end; gap: 9px; padding: 14px 20px; background: var(--surface-muted); border-top: 1px solid var(--border); }
.dialog-form { margin: 0; }
.dialog-form .ui-dialog-body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.dialog-form .ui-dialog-body > label { min-width: 0; display: grid; align-content: start; gap: 6px; color: var(--text-soft); font-size: 11px; font-weight: 500; }
.dialog-form .ui-dialog-body > label > span { color: var(--text-soft); }
.dialog-form .ui-dialog-body > label small { color: var(--text-muted); font-size: 11px; font-weight: 400; }
.dialog-form .ui-dialog-body > label em { color: var(--danger); font-size: 11px; font-style: normal; }
.dialog-form .field-span-2 { grid-column: span 2; }
.dialog-form ul, .dialog-form [id^='id_courses'] { margin: 0; padding: 10px; display: grid; gap: 8px; list-style: none; background: var(--surface-muted); border: 1px solid var(--border); border-radius: 8px; }
.dialog-form ul label, .dialog-form [id^='id_courses'] label { display: flex; align-items: center; gap: 8px; }
.ui-dialog-confirm { width: min(430px, 100%); display: grid; grid-template-columns: auto 1fr; padding: 22px 22px 0; }
.confirm-icon { width: 42px; height: 42px; display: grid; place-items: center; color: var(--danger); background: var(--danger-soft); border-radius: 10px; }
.confirm-icon svg { width: 20px; height: 20px; }
.confirm-copy { padding: 1px 0 22px 14px; }
.confirm-copy h2 { margin: 0; font-size: 16px; }
.confirm-copy p { margin: 7px 0 0; color: var(--text-muted); font-size: 12px; line-height: 1.65; }
.ui-dialog-confirm .ui-dialog-footer { grid-column: 1 / -1; margin: 0 -22px; }
@keyframes dialogFade { from { opacity: 0; } }
@keyframes dialogIn { from { opacity: 0; transform: translateY(10px) scale(.985); } }

.toast-region { position: fixed; z-index: 150; top: 18px; right: 18px; width: min(380px, calc(100% - 28px)); display: grid; gap: 8px; pointer-events: none; }
.app-toast { min-height: 48px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 10px 11px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 16px 36px rgba(15, 23, 42, .14); opacity: 0; transform: translateY(-7px); transition: opacity .18s, transform .18s; pointer-events: auto; font-size: 12px; }
.app-toast.visible { opacity: 1; transform: translateY(0); }
.app-toast-icon { width: 8px; height: 8px; background: var(--info); border-radius: 50%; }
.app-toast.success .app-toast-icon { background: var(--success); }
.app-toast.error .app-toast-icon { background: var(--danger); }
.app-toast.warning .app-toast-icon { background: var(--warning); }
.app-toast button { width: 28px; height: 28px; padding: 0; color: var(--text-muted); background: transparent; border: 0; border-radius: 6px; cursor: pointer; }
.app-toast button:hover { background: var(--surface-strong); }

@media (max-width: 820px) {
    .filter-bar .custom-select { flex: 1 1 160px; min-width: 0; }
    .ui-dialog { align-items: flex-end; padding: 0; }
    .ui-dialog-shell { width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; animation-name: dialogSheetIn; }
    .ui-dialog-wide { width: 100%; }
    .ui-dialog-header { padding: 16px; }
    .ui-dialog-body, .ui-dialog-body.form-grid { padding: 16px; }
    .ui-dialog-footer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
    .ui-dialog-confirm { width: calc(100% - 24px); margin: auto 12px; border-radius: 14px; animation-name: dialogIn; }
    .dialog-form .ui-dialog-body { grid-template-columns: 1fr; }
    .dialog-form .field-span-2 { grid-column: auto; }
    .toast-region { top: 68px; right: 14px; }
    @keyframes dialogSheetIn { from { opacity: 0; transform: translateY(32px); } }
}
@media (max-width: 520px) {
    .file-picker { grid-template-columns: auto 1fr; }
    .file-picker .button { grid-column: 1 / -1; width: 100%; }
    .ui-dialog-footer .button { flex: 1; }
}

.empty-state .button { margin-top: 16px; }

.field-invalid input, .field-invalid textarea, .field-invalid .custom-select-trigger, .field-invalid .file-picker { border-color: var(--danger); }
.field-invalid input:focus, .field-invalid textarea:focus, .field-invalid .custom-select-trigger:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.form-error-summary { padding: 10px 12px; color: var(--danger); background: var(--danger-soft); border: 1px solid var(--danger-border); border-radius: 8px; font-size: 12px; }

.form-grid label.field-checkbox, .dialog-form .ui-dialog-body > label.field-checkbox { grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px 12px; padding: 11px 12px; background: var(--surface-muted); border: 1px solid var(--border); border-radius: 9px; }
.field-checkbox > span { grid-column: 1; grid-row: 1; color: var(--text) !important; }
.field-checkbox > input[type='checkbox'] { grid-column: 2; grid-row: 1; }
.field-checkbox > small, .field-checkbox > em { grid-column: 1 / -1; }
