:root {
    color-scheme: dark;
    --bg: #080b13;
    --panel: rgba(20, 25, 39, 0.92);
    --border: #2a3144;
    --text: #f4f6fb;
    --muted: #929bb0;
    --accent: #7667ff;
    --accent-strong: #8c80ff;
    --green: #48d597;
    --red: #ff667d;
}

* { box-sizing: border-box; }
body { color: var(--text); font-family: Inter, Pretendard, "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, textarea { font: inherit; }

.key-page { display: grid; gap: 1rem; }
.key-hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem; padding: 0.5rem 0; }
.key-hero h1 { margin: 0; font-size: clamp(2.2rem, 5vw, 4rem); letter-spacing: -0.055em; }
.key-hero p:last-child { margin: 0.45rem 0 0; color: var(--muted); }
.eyebrow { margin: 0 0 0.35rem; color: var(--accent-strong); font-size: 0.68rem; font-weight: 850; letter-spacing: 0.14em; }
.master-badge { padding: 0.45rem 0.7rem; color: #ffd8df; border: 1px solid rgba(255, 102, 125, 0.4); border-radius: 999px; background: rgba(255, 102, 125, 0.08); font-size: 0.68rem; font-weight: 850; }

.security-notice { display: grid; gap: 0.25rem; padding: 0.9rem 1rem; color: #cabfff; border: 1px solid rgba(118, 103, 255, 0.3); border-radius: 0.8rem; background: rgba(118, 103, 255, 0.08); font-size: 0.76rem; }
.security-notice span { color: var(--muted); line-height: 1.55; }
.key-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.7rem; }
.key-summary > div { padding: 1rem; border: 1px solid var(--border); border-radius: 0.8rem; background: #101624; }
.key-summary span, .key-summary strong { display: block; }
.key-summary span { color: var(--muted); font-size: 0.68rem; }
.key-summary strong { margin-top: 0.4rem; overflow: hidden; text-overflow: ellipsis; font-size: 1.05rem; white-space: nowrap; }

.key-grid { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 1rem; align-items: start; }
.panel { padding: 1.2rem; border: 1px solid var(--border); border-radius: 1rem; background: var(--panel); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
h2 { margin: 0; font-size: 1.1rem; }
label { display: block; color: var(--muted); font-size: 0.72rem; font-weight: 750; }
label small, legend small { font-weight: 500; }
input, textarea {
    width: 100%;
    margin-top: 0.4rem;
    padding: 0.65rem 0.75rem;
    color: var(--text);
    border: 1px solid #343c51;
    border-radius: 0.65rem;
    outline: none;
    background: #0e1320;
}
input { min-height: 2.6rem; }
textarea { min-height: 5.2rem; resize: vertical; }
input:focus, textarea:focus { border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(118, 103, 255, 0.14); }
form { display: grid; gap: 0.8rem; }
fieldset { display: flex; gap: 1rem; margin: 0; padding: 0.7rem; border: 1px solid #30384d; border-radius: 0.7rem; }
legend { padding: 0 0.35rem; color: var(--muted); font-size: 0.7rem; font-weight: 750; }
.check-option { display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.check-option input { width: auto; min-height: auto; margin: 0; accent-color: var(--accent); }

.button { min-height: 2.55rem; padding: 0.58rem 0.9rem; color: var(--text); border: 1px solid transparent; border-radius: 0.6rem; cursor: pointer; font-weight: 750; }
.button:disabled { cursor: wait; opacity: 0.55; }
.button.primary { background: var(--accent); }
.button.primary:hover { background: var(--accent-strong); }
.button.quiet { border-color: #343c51; background: #161c2a; }
.button.danger { color: #ffd6dc; border-color: rgba(255, 102, 125, 0.4); background: rgba(255, 102, 125, 0.12); }
.button.compact { min-height: 2rem; padding: 0.35rem 0.55rem; font-size: 0.7rem; }
.button.wide { width: 100%; }
.status { display: inline-flex; padding: 0.32rem 0.58rem; border-radius: 999px; font-size: 0.68rem; font-weight: 800; white-space: nowrap; }
.status.neutral { color: var(--muted); background: #171d2a; }
.status.ok { color: #b9f9d9; background: rgba(72, 213, 151, 0.13); }
.status.error { color: #ffd1d8; background: rgba(255, 102, 125, 0.13); }
.form-message { min-height: 1.1rem; margin: 0.65rem 0 0; color: var(--muted); font-size: 0.74rem; }
.form-message.error { color: var(--red); }
.form-message.success { color: var(--green); }

.result-box { position: relative; margin-top: 0.8rem; padding: 0.85rem; border: 1px solid rgba(72, 213, 151, 0.3); border-radius: 0.7rem; background: rgba(72, 213, 151, 0.07); }
.result-box span, .result-box code { display: block; }
.result-box span { color: var(--muted); font-size: 0.68rem; }
.result-box code { margin: 0.45rem 4rem 0 0; overflow-wrap: anywhere; color: #b9f9d9; }
.result-box .button { position: absolute; top: 0.75rem; right: 0.75rem; }
.empty-state { margin: 0; padding: 2rem 1rem; color: var(--muted); text-align: center; font-size: 0.78rem; }
.selected-key-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.7rem; border: 1px solid #30384d; border-radius: 0.7rem; background: #0d121e; }
.selected-key-row code { min-width: 0; flex: 1; overflow-wrap: anywhere; color: #d5d0ff; }
#edit-role-form { grid-template-columns: 1fr auto auto auto; margin-top: 1rem; align-items: end; }
#edit-role-form fieldset { align-self: stretch; }
.probe-result { display: grid; gap: 0.45rem; margin-top: 0.8rem; padding: 0.75rem; border: 1px solid #30384d; border-radius: 0.7rem; background: #0d121e; }
.probe-result > div { display: flex; justify-content: space-between; gap: 1rem; color: var(--muted); font: 0.72rem ui-monospace, monospace; }
.pass { color: var(--green); }
.deny { color: var(--red); }

.list-actions { display: flex; align-items: center; gap: 0.6rem; }
.hint { color: var(--muted); font-size: 0.7rem; }
.table-wrap { overflow-x: auto; border: 1px solid #252c3c; border-radius: 0.75rem; background: #0d121e; }
table { width: 100%; min-width: 940px; border-collapse: collapse; }
th, td { padding: 0.72rem; border-bottom: 1px solid #222a3a; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 0.66rem; }
td { font-size: 0.76rem; }
td code { color: #aba4e9; }
tbody tr { transition: background 120ms ease; }
tbody tr:hover, tbody tr.selected { background: rgba(118, 103, 255, 0.09); }
.table-action { padding: 0; color: #aaa2ff; border: 0; background: transparent; cursor: pointer; font: inherit; font-weight: 750; }

@media (max-width: 1050px) {
    .key-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
    .key-hero { align-items: flex-start; flex-direction: column; gap: 0.8rem; }
    .key-summary { grid-template-columns: 1fr 1fr; }
    #edit-role-form { grid-template-columns: 1fr 1fr; }
    #edit-role-form fieldset { grid-column: 1 / -1; }
}
@media (max-width: 450px) {
    .key-summary { grid-template-columns: 1fr; }
    #edit-role-form { grid-template-columns: 1fr; }
    #edit-role-form fieldset { grid-column: auto; }
}
