/*
 * [app.css] — 전체 스타일. 외부 프레임워크 없음.
 *
 * 구성: 변수 → 기본 → 헤더/탭 → 현황판 → 카드/폼/모달 → 토스트 → 모바일.
 * 색 규칙: 확정 = 회청색, 대기 = 빗금, 내 예약 = 파랑, 지난 시간 = 흐림. (02-아키텍처.md 8절)
 */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #e3e6ea;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  --confirmed: #cbd5e1;
  --confirmed-text: #334155;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  --row-h: 44px;
  --label-w: 120px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", "Apple SD Gothic Neo", sans-serif; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 16px; }
h3 { font-size: 13px; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .02em; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); }
.note { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.lead { font-size: 15px; font-weight: 500; }
[hidden] { display: none !important; }

/* ---------- 통신 중 표시 ---------- */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 100; background: transparent; }
.progress-bar { height: 100%; width: 30%; background: var(--accent); border-radius: 0 2px 2px 0; animation: progress-slide 1.1s ease-in-out infinite; }
@keyframes progress-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(340%); } }
.btn.busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.busy::after { content: ''; position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px; border: 2px solid rgba(0,0,0,.25); border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; color: var(--text); }
.btn-primary.busy::after, .btn-warn.busy::after { border-color: rgba(255,255,255,.4); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
.board-wrap.loading { opacity: .55; transition: opacity .2s; }
@media (prefers-reduced-motion: reduce) { .progress-bar, .btn.busy::after { animation-duration: 2s; } }

/* ---------- 헤더 ---------- */
.header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.header h1 { font-size: 17px; }
.header .tz { font-size: 12px; color: var(--muted); margin-left: 10px; }
.header-right { display: flex; align-items: center; gap: 10px; }
.tabs { display: flex; gap: 4px; padding: 8px 16px 0; background: var(--surface); border-bottom: 1px solid var(--line); }
.tab { border: 0; background: none; padding: 8px 12px; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-badge { display: inline-block; margin-left: 6px; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #fef3c7; color: #92400e; font-weight: 600; }
.settings { max-width: 720px; display: grid; gap: 14px; }
.settings .card h3 { margin-top: 0; }
.kv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv-table td { padding: 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.kv-table td:first-child { color: var(--muted); width: 45%; }
.check-list { margin: 8px 0 0; padding-left: 18px; }
.check-list .ok { color: var(--ok); }
.check-list .bad { color: var(--danger); }
.view { padding: 14px 16px 40px; }
.banner { background: #fef3c7; color: #92400e; padding: 6px 16px; font-size: 13px; text-align: center; }

/* ---------- 로그인 ---------- */
.login { max-width: 420px; margin: 60px auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; text-align: center; }
.login h2 { margin-bottom: 8px; }
.login .btn-block { margin-top: 8px; }
#login-button { display: flex; flex-direction: column; align-items: center; margin-top: 16px; }

/* ---------- 버튼/입력 ---------- */
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 12px; font-size: 14px; cursor: pointer; }
.btn:hover { background: #f3f4f6; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { display: block; width: 100%; text-align: left; }
.btn-alt { display: block; width: 100%; text-align: left; margin-bottom: 6px; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; width: 32px; height: 32px; font-size: 18px; line-height: 1; cursor: pointer; }
.seg { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; cursor: pointer; font-size: 13px; }
.seg:first-of-type { border-radius: 8px 0 0 8px; }
.seg + .seg { border-left: 0; border-radius: 0 8px 8px 0; }
.seg.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.input, .select, .date-input { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 14px; background: var(--surface); color: var(--text); width: 100%; font-family: inherit; }
.date-input { width: auto; }
.select { width: auto; min-width: 90px; }
.field { display: block; margin-bottom: 10px; }
.field-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field .select { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 10px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
details.optional { border: 1px dashed var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; }
details.optional summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-bottom: 6px; }

/* ---------- 툴바 ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.toolbar-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.toolbar-label { font-weight: 600; margin-left: 6px; }

/* ---------- 현황판 ---------- */
.board-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; padding-bottom: 6px; }
.grid { display: inline-block; min-width: 100%; }
.row { display: flex; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-label { flex: 0 0 var(--label-w); position: sticky; left: 0; background: var(--surface); z-index: 2; padding: 6px 10px; border-right: 1px solid var(--line); min-height: var(--row-h); display: flex; flex-direction: column; justify-content: center; }
.row-label-head { min-height: 28px; font-weight: 600; }
.row-label.is-today .row-name { color: var(--accent); }
.row-name { font-weight: 600; }
.row-sub { font-size: 11px; color: var(--muted); }
.track { position: relative; height: var(--row-h); flex: 0 0 auto; background: repeating-linear-gradient(to right, transparent 0, transparent 25px, #f1f3f5 25px, #f1f3f5 26px); cursor: crosshair; }
.track-head { height: 28px; background: none; cursor: default; }
.hour-label { position: absolute; top: 6px; font-size: 11px; color: var(--muted); padding-left: 4px; border-left: 1px solid var(--line); height: 16px; }
.hour-line { position: absolute; top: 0; bottom: 0; width: 1px; background: #dfe3e8; pointer-events: none; }
.past-shade { position: absolute; top: 0; bottom: 0; left: 0; background: rgba(0,0,0,.035); pointer-events: none; }
.event { position: absolute; top: 5px; height: calc(var(--row-h) - 10px); background: var(--confirmed); color: var(--confirmed-text); border-radius: 6px; padding: 0 6px; display: flex; align-items: center; overflow: hidden; white-space: nowrap; font-size: 12px; cursor: pointer; border: 1px solid rgba(0,0,0,.06); }
.event:hover { filter: brightness(.96); }
.event.mine { background: var(--accent); color: #fff; border-color: transparent; }
.event.pending { background: repeating-linear-gradient(135deg, #fde68a 0, #fde68a 6px, #fef3c7 6px, #fef3c7 12px); color: #78350f; }
.event.pending.mine { background: repeating-linear-gradient(135deg, #93c5fd 0, #93c5fd 6px, #dbeafe 6px, #dbeafe 12px); color: #1e3a8a; }
.event.preempt { background: none; border: 2px dashed var(--warn); color: var(--warn); top: 2px; height: calc(var(--row-h) - 4px); z-index: 1; }
.event.warning { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.event.past { opacity: .55; }
.event-title { overflow: hidden; text-overflow: ellipsis; }
.legend { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 10px 12px 4px; font-size: 12px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-hint { margin-left: auto; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; }
.swatch-confirmed { background: var(--confirmed); }
.swatch-pending { background: repeating-linear-gradient(135deg, #fde68a 0, #fde68a 4px, #fef3c7 4px, #fef3c7 8px); }
.swatch-mine { background: var(--accent); }

/* ---------- 카드 ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.card-escalated { border-color: #fcd34d; background: #fffbeb; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.card-title { font-size: 15px; font-weight: 600; margin: 2px 0; }
.kv { margin: 4px 0; }
.list { margin: 4px 0 0; padding-left: 18px; }
.badge { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px; background: #eef0f3; color: var(--muted); }
.badge-ok { background: #d1fae5; color: #065f46; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-type { background: var(--accent-soft); color: var(--accent); }
.grade-top { background: #fee2e2; color: #991b1b; font-weight: 600; }
.grade-high { background: #ffedd5; color: #9a3412; font-weight: 600; }
.grade-low { background: #eef0f3; color: var(--muted); }

/* ---------- 모달 ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 460px; max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-wide { max-width: 560px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px 8px; }
.modal-body { padding: 4px 18px 18px; }
body.modal-open { overflow: hidden; }
.section { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }

.footer { text-align: center; font-size: 12px; color: var(--muted); padding: 20px 16px 30px; }
.footer a { color: var(--muted); }

/* ---------- 토스트 ---------- */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transform: translateY(8px); transition: all .25s; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: none; }
.toast-ok { background: var(--ok); }
.toast-error { background: var(--danger); }

/* ---------- 모바일 ---------- */
@media (max-width: 640px) {
  :root { --label-w: 84px; }
  .header .tz { display: none; }
  .view { padding: 10px; }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .toolbar-label { width: 100%; margin-left: 0; }
  .legend-hint { margin-left: 0; width: 100%; }
}
