:root {
    --page: #f5f6f7;
    --surface: #ffffff;
    --surface-muted: #f9fafb;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --text: #20242b;
    --muted: #69717d;
    --primary: #176c4c;
    --primary-hover: #125b40;
    --primary-soft: #e8f4ee;
    --blue: #2f66b1;
    --blue-soft: #edf3fb;
    --amber: #8b5b11;
    --amber-soft: #fff6df;
    --danger: #b23a3a;
    --danger-soft: #fff0f0;
    --shadow: 0 8px 24px rgba(24, 33, 45, 0.08);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    margin: 0;
    min-width: 320px;
    min-height: 100%;
}

body {
    min-height: 100vh;
    background: var(--page);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    font-size: 12px;
    line-height: 1.5;
}

button,
input,
select,
textarea {
    font: inherit;
    letter-spacing: 0;
}

button,
select,
input[type="checkbox"] {
    cursor: pointer;
}

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

select:disabled,
input:disabled {
    background: var(--surface-muted);
    border-color: var(--border);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
    outline: 2px solid #85bda1;
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.topbar {
    min-height: 58px;
    padding: 9px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand-block,
.topbar-actions,
.title-with-status,
.form-actions,
.section-heading-row,
.model-toolbar,
.row-actions {
    display: flex;
    align-items: center;
}

.brand-block {
    min-width: 0;
    gap: 10px;
}

.brand-mark {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: var(--primary);
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
}

.brand-block h1,
.brand-block p,
.page-heading h2,
.page-heading p,
.editor-heading h3,
.editor-heading p,
.section-heading-row h3,
.section-heading-row p,
.settings-row h3,
.settings-row p,
.dialog-heading h2,
.dialog-heading p {
    margin: 0;
}

.brand-block h1 {
    font-size: 14px;
    font-weight: 650;
}

.brand-block p {
    color: var(--muted);
}

.topbar-actions {
    flex: 0 0 auto;
    gap: 8px;
}

.runtime-badge,
.state-badge,
.capability-badge,
.model-status,
.app-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    white-space: nowrap;
}

.runtime-badge {
    min-height: 28px;
    padding: 5px 9px;
    color: var(--primary);
    background: var(--primary-soft);
}

.button,
.icon-button {
    min-height: 34px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 12px;
}

.button {
    padding: 8px 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: var(--surface-muted);
    color: var(--text);
}

.button:hover:not(:disabled) {
    filter: brightness(0.98);
}

.button-primary {
    background: var(--primary);
    color: #ffffff;
}

.button-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.button-secondary {
    border-color: var(--border-strong);
    background: var(--surface);
}

.button-danger {
    border-color: #efcaca;
    background: var(--surface);
    color: var(--danger);
}

.back-icon {
    display: none;
}

.icon-button {
    width: 40px;
    padding: 0 7px;
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--muted);
}

.app-shell {
    min-height: calc(100vh - 58px);
    display: grid;
    grid-template-columns: 194px minmax(0, 1fr);
}

.side-navigation {
    min-width: 0;
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.side-navigation nav {
    display: grid;
    gap: 3px;
}

.nav-item {
    width: 100%;
    min-height: 50px;
    padding: 8px;
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr);
    align-items: center;
    gap: 7px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    text-align: left;
}

.nav-item:hover {
    background: var(--surface-muted);
}

.nav-item.active {
    border-color: #bcdccc;
    background: var(--primary-soft);
    color: var(--primary);
}

.nav-symbol {
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border-radius: 5px;
    background: var(--surface-muted);
    color: var(--muted);
    font-size: 15px;
}

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

.nav-item strong,
.nav-item small {
    display: block;
}

.nav-item strong {
    font-weight: 650;
}

.nav-item small {
    margin-top: 1px;
    color: var(--muted);
    font-size: 11px;
}

.side-status {
    padding: 10px 8px;
    display: grid;
    grid-template-columns: 8px minmax(0, 1fr);
    gap: 7px;
    border-top: 1px solid var(--border);
    color: var(--muted);
}

.side-status strong,
.side-status small {
    display: block;
}

.side-status strong {
    color: var(--text);
    font-weight: 600;
}

.side-status small {
    margin-top: 2px;
    font-size: 11px;
}

.status-dot {
    width: 7px;
    height: 7px;
    margin-top: 5px;
    border-radius: 50%;
    background: var(--primary);
}

.content-area {
    min-width: 0;
    padding: 22px;
}

.view {
    width: min(1120px, 100%);
    margin: 0 auto;
}

.page-heading {
    min-height: 58px;
    margin-bottom: 14px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.eyebrow {
    color: var(--primary) !important;
    font-weight: 650;
}

.page-heading h2 {
    margin-top: 1px;
    font-size: 20px;
    font-weight: 650;
}

.page-heading > div > p:last-child {
    margin-top: 3px;
    color: var(--muted);
}

.workspace-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.provider-workspace {
    min-height: 620px;
    display: grid;
    grid-template-columns: 246px minmax(0, 1fr);
    overflow: hidden;
}

.provider-sidebar {
    min-width: 0;
    border-right: 1px solid var(--border);
    background: var(--surface-muted);
}

.search-field {
    display: block;
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

.search-field input,
.field input,
.field select,
.model-toolbar input,
.assignment-selects select {
    width: 100%;
    min-height: 34px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
    background: var(--surface);
    color: var(--text);
}

.search-field input:focus,
.field input:focus,
.field select:focus,
.model-toolbar input:focus,
.assignment-selects select:focus {
    border-color: #85bda1;
    box-shadow: 0 0 0 2px rgba(23, 108, 76, 0.11);
}

.provider-list {
    padding: 5px;
}

.provider-item {
    width: 100%;
    min-height: 56px;
    padding: 8px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    text-align: left;
}

.provider-item:hover {
    background: var(--surface);
}

.provider-item.active {
    border-color: #bcdccc;
    background: var(--surface);
}

.provider-item strong,
.provider-item small {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.provider-item strong {
    font-weight: 650;
}

.provider-item small {
    max-width: 168px;
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
}

.provider-indicator {
    width: 7px;
    height: 7px;
    margin-top: 5px;
    border-radius: 50%;
    background: var(--border-strong);
}

.provider-indicator.enabled {
    background: var(--primary);
}

.provider-editor {
    min-width: 0;
}

.provider-empty-state {
    min-height: 260px;
    padding: 24px;
    display: grid;
    align-content: center;
    justify-items: center;
    text-align: center;
    color: var(--muted);
}

.provider-empty-state strong {
    color: var(--text);
    font-size: 13px;
}

.provider-empty-state p {
    margin: 4px 0 0;
}

#provider-form {
    padding: 16px;
}

.editor-heading {
    margin-bottom: 16px;
    padding-bottom: 13px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--border);
}

.title-with-status {
    gap: 7px;
}

.editor-heading h3,
.section-heading-row h3,
.settings-row h3 {
    font-size: 13px;
    font-weight: 650;
}

.editor-heading p,
.section-heading-row p,
.settings-row p {
    margin-top: 3px;
    color: var(--muted);
}

.state-badge {
    min-height: 21px;
    padding: 2px 7px;
    background: var(--surface-muted);
    color: var(--muted);
    font-size: 11px;
}

.state-badge.enabled {
    background: var(--primary-soft);
    color: var(--primary);
}

.switch-control {
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--text);
    white-space: nowrap;
}

.switch-control input {
    width: 32px;
    height: 18px;
    margin: 0;
    accent-color: var(--primary);
}

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

.field {
    min-width: 0;
    display: grid;
    gap: 5px;
    font-weight: 600;
}

.field-wide {
    grid-column: 1 / -1;
}

.field small {
    color: var(--muted);
    font-size: 11px;
    font-weight: 400;
}

#key-status.error {
    color: var(--danger);
}

.password-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 48px auto auto;
    gap: 6px;
}

.capability-fieldset {
    margin: 13px 0 0;
    padding: 9px 10px 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.capability-fieldset legend {
    padding: 0 4px;
    font-weight: 600;
}

.capability-fieldset label {
    display: flex;
    align-items: center;
    gap: 5px;
}

.capability-fieldset input {
    margin: 0;
    accent-color: var(--primary);
}

.form-actions {
    min-height: 42px;
    margin-top: 12px;
    justify-content: flex-end;
    gap: 7px;
}

.inline-status {
    min-width: 0;
    margin-right: auto;
    color: var(--muted);
}

.inline-status.error {
    color: var(--danger);
}

.models-section {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.section-heading-row {
    justify-content: space-between;
    gap: 14px;
}

.model-toolbar {
    margin: 12px 0 8px;
    justify-content: space-between;
    gap: 10px;
}

.model-toolbar input {
    width: min(260px, 100%);
}

.segmented-control {
    display: inline-flex;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    overflow: hidden;
}

.segmented-control button {
    min-height: 32px;
    padding: 6px 9px;
    border: 0;
    border-right: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--muted);
}

.segmented-control button:last-child {
    border-right: 0;
}

.segmented-control button.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 650;
}

.model-table-wrap,
.plain-table-wrap {
    width: 100%;
    overflow-x: auto;
}

.model-table,
.plain-table {
    width: 100%;
    border-collapse: collapse;
}

.model-table th,
.model-table td,
.plain-table th,
.plain-table td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.model-table th,
.plain-table th {
    color: var(--muted);
    font-weight: 600;
    background: var(--surface-muted);
}

.favorite-column {
    width: 54px;
    text-align: center !important;
}

.favorite-button {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #a0a6af;
    font-size: 17px;
}

.favorite-button:hover {
    background: var(--amber-soft);
    color: var(--amber);
}

.favorite-button.active {
    color: var(--amber);
}

.model-name {
    font-family: "SFMono-Regular", Consolas, monospace;
    word-break: break-word;
}

.capability-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.capability-badge,
.model-status,
.app-status {
    min-height: 20px;
    padding: 2px 6px;
    font-size: 11px;
}

.capability-badge.text {
    background: var(--blue-soft);
    color: var(--blue);
}

.capability-badge.image {
    background: var(--amber-soft);
    color: var(--amber);
}

.capability-badge.vision {
    background: var(--primary-soft);
    color: var(--primary);
}

.model-status,
.app-status {
    background: var(--primary-soft);
    color: var(--primary);
}

.model-status.pending {
    background: var(--amber-soft);
    color: var(--amber);
}

.empty-state {
    padding: 28px 12px !important;
    color: var(--muted);
    text-align: center !important;
}

.assignment-list {
    overflow: hidden;
}

.assignment-row {
    min-height: 94px;
    padding: 15px;
    display: grid;
    grid-template-columns: 40px minmax(170px, 1fr) minmax(380px, 1.5fr);
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

.assignment-row:last-child {
    border-bottom: 0;
}

.assignment-symbol {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: var(--surface-muted);
    color: var(--primary);
    font-size: 15px;
    font-weight: 650;
}

.assignment-copy h3,
.assignment-copy p {
    margin: 0;
}

.assignment-copy h3 {
    font-size: 13px;
    font-weight: 650;
}

.assignment-copy p {
    margin-top: 3px;
    color: var(--muted);
}

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

.connected-apps-section {
    margin-top: 18px;
}

.connected-apps-section .section-heading-row {
    margin-bottom: 8px;
}

.plain-table {
    background: var(--surface);
    border: 1px solid var(--border);
}

.settings-list {
    overflow: hidden;
}

.settings-row {
    min-height: 92px;
    padding: 16px;
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(220px, auto);
    align-items: center;
    gap: 24px;
    border-bottom: 1px solid var(--border);
}

.settings-row:last-child {
    border-bottom: 0;
}

.readonly-value {
    min-width: 220px;
    max-width: 420px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-muted);
    color: var(--muted);
}

.row-actions {
    justify-content: flex-end;
    gap: 7px;
}

.danger-row {
    background: #fffdfd;
}

.danger-row h3 {
    color: var(--danger);
}

.dialog {
    width: min(430px, calc(100% - 28px));
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.dialog::backdrop {
    background: rgba(21, 28, 34, 0.42);
}

.dialog form {
    padding: 16px;
}

.dialog-heading {
    margin-bottom: 15px;
    padding-bottom: 12px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

.dialog-heading h2 {
    font-size: 15px;
    font-weight: 650;
}

.dialog-heading p {
    margin-top: 3px;
    color: var(--muted);
}

.dialog .field + .field {
    margin-top: 12px;
}

.dialog-actions {
    margin-top: 18px;
    display: flex;
    justify-content: flex-end;
    gap: 7px;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 20;
    max-width: min(390px, calc(100vw - 36px));
    padding: 9px 12px;
    border-radius: 6px;
    background: #27313a;
    color: #ffffff;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 150ms ease, transform 150ms ease;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.error {
    background: var(--danger);
}

.toast.success {
    background: var(--primary);
}
