/* Material Design 3 – color roles, type scale, shape, elevation, state layers */
:root {
  --primary: #0b57d0; --on-primary: #fff;
  --primary-container: #d3e3fd; --on-primary-container: #041e49;
  --secondary-container: #dde3ea; --on-secondary-container: #151c22;
  --surface: #f8f9fc; --on-surface: #191c20; --on-surface-variant: #43474e;
  --sc-low: #f2f3f9; --sc: #ecedf3; --sc-high: #e6e8ee; --sc-highest: #e1e3e9;
  --outline: #74777f; --outline-variant: #c3c6cf;
  --error: #ba1a1a; --on-error: #fff; --error-container: #ffdad6; --on-error-container: #410002;
  --scrim: rgba(0, 0, 0, .32); --inverse-surface: #2e3135; --inverse-on-surface: #f0f0f7;
  --shadow1: 0 1px 2px rgba(0,0,0,.3), 0 1px 3px 1px rgba(0,0,0,.15);
  --shadow3: 0 1px 3px rgba(0,0,0,.3), 0 4px 8px 3px rgba(0,0,0,.15);
  --r-xs: 4px; --r-s: 8px; --r-m: 12px; --r-l: 16px; --r-xl: 28px;
  font-family: "Roboto", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --primary: #a8c7fa; --on-primary: #062e6f;
  --primary-container: #0842a0; --on-primary-container: #d3e3fd;
  --secondary-container: #3f4759; --on-secondary-container: #dde3ea;
  --surface: #111318; --on-surface: #e2e2e9; --on-surface-variant: #c3c6cf;
  --sc-low: #191c20; --sc: #1d2024; --sc-high: #282a2f; --sc-highest: #33353a;
  --outline: #8d9199; --outline-variant: #43474e;
  --error: #ffb4ab; --on-error: #690005; --error-container: #93000a; --on-error-container: #ffdad6;
  --scrim: rgba(0, 0, 0, .6); --inverse-surface: #e2e2e9; --inverse-on-surface: #2e3135;
  color-scheme: dark;
}
* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { background: var(--surface); color: var(--on-surface); font-size: 14px; line-height: 20px; letter-spacing: .25px; }
button, input, select { font: inherit; color: inherit; }
.title-l { font-size: 22px; line-height: 28px; font-weight: 400; letter-spacing: 0; }
.title-m { font-size: 16px; line-height: 24px; font-weight: 500; letter-spacing: .15px; }
.headline-s { font-size: 24px; line-height: 32px; font-weight: 400; letter-spacing: 0; }
.body-s { font-size: 12px; line-height: 16px; letter-spacing: .4px; color: var(--on-surface-variant); }
svg.ic { width: 24px; height: 24px; fill: currentColor; flex: none; }

/* state layer */
.state { position: relative; overflow: hidden; }
.state::after { content: ""; position: absolute; inset: 0; background: currentColor; opacity: 0; transition: opacity .15s; pointer-events: none; }
.state:hover::after { opacity: .08; }
.state:focus-visible::after { opacity: .12; }
.state:active::after { opacity: .12; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 24px; border: 0; border-radius: 20px; background: none; cursor: pointer; font-weight: 500; letter-spacing: .1px; white-space: nowrap; }
.btn.has-icon { padding: 0 24px 0 16px; }
.btn.filled { background: var(--primary); color: var(--on-primary); }
.btn.tonal { background: var(--secondary-container); color: var(--on-secondary-container); }
.btn.outlined { border: 1px solid var(--outline); color: var(--primary); }
.btn.text { color: var(--primary); padding: 0 12px; }
.btn.danger { background: var(--error); color: var(--on-error); }
.btn:disabled { opacity: .38; pointer-events: none; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: none; cursor: pointer; display: inline-grid; place-items: center; color: var(--on-surface-variant); flex: none; }
.icon-btn.danger { color: var(--error); }
.fab { position: fixed; right: 16px; bottom: 16px; z-index: 5; height: 56px; padding: 0 20px 0 16px; border: 0; border-radius: var(--r-l); background: var(--primary-container); color: var(--on-primary-container); box-shadow: var(--shadow3); display: inline-flex; align-items: center; gap: 12px; font-weight: 500; cursor: pointer; }

/* text field (outlined) */
.field { position: relative; display: block; margin-bottom: 20px; }
.field input, .field select { width: 100%; height: 56px; padding: 0 16px; border: 1px solid var(--outline); border-radius: var(--r-xs); background: transparent; font-size: 16px; letter-spacing: .5px; outline: none; }
.field select { appearance: none; padding-right: 40px; cursor: pointer; }
.field select option { background: var(--sc-high); color: var(--on-surface); }
.field label { position: absolute; left: 12px; top: 16px; padding: 0 4px; background: var(--sc-high); color: var(--on-surface-variant); font-size: 16px; pointer-events: none; transform-origin: left top; transition: transform .15s, color .15s; }
.field input:focus, .field select:focus { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.field input:focus + label, .field input:not(:placeholder-shown) + label, .field select + label { transform: translateY(-24px) scale(.75); }
.field input:focus + label, .field select:focus + label { color: var(--primary); }
.field .hint { display: block; margin: 4px 16px 0; }
.card-surface .field label, .login-card .field label { background: var(--sc-low); }
.login-card .field label { background: var(--sc-low); }

/* switch */
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 16px; border: 2px solid var(--outline); background: var(--sc-highest); transition: .2s; }
.switch span::before { content: ""; position: absolute; top: 50%; left: 6px; width: 16px; height: 16px; border-radius: 50%; background: var(--outline); transform: translateY(-50%); transition: .2s; }
.switch input:checked + span { background: var(--primary); border-color: var(--primary); }
.switch input:checked + span::before { left: 24px; width: 24px; height: 24px; background: var(--on-primary); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 8px; }

/* segmented button */
.segmented { display: inline-flex; border: 1px solid var(--outline); border-radius: 20px; overflow: hidden; }
.segmented button { min-width: 44px; height: 38px; padding: 0 12px; border: 0; border-left: 1px solid var(--outline); background: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.segmented button:first-child { border-left: 0; }
.segmented button[aria-pressed="true"] { background: var(--secondary-container); color: var(--on-secondary-container); font-weight: 500; }
.segmented button[aria-pressed="true"]::before { content: "✓"; font-size: 14px; }

/* login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--sc-low); border-radius: var(--r-xl); padding: 40px 32px 32px; box-shadow: var(--shadow1); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; color: var(--primary); }
.brand .logo { width: 48px; height: 48px; border-radius: 16px; background: var(--primary-container); color: var(--on-primary-container); display: grid; place-items: center; }
.login-card h1 { margin-bottom: 4px; }
.login-card p { color: var(--on-surface-variant); margin-bottom: 28px; }
.login-card .btn { width: 100%; height: 48px; border-radius: 24px; }
.form-error { min-height: 20px; margin: -8px 0 12px; color: var(--error); font-size: 13px; }

/* app shell */
.app { display: grid; grid-template-rows: 64px 1fr; grid-template-columns: 80px 1fr; grid-template-areas: "top top" "rail main"; height: 100%; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 4px; padding: 0 12px 0 20px; background: var(--surface); }
.topbar .brand { margin: 0; flex: 1; }
.topbar .brand .logo { width: 36px; height: 36px; border-radius: 12px; }
.userchip { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px 0 8px; border: 0; border-radius: 20px; background: none; cursor: pointer; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-weight: 500; }
.rail { grid-area: rail; display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 12px; }
.nav-item { width: 80px; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 0; border: 0; background: none; cursor: pointer; font-size: 12px; font-weight: 500; letter-spacing: .5px; color: var(--on-surface-variant); }
.nav-item .pill { width: 56px; height: 32px; border-radius: 16px; display: grid; place-items: center; transition: background .2s; }
.nav-item[aria-current="page"] { color: var(--on-surface); }
.nav-item[aria-current="page"] .pill { background: var(--secondary-container); color: var(--on-secondary-container); }
.main { grid-area: main; overflow: auto; padding: 8px 24px 96px 8px; }
.page { max-width: 1800px; margin: 0 auto; }
.page-head { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 16px; padding: 8px 8px 16px 16px; }
.page-head h2 { flex: 1; min-width: 140px; }
.page-head .tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* viewer grid */
.grid { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 16px; padding: 0 8px 0 16px; }
.vcard { background: var(--sc-low); border-radius: var(--r-l); overflow: hidden; border: 1px solid var(--outline-variant); display: flex; flex-direction: column; }
.vcard-head { display: flex; align-items: center; gap: 4px; padding: 4px 4px 4px 16px; min-height: 48px; }
.vcard-head .title-m { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frame { position: relative; aspect-ratio: 16 / 9; background: #000; }
.frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.frame:fullscreen { aspect-ratio: auto; }
.frame.pseudo-fs { position: fixed; inset: 0; z-index: 100; aspect-ratio: auto; }
.frame .fs-exit { position: absolute; top: 8px; right: 8px; z-index: 2; background: rgba(0,0,0,.6); color: #fff; }
.frame:not(.pseudo-fs) .fs-exit { display: none; }

/* empty state */
.empty { text-align: center; padding: 64px 16px; color: var(--on-surface-variant); }
.empty svg.ic { width: 64px; height: 64px; opacity: .5; margin-bottom: 16px; }

/* list (manage) */
.list { background: var(--sc-low); border-radius: var(--r-l); margin: 0 8px 0 16px; overflow: hidden; border: 1px solid var(--outline-variant); }
.li { display: flex; align-items: center; gap: 16px; padding: 12px 8px 12px 16px; min-height: 72px; border-top: 1px solid var(--outline-variant); }
.li:first-child { border-top: 0; }
.li .lead { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-container); color: var(--on-primary-container); display: grid; place-items: center; flex: none; font-weight: 500; font-size: 16px; }
.li .txt { flex: 1; min-width: 0; }
.li .txt .l1 { font-size: 16px; line-height: 24px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .txt .l2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--on-surface-variant); }
.li .acts { display: flex; align-items: center; gap: 0; flex: none; }
.li.off .txt, .li.off .lead { opacity: .5; }
.chip { display: inline-flex; align-items: center; height: 24px; padding: 0 8px; margin-left: 8px; border-radius: var(--r-s); border: 1px solid var(--outline); font-size: 12px; font-weight: 500; vertical-align: middle; }
.chip.admin { background: var(--primary-container); color: var(--on-primary-container); border-color: transparent; }

/* dialog / menu / snackbar */
dialog { border: 0; border-radius: var(--r-xl); padding: 24px; background: var(--sc-high); color: var(--on-surface); width: min(calc(100% - 32px), 440px); max-height: calc(100% - 32px); margin: auto; box-shadow: var(--shadow3); }
dialog::backdrop { background: var(--scrim); }
dialog h3 { margin-bottom: 16px; }
dialog .body { margin-bottom: 16px; color: var(--on-surface-variant); }
dialog .field { margin-top: 8px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.menu { position: fixed; z-index: 50; min-width: 200px; padding: 8px 0; background: var(--sc-high); border-radius: var(--r-xs); box-shadow: var(--shadow3); }
.menu button { display: flex; align-items: center; gap: 12px; width: 100%; height: 48px; padding: 0 12px; border: 0; background: none; cursor: pointer; text-align: left; }
.snackbar { position: fixed; left: 50%; bottom: 24px; z-index: 200; transform: translate(-50%, 100px); max-width: calc(100% - 32px); padding: 14px 16px; border-radius: var(--r-xs); background: var(--inverse-surface); color: var(--inverse-on-surface); box-shadow: var(--shadow3); transition: transform .25s; }
.snackbar.show { transform: translate(-50%, 0); }
.progress { height: 4px; background: var(--primary-container); overflow: hidden; }
.progress::after { content: ""; display: block; width: 40%; height: 100%; background: var(--primary); animation: ind 1s infinite linear; }
@keyframes ind { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* compact: bottom navigation bar */
.bottom-nav { display: none; }
@media (max-width: 599px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 64px 1fr 80px; grid-template-areas: "top" "main" "bar"; }
  .rail { display: none; }
  .bottom-nav { grid-area: bar; display: flex; justify-content: space-around; align-items: center; background: var(--sc); }
  .bottom-nav .nav-item { width: auto; flex: 1; }
  .main { padding: 0 0 96px 0; }
  .grid { padding: 0 12px; gap: 12px; }
  .list { margin: 0 12px; }
  .page-head { padding: 8px 12px 12px; }
  .fab { bottom: 96px; }
  .userchip .uname { display: none; }
  .login-card { padding: 32px 24px 24px; border-radius: var(--r-l); }
  .snackbar { bottom: 96px; }
}
@media (max-width: 399px) { .topbar .brand .title-l { font-size: 18px; } }
