:root {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --text: #172033;
    --muted: #6f7a8d;
    --line: #e4e8ef;
    --primary: #1d4ed8;
    --primary-dark: #173ea7;
    --danger: #b42318;
    --success-bg: #ecfdf3;
    --success-text: #067647;
    --error-bg: #fff1f0;
    --error-text: #b42318;
    --shadow: 0 12px 30px rgba(20, 32, 55, .06);
}
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "HarmonyOS Sans", "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .94em; }
.app-shell { min-height: 100vh; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 10;
    display: flex; flex-direction: column; padding: 24px 18px;
    color: #eef3ff; background: #111827;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
    color: white; background: #2563eb; font-weight: 800; letter-spacing: -.04em;
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 14px; }
.brand span { margin-top: 1px; color: #8fa0ba; font-size: 11px; }
.sidebar nav { margin-top: 32px; display: grid; gap: 6px; }
.sidebar nav a { padding: 10px 12px; border-radius: 8px; color: #b9c4d6; text-decoration: none; }
.sidebar nav a:hover { background: #1f2937; color: #fff; }
.sidebar nav a.active { background: #263348; color: #fff; font-weight: 650; }
.sidebar-footer { margin-top: auto; padding: 16px 12px 0; border-top: 1px solid #293447; }
.signed-in { margin-bottom: 8px; color: #9aa8bc; font-size: 12px; }
.link-button { border: 0; padding: 0; color: #c9d4e5; background: none; cursor: pointer; }
.link-button:hover { color: #fff; text-decoration: underline; }
.main { min-height: 100vh; margin-left: 250px; padding: 36px 40px 60px; }
.main-auth { margin-left: 0; padding: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.page-head.compact { align-items: flex-start; }
.page-head h1 { margin: 3px 0 2px; font-size: 28px; line-height: 1.25; letter-spacing: -.02em; }
.page-head p { margin: 0; color: var(--muted); }
.back-link { display: inline-block; margin-bottom: 8px; color: var(--muted); }
.head-actions { display: flex; align-items: center; gap: 8px; }
.head-actions form { margin: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.search-card { margin-bottom: 16px; padding: 14px 16px; }
.search-form { display: flex; gap: 8px; }
.search-input-wrap { flex: 1; }
.search-form input { width: 100%; }
.result-count { margin-top: 10px; color: var(--muted); font-size: 12px; }
input, textarea, select {
    width: 100%; border: 1px solid #cfd6e2; border-radius: 8px; padding: 10px 12px;
    color: var(--text); background: #fff; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { border-color: #7598ef; box-shadow: 0 0 0 3px rgba(37, 99, 235, .10); }
textarea { resize: vertical; }
select { cursor: pointer; }
.button {
    display: inline-flex; align-items: center; justify-content: center; min-height: 39px; padding: 8px 14px;
    border: 1px solid #cfd6e2; border-radius: 8px; color: #273248; background: #fff;
    font-weight: 650; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.button:hover { border-color: #aeb8c8; background: #f8fafc; text-decoration: none; }
.button.primary { border-color: var(--primary); color: #fff; background: var(--primary); }
.button.primary:hover { border-color: var(--primary-dark); background: var(--primary-dark); }
.button.danger { border-color: #f0b5af; color: var(--danger); background: #fff7f6; }
.button.ghost { color: var(--muted); background: transparent; }
.button.full { width: 100%; }
.table-card { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: #657086; background: #fafbfc; font-size: 12px; font-weight: 700; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfe; }
.server-link { color: var(--text); font-weight: 700; }
.actions { display: flex; gap: 10px; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.empty-state { display: grid; justify-items: center; gap: 4px; padding: 64px 20px; color: var(--muted); }
.empty-state strong { color: var(--text); font-size: 16px; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 20px; color: var(--muted); }
.alert { margin-bottom: 18px; padding: 12px 14px; border-radius: 9px; }
.alert.success { color: var(--success-text); background: var(--success-bg); border: 1px solid #abefc6; }
.alert.error { color: var(--error-text); background: var(--error-bg); border: 1px solid #f7c5c0; }
.error-list > div + div { margin-top: 4px; }
.form-card { max-width: 920px; padding: 0; overflow: hidden; }
.form-section { padding: 24px; border-bottom: 1px solid var(--line); }
.section-title, .card-title { margin-bottom: 18px; }
.section-title strong, .section-title span, .card-title strong, .card-title span { display: block; }
.section-title strong, .card-title strong { font-size: 16px; }
.section-title span, .card-title span { color: var(--muted); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.full-span { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 7px; font-weight: 700; }
.field label span { margin-left: 5px; color: var(--muted); font-size: 11px; font-weight: 500; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 18px 24px; background: #fbfcfd; }
.narrow-form { max-width: 600px; padding: 24px; }
.narrow-form .field + .field { margin-top: 18px; }
.narrow-form .form-actions { margin: 24px -24px -24px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.detail-card { padding: 22px; }
.full-detail { grid-column: 1 / -1; }
.details { margin: 0; }
.details > div { display: grid; grid-template-columns: 130px 1fr; gap: 18px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.details > div:last-child { border-bottom: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; min-width: 0; }
.details dd code { word-break: break-all; }
.copy-button {
    margin-left: 8px; padding: 2px 7px; border: 1px solid #d8dee8; border-radius: 6px;
    color: #5b6780; background: #fff; font-size: 11px; cursor: pointer;
}
.copy-button:hover { color: var(--primary); border-color: #9bb2ec; }
.graph-link { display: inline-block; text-decoration: none; }
.graph-link:hover { text-decoration: none; }
.no-left-margin { margin-left: 0; }
.table-graph-link { margin-left: 8px; font-size: 11px; white-space: nowrap; }
.copy-button:disabled { opacity: .6; cursor: wait; }
.hidden { display: none !important; }
.security-note { margin-top: 14px; padding: 10px 12px; border-radius: 8px; color: #6f5b1c; background: #fffaeb; font-size: 12px; }
.ip-list { display: grid; gap: 8px; }
.ip-list > div { display: flex; align-items: center; }
.notes-content { min-height: 50px; white-space: normal; word-break: break-word; }
.muted { color: var(--muted); }
.auth-wrap, .install-wrap { min-height: 100vh; display: grid; place-items: center; padding: 28px; }
.auth-card, .install-card { width: 100%; max-width: 430px; padding: 30px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 18px 50px rgba(20, 32, 55, .09); }
.auth-brand, .install-brand { margin-bottom: 30px; }
.auth-card h1, .install-card h1 { margin: 0 0 4px; font-size: 25px; }
.auth-card .field, .install-card .field { margin-top: 18px; }
.auth-card .button, .install-card .button { margin-top: 22px; }
.install-body { background: #f3f6fb; }
.checks { margin: 22px 0; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.checks > div { display: flex; justify-content: space-between; padding: 9px 11px; border-bottom: 1px solid var(--line); }
.checks > div:last-child { border-bottom: 0; }
.checks .ok { color: var(--success-text); }
.checks .bad { color: var(--danger); }
.install-note { margin: 20px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

.search-form-wide select { width: min(320px, 32vw); }
.table-subtext { margin-top: 3px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.field-help { margin-top: 6px; color: var(--muted); font-size: 11px; }
.port-check-status { min-height: 20px; margin-top: 6px; font-size: 12px; }
.port-check-status.checking { color: var(--muted); }
.port-check-status.available { color: var(--success-text); }
.port-check-status.conflict, .port-check-status.error { color: var(--danger); }
input[aria-invalid="true"] { border-color: #e58d84; box-shadow: 0 0 0 3px rgba(180, 35, 24, .08); }
.inline-notice { margin-bottom: 18px; padding: 11px 13px; border: 1px solid #c9d8fb; border-radius: 8px; color: #31466f; background: #f4f7ff; }
.empty-inline { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 100px; }
.card-section-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.card-title.no-margin { margin: 0; }
.compact-empty { padding: 36px 20px; }
@media (max-width: 760px) {
    .search-form-wide select { width: 100%; flex-basis: 100%; }
    .card-section-head { align-items: stretch; flex-direction: column; }
    .card-section-head .button { width: 100%; }
}

@media (max-width: 900px) {
    .sidebar { position: static; width: auto; min-height: auto; }
    .sidebar nav { grid-template-columns: repeat(4, 1fr); margin-top: 20px; }
    .sidebar-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; }
    .signed-in { margin: 0; }
    .main { margin-left: 0; padding: 26px 20px 48px; }
    .main-auth { padding: 0; }
    .detail-grid { grid-template-columns: 1fr; }
    .full-detail { grid-column: auto; }
}
@media (max-width: 640px) {
    .sidebar nav { grid-template-columns: 1fr; }
    .page-head { align-items: stretch; flex-direction: column; }
    .head-actions { width: 100%; }
    .head-actions .button, .head-actions form, .head-actions form .button { flex: 1; width: 100%; }
    .search-form { flex-wrap: wrap; }
    .search-input-wrap { flex-basis: 100%; }
    .form-grid { grid-template-columns: 1fr; }
    .full-span { grid-column: auto; }
    .details > div { grid-template-columns: 1fr; gap: 5px; }
    .auth-wrap, .install-wrap { padding: 16px; }
    .auth-card, .install-card { padding: 24px 20px; }
}

/* Tags */
.tag-badge-list, .server-tag-cell, .tag-cloud { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tag-badge {
    display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border: 1px solid transparent;
    border-radius: 999px; font-size: 11px; font-weight: 700; line-height: 1.35; white-space: nowrap;
}
.tag-red { color: #9f2017; background: #fff1ef; border-color: #f3b8b2; }
.tag-orange { color: #9a4b06; background: #fff5e8; border-color: #f2c48e; }
.tag-yellow { color: #78610b; background: #fffbea; border-color: #ead984; }
.tag-blue { color: #2556a5; background: #eef4ff; border-color: #b9cef7; }
.tag-green { color: #17663a; background: #ecfdf3; border-color: #a9e8c2; }
.tag-purple { color: #6840a4; background: #f6f0ff; border-color: #d6c1f4; }
.tag-gray { color: #556174; background: #f3f5f8; border-color: #d6dce5; }
.tag-inactive { opacity: .58; filter: grayscale(.18); }
.tag-more { color: var(--muted); font-size: 11px; white-space: nowrap; }

.tag-choice { position: relative; display: inline-flex; cursor: pointer; }
.tag-choice input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.tag-choice span {
    display: inline-flex; align-items: center; min-height: 29px; padding: 5px 10px; border: 1px solid currentColor;
    border-radius: 999px; font-size: 12px; font-weight: 650; line-height: 1.2; opacity: .72;
    transition: transform .12s, box-shadow .12s, opacity .12s;
}
.tag-choice:hover span { opacity: 1; transform: translateY(-1px); }
.tag-choice input:focus-visible + span { outline: 3px solid rgba(37, 99, 235, .22); outline-offset: 2px; }
.tag-choice input:checked + span { opacity: 1; box-shadow: inset 0 0 0 1px currentColor, 0 2px 7px rgba(27, 39, 64, .10); }
.tag-editor-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.button.small { min-height: 31px; padding: 5px 10px; font-size: 12px; }
.text-link { font-size: 12px; }
.inline-tag-create {
    display: grid; grid-template-columns: minmax(180px, 1fr) minmax(180px, 260px) auto; gap: 8px;
    align-items: center; margin-top: 12px; padding: 12px; border: 1px dashed #c8d2e3; border-radius: 9px; background: #fafcff;
}
.inline-status { grid-column: 1 / -1; min-height: 16px; color: var(--muted); font-size: 11px; }
.inline-status.success { color: var(--success-text); }
.inline-status.error { color: var(--danger); }

.tag-filter-form { flex-wrap: wrap; }
.full-search-row { flex: 1 0 100%; }
.tag-filter-panel { margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--line); }
.tag-filter-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 9px; }
.tag-filter-heading strong { font-size: 12px; }
.tag-filter-heading select { width: auto; min-width: 170px; padding: 6px 9px; font-size: 12px; }
.compact-tag-cloud { gap: 5px; }
.compact-tag-cloud .tag-choice span { min-height: 26px; padding: 4px 8px; font-size: 11px; }
.server-tags-column { min-width: 190px; }
.server-tag-cell { margin-bottom: 5px; }
.quick-tag-button { border: 0; padding: 0; color: var(--primary); background: transparent; font-size: 11px; cursor: pointer; }
.quick-tag-button:hover { text-decoration: underline; }

.tag-dialog { width: min(680px, calc(100vw - 28px)); padding: 0; border: 0; border-radius: 13px; box-shadow: 0 24px 80px rgba(18, 28, 46, .28); }
.tag-dialog::backdrop { background: rgba(17, 24, 39, .46); }
.tag-dialog-card { margin: 0; }
.tag-dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.tag-dialog-head strong, .tag-dialog-head span { display: block; }
.tag-dialog-head span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.dialog-close { border: 0; padding: 0 5px; color: var(--muted); background: transparent; font-size: 25px; line-height: 1; cursor: pointer; }
.dialog-tag-cloud { max-height: 48vh; overflow-y: auto; padding: 20px 22px; }
.tag-dialog-status { min-height: 20px; padding: 0 22px; color: var(--muted); font-size: 12px; }
.tag-dialog-status.error { color: var(--danger); }
.tag-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 22px 20px; }

.tag-create-card { margin-bottom: 16px; padding: 20px; }
.tag-create-form { display: grid; grid-template-columns: minmax(190px, 1.2fr) minmax(190px, 1fr) 110px auto auto auto; gap: 12px; align-items: end; }
.tag-create-form .field label { font-size: 12px; }
.check-field { display: flex; align-items: center; gap: 6px; min-height: 39px; white-space: nowrap; cursor: pointer; }
.check-field input, .table-check input { width: auto; }
.tag-management-table input, .tag-management-table select { min-width: 120px; padding: 7px 8px; font-size: 12px; }
.tag-management-table .order-input { min-width: 74px; width: 74px; }
.table-check { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.row-inactive { background: #fafafa; }
.tag-policy-note { margin-top: 16px; }

@media (max-width: 1100px) {
    .tag-create-form { grid-template-columns: 1fr 1fr 100px; }
    .tag-create-form .check-field, .tag-create-form .button { align-self: center; }
}
@media (max-width: 900px) {
    .sidebar nav { grid-template-columns: repeat(5, 1fr); }
}
@media (max-width: 760px) {
    .inline-tag-create { grid-template-columns: 1fr; }
    .tag-filter-heading { align-items: stretch; flex-direction: column; }
    .tag-filter-heading select { width: 100%; }
    .tag-create-form { grid-template-columns: 1fr; }
    .tag-create-form .small-field { width: 100%; }
}
@media (max-width: 640px) {
    .sidebar nav { grid-template-columns: 1fr; }
    .tag-dialog-actions .button { flex: 1; }
}
.tag-choice.tag-red, .tag-choice.tag-orange, .tag-choice.tag-yellow, .tag-choice.tag-blue,
.tag-choice.tag-green, .tag-choice.tag-purple, .tag-choice.tag-gray { background: transparent; border-color: transparent; }
.tag-choice.tag-red span { color: #9f2017; background: #fff1ef; border-color: #f3b8b2; }
.tag-choice.tag-orange span { color: #9a4b06; background: #fff5e8; border-color: #f2c48e; }
.tag-choice.tag-yellow span { color: #78610b; background: #fffbea; border-color: #ead984; }
.tag-choice.tag-blue span { color: #2556a5; background: #eef4ff; border-color: #b9cef7; }
.tag-choice.tag-green span { color: #17663a; background: #ecfdf3; border-color: #a9e8c2; }
.tag-choice.tag-purple span { color: #6840a4; background: #f6f0ff; border-color: #d6c1f4; }
.tag-choice.tag-gray span { color: #556174; background: #f3f5f8; border-color: #d6dce5; }

/* Manual IPMI inspection */
.card-title-actions { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.card-title-actions > div { min-width: 0; }
.ipmi-check-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin-bottom: 14px; color: var(--muted); font-size: 12px; }
.ipmi-status-badge { display: inline-flex; align-items: center; min-height: 27px; padding: 4px 10px; border: 1px solid transparent; border-radius: 999px; font-weight: 750; }
.ipmi-status-badge.status-never { color: #556174; background: #f3f5f8; border-color: #d6dce5; }
.ipmi-status-badge.status-success { color: #17663a; background: #ecfdf3; border-color: #a9e8c2; }
.ipmi-status-badge.status-partial { color: #9a4b06; background: #fff5e8; border-color: #f2c48e; }
.ipmi-status-badge.status-failed { color: #9f2017; background: #fff1ef; border-color: #f3b8b2; }
.ipmi-check-message { min-height: 21px; margin-bottom: 6px; font-size: 12px; }
.ipmi-check-message.checking { color: var(--muted); }
.ipmi-check-message.success { color: var(--success-text); }
.ipmi-check-message.warning { color: #9a4b06; }
.ipmi-check-message.error { color: var(--danger); }
.ipmi-result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 12px; }
.ipmi-result-block { padding: 15px 16px; border: 1px solid var(--line); border-radius: 10px; background: #fbfcfe; }
.ipmi-result-block h3 { margin: 0 0 8px; font-size: 13px; }
.mini-details { margin: 0; }
.mini-details > div { display: grid; grid-template-columns: 135px 1fr; gap: 12px; padding: 7px 0; border-bottom: 1px solid #ebeff5; }
.mini-details > div:last-child { border-bottom: 0; }
.mini-details dt { color: var(--muted); }
.mini-details dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.state-ok { color: var(--success-text); font-weight: 700; }
.state-bad { color: var(--danger); font-weight: 700; }
.ipmi-failure-box { margin-top: 16px; padding: 13px 15px; border: 1px solid #f3b8b2; border-radius: 9px; color: #7d251d; background: #fff6f5; }
.ipmi-failure-box strong, .ipmi-failure-box span { display: block; }
.ipmi-failure-box p { margin: 5px 0; overflow-wrap: anywhere; }
.ipmi-failure-box span { color: #98635e; font-size: 11px; }
.manual-check-note { margin-top: 16px; padding: 10px 12px; border-radius: 8px; color: #536077; background: #f5f7fa; font-size: 11px; }

@media (max-width: 760px) {
    .card-title-actions { align-items: stretch; flex-direction: column; }
    .card-title-actions .button { width: 100%; }
    .ipmi-result-grid { grid-template-columns: 1fr; }
    .mini-details > div { grid-template-columns: 1fr; gap: 3px; }
}
