:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --line: #e3e8ef;
  --ink: #17212b;
  --muted: #667085;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --green: #16865a;
  --green-soft: #eaf8f1;
  --red: #d64545;
  --red-soft: #fff1f1;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

main { max-width: 1020px; margin: 0 auto; padding: 30px 22px 60px; }
h1 { margin: 5px 0 0; font-size: 26px; letter-spacing: -.03em; }
h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
p { margin: 6px 0 0; color: var(--muted); }
small, .hint { color: var(--muted); }

.brand { color: var(--primary); font-size: 13px; font-weight: 900; letter-spacing: .13em; }
.brand span { color: var(--ink); }

.login-card {
  max-width: 390px;
  margin: 10vh auto;
  padding: 34px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 45px rgba(26, 43, 63, .08);
}

.login-card h1 { margin-top: 18px; }
.login-card form { margin-top: 22px; }

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

.header-actions { display: flex; align-items: center; gap: 10px; }
.user-chip { padding: 8px 12px; border-radius: 999px; background: #e9edf3; font-weight: 700; }

nav {
  display: flex;
  gap: 5px;
  width: fit-content;
  margin-bottom: 22px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

button {
  border: 0;
  border-radius: 9px;
  padding: 11px 16px;
  background: var(--primary);
  color: white;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

button:hover { filter: brightness(.96); }
button:disabled { cursor: not-allowed; opacity: .45; }
.nav-button { background: transparent; color: var(--muted); }
.nav-button.active { background: var(--primary-soft); color: var(--primary); }
.ghost { background: #edf1f5; color: #344054; }
.danger { background: var(--red); color: white; }
.danger.ghost { background: var(--red-soft); color: var(--red); }

.card {
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.wide { margin-top: 16px; }
.narrow { max-width: 720px; }
.section-title { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; }
.section-title p { font-size: 13px; }
.step { display: block; margin-bottom: 4px; color: var(--primary); font-size: 12px; font-weight: 800; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

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

.summary span { display: block; color: var(--muted); font-size: 13px; }
.summary strong { display: inline-block; margin-top: 4px; font-size: 25px; }
.summary small { margin-left: 4px; }
.user-summary { grid-template-columns: repeat(2, 1fr); }

.task-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 16px; }
.mapping-card { border-color: #b7cffc; box-shadow: 0 8px 25px rgba(37, 99, 235, .06); }

.form-stack { display: grid; gap: 13px; }
label { display: block; color: #475467; font-size: 13px; font-weight: 650; }

input, textarea, select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  border: 1px solid #ccd5df;
  border-radius: 9px;
  outline: none;
  background: white;
  color: var(--ink);
  font: inherit;
}

input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
textarea { resize: vertical; }

.profile-list { overflow: hidden; border: 1px solid var(--line); border-radius: 11px; }
.profile { background: white; border-bottom: 1px solid var(--line); }
.profile:last-child { border-bottom: 0; }
.profile summary { list-style: none; }
.profile summary::-webkit-details-marker { display: none; }

.profile summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 15px 17px;
  cursor: pointer;
}

.profile summary:hover { background: #fafbfc; }
.profile summary > span:first-child { display: flex; align-items: center; gap: 12px; min-width: 0; }
.profile summary strong { min-width: 130px; }
.profile summary small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile summary::after { content: "설정 ▾"; color: var(--primary); font-size: 12px; font-weight: 800; }
.profile[open] summary::after { content: "닫기 ▴"; }
.summary-badges { display: flex; gap: 7px; margin-left: auto; }
.summary-badges i { padding: 3px 8px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 11px; font-style: normal; font-weight: 800; }
.summary-badges i.off { background: var(--red-soft); color: var(--red); }

.profile-body { padding: 18px; border-top: 1px solid var(--line); background: #fafbfc; }
.compact { margin: 12px 0; }
.button-row { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.button-row input { flex: 1 1 210px; width: auto; margin: 0; }

.toggle-list { display: grid; gap: 1px; margin: 8px 0 18px; }
.toggle {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin: 0;
  padding: 12px 0;
  color: var(--ink);
  font-size: 14px;
}
.toggle + .toggle { border-top: 1px solid var(--line); }
.toggle input { width: 18px; height: 18px; margin: 2px 0 0; box-shadow: none; }
.toggle span { flex: 1; }
.toggle b, .toggle small { display: block; }
.toggle small { margin-top: 2px; font-weight: 400; }

.device-list { display: grid; gap: 9px; }
.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
}
.device-main { min-width: 0; }
.device-main > strong, .device-main > small { display: block; }
.device-main > small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-meta { display: flex; flex-wrap: wrap; gap: 7px 12px; margin-top: 7px; color: var(--muted); font-size: 12px; }
.device-actions { display: flex; flex-shrink: 0; gap: 7px; }
.status { padding: 2px 7px; border-radius: 999px; font-weight: 800; }
.status-active { background: var(--green-soft); color: var(--green); }
.status-blocked { background: var(--red-soft); color: var(--red); }
.sync-pill { padding: 2px 7px; border-radius: 999px; font-weight: 800; }
.sync-success { background: var(--green-soft); color: var(--green); }
.sync-pending, .sync-waiting { background: #fff4d6; color: #8a5a00; }
.sync-failed { background: var(--red-soft); color: var(--red); }
.empty { padding: 24px; border: 1px dashed #cbd5e1; border-radius: 10px; color: var(--muted); text-align: center; }

.advanced { margin: 12px 0 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.advanced summary { padding: 15px 0; color: #475467; font-weight: 750; cursor: pointer; }

.audio-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.upload-box { display: grid; gap: 10px; padding: 16px; border: 1px solid var(--line); border-radius: 11px; }
.upload-box small { color: var(--primary); }
.upload-box input { margin: 0; }
.admin-sync-interval { max-width: 220px; }
#saveUserArs { margin-top: 14px; }

hr { margin: 22px 0; border: 0; border-top: 1px solid var(--line); }
.error { color: var(--red); }
#notice { position: sticky; top: 10px; z-index: 5; }
.notice { margin-bottom: 14px; padding: 12px 15px; border: 1px solid #9fd7bf; border-radius: 10px; background: var(--green-soft); color: #116243; font-weight: 700; }

@media (max-width: 760px) {
  main { padding: 18px 14px 40px; }
  .app-header { align-items: flex-start; }
  .header-actions { flex-direction: column; align-items: flex-end; }
  .summary-grid, .task-grid, .user-summary, .audio-grid { grid-template-columns: 1fr; }
  .summary-grid { gap: 8px; }
  .summary { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; }
  .summary strong { margin: 0; font-size: 21px; }
  .profile summary { align-items: flex-start; }
  .profile summary > span:first-child { align-items: flex-start; flex-direction: column; gap: 2px; }
  .profile summary strong { min-width: 0; }
  .summary-badges { display: none; }
  .device-item { align-items: flex-start; flex-direction: column; }
  .device-actions { width: 100%; }
  .device-actions button { flex: 1; }
  .button-row { flex-direction: column; align-items: stretch; }
  .button-row input { width: 100%; flex-basis: auto; }
}
