@import url("./tokens.css");
@import url("./screens.css");

/* 기본 컴포넌트 — iPadOS 앱 문법: 그룹 배경 위 흰 면, 머리카락 구분선, 채움 단추, 분할 단추, 반투명 막대. */

/* ───── 기본 ───── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 var(--fs)/1.47 var(--font); letter-spacing: -0.01em; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
h1, h2, h3, h4 { margin: 0; font-family: var(--font-display); letter-spacing: -0.02em; line-height: 1.2; }
p { margin: 0; }
a { color: var(--link); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent); outline-offset: 1px; border-radius: 8px; }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; letter-spacing: -0.015em; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: var(--s2); }
.stack { display: flex; flex-direction: column; gap: var(--s2); }
.wrap { flex-wrap: wrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ───── 단추(iOS: 채움 · 회색 채움 · 글자만) ───── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 30px; padding: 0 12px; border-radius: var(--r); border: 0;
  background: var(--fill); color: var(--text); font-weight: 600; font-size: var(--fs); cursor: pointer; white-space: nowrap; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background var(--t-fast) var(--ease), opacity var(--t-fast), transform var(--t-fast); }
.btn:hover { background: color-mix(in srgb, var(--fill) 100%, var(--text) 4%); }
.btn:active { transform: scale(0.97); opacity: 0.7; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-primary, .btn-accent { background: var(--accent); color: var(--accent-fg); }
.btn-primary:hover, .btn-accent:hover { background: var(--accent-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--fill-2); }
.btn-sm { min-height: 26px; padding: 0 9px; font-size: var(--fs-sm); border-radius: 7px; }
.btn-lg { min-height: 40px; padding: 0 18px; font-size: var(--fs-lg); border-radius: var(--r-lg); }
.btn-icon { width: 30px; padding: 0; }
.btn-sm.btn-icon { width: 26px; }
.btn .spin { width: 15px; height: 15px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* 분할 단추(UISegmentedControl) */
.seg { display: inline-flex; padding: 2px; gap: 0; border-radius: 9px; background: var(--fill); position: relative; }
.seg button { border: 0; background: transparent; padding: 4px 11px; min-height: 24px; border-radius: 7px; font-size: var(--fs-sm); font-weight: 500; color: var(--text); cursor: pointer; transition: background var(--t-fast), box-shadow var(--t-fast); position: relative; }
.seg button + button::before { content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 1px; background: var(--line-strong); opacity: 0.6; }
.seg button[aria-pressed="true"] { background: var(--surface); font-weight: 600; box-shadow: 0 3px 8px rgb(0 0 0 / 0.12), 0 3px 1px rgb(0 0 0 / 0.04); }
.seg button[aria-pressed="true"]::before, .seg button[aria-pressed="true"] + button::before { opacity: 0; }
:root[data-theme="dark"] .seg button[aria-pressed="true"] { background: #636366; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .seg button[aria-pressed="true"] { background: #636366; } }

/* ───── 입력 ───── */
.input, .select, .textarea { width: 100%; min-height: 32px; padding: 6px 10px; border-radius: var(--r); border: 0; background: var(--fill-2); font-size: var(--fs-md); transition: box-shadow var(--t-fast), background var(--t-fast); }
.select { appearance: none; -webkit-appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.textarea { min-height: 88px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; background: var(--surface); box-shadow: 0 0 0 1.5px var(--text-3), 0 0 0 4px var(--fill-2); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: var(--fs-sm); font-weight: 400; color: var(--text-2); padding-left: 2px; }
.field .hint { font-size: var(--fs-xs); color: var(--text-3); padding-left: 2px; }
.err { color: var(--danger-text); font-size: var(--fs-xs); }
.input[aria-invalid="true"] { box-shadow: 0 0 0 2px var(--danger); }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--s4); }

/* ───── 면(그룹 셀) ───── */
.card { background: var(--surface); border: 0; border-radius: var(--r-lg); }
.card-pad { padding: var(--s4) var(--s5); }
.card-h { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s5); min-height: 40px; border-bottom: 0.5px solid var(--line); }
.card-h h2, .card-h h3 { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -0.02em; }
.card-b { padding: var(--s4) var(--s5); }
.section-title { font-size: var(--fs-sm); font-weight: 400; color: var(--text-2); }

/* 칩(작은 꼬리표) */
.chip { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 7px; font-size: var(--fs-xs); font-weight: 600; background: var(--fill); color: var(--text-2); white-space: nowrap; }
.chip i.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.ok { background: var(--ok-soft); color: var(--ok-text); }
.chip.warn { background: var(--warn-soft); color: var(--warn-text); }
.chip.danger { background: var(--danger-soft); color: var(--danger-text); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.left { background: var(--left-soft); color: var(--left); }
.chip.right { background: var(--right-soft); color: var(--right); }
.grade { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; font-size: 10.5px; font-weight: 700; color: #fff; font-family: var(--num); }
.grade.A { background: var(--grade-a); } .grade.B { background: var(--grade-b); } .grade.C { background: var(--grade-c); }

/* 표(그룹 목록처럼: 머리카락 구분선) */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs); }
.table th { text-align: left; font-weight: 400; font-size: var(--fs-sm); color: var(--text-2); padding: 7px 12px; border-bottom: 0.5px solid var(--line); white-space: nowrap; }
.table td { padding: 8px 12px; border-bottom: 0.5px solid var(--line); vertical-align: middle; }
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr.click { cursor: pointer; }
.table tbody tr.click:hover { background: var(--fill-2); }
.table tbody tr.click:active { background: var(--fill); }
.table tr:last-child td { border-bottom: 0; }

/* 빈 화면·뼈대 */
.empty { display: grid; place-items: center; text-align: center; gap: var(--s3); padding: var(--s10) var(--s5); color: var(--text-2); }
.empty .ico { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 14px; background: var(--fill); color: var(--text-2); }
.skel { border-radius: var(--r-lg); background: linear-gradient(90deg, var(--fill-2) 0%, var(--fill) 50%, var(--fill-2) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ───── 알림창(UIAlertController 모양) · 토스트(HUD) ───── */
.dialog-backdrop { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; z-index: 100; padding: var(--s4); animation: fade var(--t) var(--ease-out); }
.dialog { width: min(300px, 100%); background: var(--material); border-radius: 14px; box-shadow: var(--shadow-3); overflow: hidden;
  padding: 20px 16px 0; display: flex; flex-direction: column; gap: 10px; text-align: center; animation: alert-in var(--t-slow) var(--ease-spring);
  -webkit-backdrop-filter: blur(40px) saturate(1.8); backdrop-filter: blur(40px) saturate(1.8); }
.dialog h2 { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -0.02em; }
.dialog p { color: var(--text); font-size: var(--fs-sm); }
.dialog .stack { gap: 4px; }
.dialog .field { text-align: left; }
.dialog.m-err { animation: alert-in var(--t-slow) var(--ease-spring), m-shake var(--t-slow) var(--ease) var(--t) 1; }
.d-icon { display: none; }
.d-fix { background: var(--fill-2); border-radius: 10px; padding: 10px 12px; font-size: var(--fs-sm); color: var(--text-2); display: flex; flex-direction: column; gap: 2px; text-align: left; }
.d-fix b { color: var(--text); font-size: var(--fs-xs); font-weight: 600; }
.d-meta { font-size: 11px; color: var(--text-3); font-family: var(--mono); }
.d-actions { display: flex; margin: 10px -16px 0; border-top: 0.5px solid var(--line-strong); }
.d-actions .btn { flex: 1; min-height: 38px; border-radius: 0; background: transparent; color: var(--link); font-size: var(--fs-lg); font-weight: 400; }
.d-actions .btn + .btn { border-left: 0.5px solid var(--line-strong); }
.d-actions .btn-primary, .d-actions .btn:last-child { font-weight: 600; }
.d-actions .btn-danger { color: var(--danger); }
.d-actions .btn:hover { background: var(--fill-2); }
.toast-host { position: fixed; left: 50%; bottom: calc(var(--s6) + var(--tabbar-h) + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: var(--s2); align-items: center; pointer-events: none; }
@media (min-width: 901px) { .toast-host { bottom: calc(var(--s8) + env(safe-area-inset-bottom)); } }
.toast { display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 10px; border-radius: var(--r-pill); background: var(--material); color: var(--text);
  font-weight: 600; font-size: var(--fs); box-shadow: var(--shadow-3); animation: rise var(--t-slow) var(--ease-spring);
  -webkit-backdrop-filter: blur(30px) saturate(1.8); backdrop-filter: blur(30px) saturate(1.8); }
.toast .ok { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--ok); color: #fff; animation: pop var(--t) var(--ease-spring) var(--t-fast) backwards; }
.toast .ok path, .m-check path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: m-draw var(--t-slow) var(--ease-out) var(--t) forwards; }
.toast.leaving, .m-leave { animation: sink var(--t-exit) var(--ease) forwards; pointer-events: none; }
.dialog-backdrop.m-leave { animation: fade var(--t-exit) var(--ease) reverse forwards; pointer-events: none; }
.dialog-backdrop.m-leave .dialog { animation: alert-out var(--t-exit) var(--ease) forwards; }
.m-new { animation: m-flash calc(var(--t-ambient) * 0.6) var(--ease-out); }

/* 진행 막대(UIProgressView) */
.progress { height: 4px; border-radius: 99px; background: var(--fill); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 100%; background: var(--text); transform-origin: left center; transform: scaleX(var(--p, 0)); transition: transform var(--t-slow) var(--ease-out); }
.progress.indeterminate > i { width: 40%; animation: indet 1.2s var(--ease) infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

/* ───── 틀(iPadOS 사이드바 · 반투명 도구막대 · 폰 탭 막대) ───── */
.demo-band { display: flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 26px; padding: 3px var(--s4); background: var(--warn-soft); color: var(--warn-text); font-size: var(--fs-xs); font-weight: 600; }
.demo-band .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--warn); animation: m-breathe calc(var(--t-ambient) * 1.5) ease-in-out var(--m-loop); }
.db-short { display: none; }
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--s3); padding: var(--s3) var(--s3) var(--s4); background: var(--sidebar-bg); border-right: 0.5px solid var(--line); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: var(--s3) var(--s3) var(--s2); font-family: var(--font-display); font-weight: 700; font-size: var(--fs-xl); letter-spacing: -0.03em; }
.brand small { display: block; font-size: var(--fs-xs); font-weight: 400; color: var(--text-2); letter-spacing: 0; font-family: var(--font); }
.logo { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; background: #1d1d1f; flex: none; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a { display: flex; align-items: center; gap: 10px; min-height: 32px; padding: 0 10px; border-radius: 7px; color: var(--text); font-size: var(--fs-md); font-weight: 400; position: relative; transition: background var(--t-fast), color var(--t-fast); }
.nav a svg { color: var(--text-2); width: 17px; height: 17px; flex: none; }
.nav a:hover { background: var(--fill-2); }
.nav a[aria-current="page"] { background: var(--select); color: var(--text); font-weight: 600; }
.nav a[aria-current="page"] svg { color: var(--text); }
.nav .badge { margin-left: auto; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; display: grid; place-items: center; background: var(--fill); color: var(--text-2); font-size: var(--fs-sm); }
.nav a[aria-current="page"] .badge { background: var(--surface); color: var(--text); }
.nav-sep { height: 0; margin: var(--s2) 12px; border-top: 0.5px solid var(--line); }
.side .cta { margin: 0 2px var(--s1); min-height: 32px; font-size: var(--fs); border-radius: var(--r); }
.me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: var(--s3) var(--s2) 0; border-top: 0.5px solid var(--line); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(180deg, #a5abb8, #858a94); color: #fff; font-size: var(--fs-sm); font-weight: 600; flex: none; }
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.who b { font-size: var(--fs); font-weight: 600; }
.who span { font-size: var(--fs-xs); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: var(--s3); min-height: var(--header-h); padding: 6px var(--s8); background: var(--material); border-bottom: 0.5px solid var(--line); }
:root[data-blur="on"] .topbar, .topbar { -webkit-backdrop-filter: blur(24px) saturate(1.8); backdrop-filter: blur(24px) saturate(1.8); }
.topbar h1 { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.03em; }
.topbar .crumb { color: var(--text-2); font-size: var(--fs); }
.topbar .help-btn { color: var(--text-2); }
.menu-btn { display: none; }
.content { padding: var(--s5) var(--s8) var(--s10); max-width: 1760px; width: 100%; }
.page-enter { animation: pageIn var(--t-slow) var(--ease-out); }
@keyframes pageIn { from { opacity: 0; transform: translateY(4px); } }
.tabbar { display: none; }

@media (max-width: 1024px) and (min-width: 901px) { :root { --sidebar-w: 240px; } .content { padding: var(--s4) var(--s6) var(--s10); } .topbar { padding: 6px var(--s6); } }
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; z-index: 60; inset: 0 auto 0 0; width: min(300px, 86vw); transform: translateX(-100%); transition: transform var(--t-slow) var(--ease-out); box-shadow: var(--shadow-3); background: var(--bg); }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; color: var(--text); }
  .topbar { padding: 6px var(--s4); }
  .topbar h1 { font-size: var(--fs-lg); font-weight: 600; }
  .content { padding: var(--s4) var(--s4) calc(var(--tabbar-h) + var(--s8) + env(safe-area-inset-bottom)); }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--material); border-top: 0.5px solid var(--line); -webkit-backdrop-filter: blur(24px) saturate(1.8); backdrop-filter: blur(24px) saturate(1.8); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: #8e8e93; font-size: 10px; font-weight: 500; transition: color var(--t-fast); }
  .tabbar a[aria-current="page"] { color: var(--text); }
  .tabbar a.fab { color: var(--text); }
  .tabbar a.fab span.ring { width: 44px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--accent); color: var(--accent-fg); }
  .db-long { display: none; } .db-short { display: inline; }
}

/* ───── 로그인 ───── */
.auth { display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.auth-art { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; gap: var(--s8); padding: var(--s10); background: #000; color: #fff; }
.auth-art .brand { color: #fff; padding: 0; }
.auth-art h1 { font-size: clamp(32px, 3.6vw, 48px); font-weight: 700; letter-spacing: -0.04em; line-height: 1.08; }
.auth-art p { color: rgb(235 235 245 / 0.6); max-width: 30em; margin-top: var(--s4); font-size: var(--fs-md); }
.auth-art .legend { display: flex; gap: var(--s4); font-size: var(--fs-xs); color: rgb(235 235 245 / 0.55); }
.auth-art .legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.auth-main { display: grid; place-items: center; padding: var(--s8) var(--s5); background: var(--bg); }
.auth-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: var(--s5); }
.auth-card h2 { font-size: var(--fs-3xl); font-weight: 700; letter-spacing: -0.035em; }
.auth-card form { display: flex; flex-direction: column; gap: var(--s4); }
.pw-wrap { position: relative; }
.pw-wrap .pw-toggle { position: absolute; right: 4px; top: 5px; }
@media (max-width: 900px) { .auth { grid-template-columns: 1fr; } .auth-art { min-height: 280px; padding: var(--s6) var(--s5); } .auth-art .art-host { display: none; } }

/* ───── 모션 공통 키프레임 ───── */
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes alert-in { from { opacity: 0; transform: scale(1.12); } }
@keyframes alert-out { to { opacity: 0; transform: scale(0.96); } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@keyframes sink { to { opacity: 0; transform: translateY(8px); } }
@keyframes m-shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes m-breathe { 50% { opacity: 0.35; } }
@keyframes m-flash { from { box-shadow: 0 0 0 3px var(--accent-soft); } }
@keyframes m-grow-x { from { transform: scaleX(0); } }
@keyframes m-grow-y { from { transform: scaleY(0); } }
@keyframes m-draw { to { stroke-dashoffset: 0; } }
@keyframes m-ring { 0% { transform: scale(0.9); opacity: 0.9; } 70%, 100% { transform: scale(1.6); opacity: 0; } }
.m-stagger > * { animation: rise var(--t-slow) var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * var(--stagger)); }

/* 움직임 정도(설정 ui.motion_level) · OS 움직임 줄이기 */
:root[data-motion="calm"] { --m-loop: 3; }
:root[data-motion="off"] *, :root[data-motion="off"] *::before, :root[data-motion="off"] *::after { animation-duration: 0.001ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
:root[data-motion="off"] :is(.btn .spin, .spinner) { animation-duration: 0.8s !important; animation-iteration-count: infinite !important; }
:root[data-motion="off"] .progress.indeterminate > i { animation-duration: 1.2s !important; animation-iteration-count: infinite !important; }
:root[data-blur="off"] :is(.topbar, .tabbar, .dialog, .toast) { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--surface); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
@media print { .side, .topbar, .tabbar, .demo-band, .no-print { display: none !important; } .shell { display: block; } .content { padding: 0; } body { background: #fff; } }
