:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #667085;
    --line: #d9dee7;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --danger: #b42318;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, "Microsoft YaHei", sans-serif;
}

.shell {
    width: min(1120px, calc(100% - 32px));
    margin: 28px auto 48px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 28px;
    line-height: 1.25;
}

h2 {
    margin-bottom: 14px;
    font-size: 18px;
}

p {
    margin-top: 6px;
    color: var(--muted);
}

.hint {
    font-size: 13px;
}

.panel {
    margin-top: 16px;
    padding: 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.grid {
    display: grid;
    gap: 14px;
}

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

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

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

label span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 13px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 12px;
    color: var(--text);
    font: inherit;
    outline: none;
}

textarea {
    margin-top: 14px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.token-grid {
    margin-top: 14px;
}

button {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0 14px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font: inherit;
}

button.primary {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}

button.primary:hover {
    background: var(--brand-dark);
}

button.danger {
    border-color: var(--danger);
    color: var(--danger);
}

#saveConfig {
    margin-top: 14px;
}

.actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 14px;
}

.actions.left {
    justify-content: flex-start;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.switch input {
    width: 18px;
    height: 18px;
}

.switch span {
    margin: 0;
    color: var(--text);
}

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

.rule-table,
.keyboard-table {
    display: grid;
    gap: 8px;
}

.rule-row,
.keyboard-row {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) minmax(220px, 1.4fr) minmax(220px, 1.3fr) 56px 140px;
    gap: 8px;
    align-items: center;
}

.keyboard-row {
    grid-template-columns: minmax(120px, 0.8fr) minmax(220px, 1.2fr) 58px minmax(220px, 1.2fr) 58px 140px;
}

.rule-head,
.keyboard-head {
    color: var(--muted);
    font-size: 13px;
}

#ruleList,
#keyboardList {
    display: grid;
    gap: 8px;
}

.row-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.mini-switch {
    display: flex;
    justify-content: center;
}

.mini-switch input {
    width: 18px;
    height: 18px;
}

.rule-item {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.rule-title {
    font-weight: 700;
}

.rule-meta {
    margin-top: 6px;
    color: var(--muted);
    font-size: 13px;
}

.rule-reply {
    margin-top: 8px;
    line-height: 1.6;
}

.rule-buttons {
    display: flex;
    gap: 8px;
    align-items: start;
}

.chat-test {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

pre {
    min-height: 48px;
    margin: 12px 0 0;
    padding: 12px;
    overflow: auto;
    border-radius: 6px;
    background: #111827;
    color: #f9fafb;
}

@media (max-width: 720px) {
    .topbar,
    .actions {
        align-items: stretch;
        flex-direction: column;
    }

    .grid.two,
    .chat-test,
    .rule-item,
    .rule-row,
    .keyboard-row {
        grid-template-columns: 1fr;
    }

    .rule-head,
    .keyboard-head {
        display: none;
    }

    .rule-buttons {
        justify-content: flex-end;
    }
}
