/* MeDia 화면 공통 스타일 — 다크 테마 기본, 폰 폭 우선 */
:root {
    --bg: #0f1115;
    --surface: #181b22;
    --surface-2: #20242d;
    --border: #2c313c;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --accent: #4f8cff;
    --accent-text: #ffffff;
    --danger: #ff6b6b;
    --ok: #3ecf8e;
    --radius: 10px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand { color: var(--text); font-weight: 700; font-size: 1.15rem; }

.menu { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.menu form { margin: 0; }

.page { max-width: 960px; margin: 0 auto; padding: 24px 16px 48px; }

.narrow { max-width: 420px; margin: 0 auto; }

h1 { font-size: 1.5rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 28px 0 12px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.card > h2:first-child, .card > :first-child { margin-top: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

label { display: block; margin: 0 0 6px; color: var(--muted); font-size: 0.9rem; }

.field { margin-bottom: 14px; }

input[type=text], input[type=password], input[type=number], select {
    width: 100%;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
}

input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

input.code { font-size: 1.4rem; letter-spacing: 0.3em; text-align: center; }

.check { display: flex; align-items: center; gap: 8px; color: var(--text); }

fieldset.perms { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; display: grid; gap: 8px; }
fieldset.perms legend { color: var(--muted); font-size: 0.9rem; padding: 0 4px; }
.row-actions form.perm-form { flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.row-actions form.perm-form .check { width: auto; }
.check input { width: 18px; height: 18px; }

button, .button {
    display: inline-block;
    padding: 10px 16px;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

button.block { width: 100%; }
button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button.link { background: none; padding: 0; color: var(--accent); font-weight: 400; }
button.small { padding: 6px 10px; font-size: 0.875rem; }

/* UI 헌법 제1조 — 꺼진 버튼은 회색으로 눌리지 않음을 드러낸다(모든 버튼 종류보다 뒤에 두어 덮이지 않게) */
button:disabled, button.secondary:disabled, button.danger:disabled {
    background: var(--surface-2);
    color: #5d6470;
    border: 1px dashed var(--border);
    cursor: not-allowed;
}

.gate-hint { margin: 0 0 10px; color: var(--muted); font-size: 0.875rem; }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; }
.alert.error { background: rgba(255, 107, 107, 0.12); color: var(--danger); }
.alert.ok { background: rgba(62, 207, 142, 0.12); color: var(--ok); }

.qr { display: block; width: 220px; height: 220px; margin: 8px auto 12px; background: #fff; border-radius: 8px; padding: 8px; }

.secret { font-family: ui-monospace, Consolas, monospace; word-break: break-all; background: var(--surface-2); padding: 8px 10px; border-radius: 6px; }

.codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; padding: 0; list-style: none; }
.codes li { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 8px; border-radius: 6px; text-align: center; white-space: nowrap; letter-spacing: 0.04em; }

.list { width: 100%; border-collapse: collapse; }
.list th, .list td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.list th { color: var(--muted); font-weight: 500; font-size: 0.875rem; }

.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.row-actions form { margin: 0; display: flex; gap: 6px; }
.row-actions input, .row-actions select { width: auto; padding: 6px 8px; font-size: 0.875rem; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.8rem; background: var(--surface-2); color: var(--muted); }
.tag.on { color: var(--ok); }
.tag.off { color: var(--danger); }

/* 폰 폭 — 표를 카드형 줄로 */
@media (max-width: 640px) {
    .list thead { display: none; }
    .list tr { display: block; border-bottom: 1px solid var(--border); padding: 8px 0; }
    .list td { display: block; border: 0; padding: 4px 0; }
    .list td[data-label]::before { content: attr(data-label) " "; color: var(--muted); font-size: 0.875rem; }
}
