/* ─────────────────────────────────────────────────────────────
   노스팜CC 식음 — 공통 디자인 시스템
   styles.css 다음에 로드되어 전 화면의 톤을 통일한다.

   방향
   - 반투명·블러(글래스)와 그라디언트를 걷어내고 불투명 면 + 1px 헤어라인
   - 헤더는 4단 스택에서 한 줄로 (로고 260px -> 심볼 28px)
   - 숫자는 tabular-nums 로 자릿수 정렬

   custom-button 은 섀도우 DOM 안에서 styles.css 와 이 파일을 함께 읽는다.
   (Button.js 참고) 그래서 여기 버튼 규칙이 커스텀 버튼에도 적용된다.
   ───────────────────────────────────────────────────────────── */

/* ── 토큰 재정의 ─────────────────────────────────────────── */
:root {
  color-scheme: light;

  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f6f7f9;

  --text: #12151a;
  --muted: #6b7280;
  --faint: #9aa1ac;

  --accent: #3b5bdb;
  --accent-rgb: 59, 91, 219;
  --accent-soft: #eef2ff;

  --line: #e6e8ec;
  --line-soft: #eef0f3;
  --line-strong: #d7dbe1;

  --success: #0f7b52;
  --danger: #c02638;
  --warn: #b45309;

  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-2: 0 4px 14px rgba(16, 24, 40, 0.07);

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;

  --layout-max: 1440px;
  --glass-blur: none;
  --header-h: 54px;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0d1014;
  --surface: #171a21;
  --surface-2: #1f232b;

  --text: #e9edf3;
  --muted: #98a1ae;
  --faint: #6b7480;

  --accent: #7c8cff;
  --accent-rgb: 124, 140, 255;
  --accent-soft: #232941;

  --line: #2b303a;
  --line-soft: #23272f;
  --line-strong: #3a414d;

  --success: #34d399;
  --danger: #fb7185;
  --warn: #fbbf24;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 6px 18px rgba(0, 0, 0, 0.45);
}

body {
  background: var(--bg);
  color: var(--text);
}

/* ── 헤더: 4단 스택 -> 한 줄 ──────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 60;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  min-height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  display: block;
}

.app-header-inner {
  width: min(100%, var(--layout-max));
  margin-inline: auto;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.app-header .brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text);
  flex: 0 0 auto;
}

.app-header .brand-logo {
  height: 26px;
  width: auto;
  max-width: 48px;
  object-fit: contain;
  display: block;
}

.app-header .brand-title {
  font-size: 0.94rem;
  font-weight: 680;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.app-header .kicker {
  margin: 0;
  font-size: 0.63rem;
  font-weight: 620;
  letter-spacing: 0.1em;
  color: var(--faint);
  text-transform: uppercase;
  white-space: nowrap;
  padding-left: 9px;
  border-left: 1px solid var(--line);
}

/* 주 메뉴 */
.app-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.app-nav::-webkit-scrollbar { display: none; }

.app-nav a {
  font-size: 0.83rem;
  font-weight: 560;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 11px;
  border-radius: 7px;
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}

.app-nav a:hover {
  color: var(--text);
  background: var(--surface-2);
}

.app-nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 640;
}

.app-header .actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: auto;
}

/* 세션 타이머 */
.app-header .session-timer {
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 9px;
  background: var(--surface-2);
}

.app-header .session-timer.is-warning {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--line));
}

/* 사용자 메뉴 */
.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 560;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 10px;
  cursor: pointer;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-trigger:hover { background: var(--surface-2); }

.user-menu-dropdown {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  backdrop-filter: none;
}

.user-menu-item {
  font-size: 0.82rem;
  color: var(--text);
  background: transparent;
  border: 0;
  padding: 9px 12px;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.user-menu-item:hover { background: var(--surface-2); }
.user-menu-item.is-danger { color: var(--danger); }

/* 승인 요청이 없을 때 빈 칩이 헤더에 남지 않도록 */
.request-status:empty { display: none; }

.request-status {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px 9px;
}

.request-status.status-approved {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 35%, var(--line));
}

.request-status.status-denied {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
}

.store-selector {
  font-size: 0.8rem;
  padding: 6px 10px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  max-width: 180px;
}

/* ── 본문 레이아웃 ───────────────────────────────────────── */
main {
  width: min(100%, var(--layout-max));
  margin-inline: auto;
  margin-top: 18px;
  gap: 14px;
}

.app-footer {
  width: min(100%, var(--layout-max));
  margin-inline: auto;
  padding: 22px 20px 40px;
  color: var(--faint);
  font-size: 0.76rem;
}

.app-footer a { color: var(--muted); }

/* ── 페이지 제목 ─────────────────────────────────────────── */
.page-head {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin-bottom: -2px;
}

.page-head h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 660;
  letter-spacing: -0.025em;
  color: var(--text);
}

.page-sub {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ── 로그인 ──────────────────────────────────────────────── */
.login-head {
  display: grid;
  gap: 10px;
  justify-items: center;
  text-align: center;
  padding-bottom: 6px;
}

.login-head .brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text);
}

.login-head .brand-logo {
  height: 30px;
  width: auto;
  object-fit: contain;
}

.login-head .brand-title {
  font-size: 0.95rem;
  font-weight: 680;
  letter-spacing: -0.02em;
}

.login-head h1 {
  margin: 2px 0 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.login-head .actions { justify-content: center; }

/* ── 카드 ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.card h2,
.card h3 {
  letter-spacing: -0.015em;
}

/* ── 폼 컨트롤 ───────────────────────────────────────────── */
input,
select,
textarea {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  padding: 8px 10px;
  backdrop-filter: none;
}

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

label {
  font-size: 0.78rem;
  font-weight: 560;
  color: var(--muted);
}

/* ── 버튼 (섀도우 DOM 안의 custom-button 에도 적용된다) ────── */
button {
  font: inherit;
  font-size: 0.83rem;
  font-weight: 570;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 13px;
  cursor: pointer;
  line-height: 1.25;
  white-space: nowrap;
  box-shadow: none;
  text-shadow: none;
  transition: background 0.12s ease, border-color 0.12s ease;
}

button:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--line-strong);
  transform: none;
  box-shadow: none;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* variant 별 채색은 custom-button 의 섀도우 DOM 안에서만 적용한다.
   :host 는 섀도우 안에서만 매칭되므로, 일반 페이지의 <button>(사용자 메뉴,
   필터 버튼 등)이 파란 주 버튼으로 칠해지는 일이 없다.
   (button:not(.secondary):not(.danger) 는 특정도가 0,2,1 이라
    .user-menu-trigger 같은 단일 클래스 규칙을 이겨버렸다) */
:host button:not(.secondary):not(.danger) {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

:host button:not(.secondary):not(.danger):hover:not(:disabled) {
  background: var(--accent);
  filter: brightness(1.08);
}

:host button.secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

:host button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

:host button.danger:hover:not(:disabled) {
  background: var(--danger);
  filter: brightness(1.08);
}

custom-button.compact button,
custom-button.mini button {
  padding: 6px 11px;
  font-size: 0.8rem;
}

/* 섀도우 DOM 밖의 주 동작 버튼 (모바일 저장 바 등) */
.mobile-save-btn,
button.is-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 620;
}

.mobile-save-btn:hover:not(:disabled),
button.is-primary:hover:not(:disabled) {
  background: var(--accent);
  filter: brightness(1.08);
}

/* 등록 화면 모드 토글 */
.sales-mode-btn.is-active {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
  color: var(--accent);
  font-weight: 630;
}

.link-button {
  font-size: 0.82rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 11px;
  text-decoration: none;
}

.link-button:hover {
  color: var(--text);
  background: var(--surface-2);
}

/* ── 표 ──────────────────────────────────────────────────── */
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.83rem;
}

thead th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 620;
  letter-spacing: 0.02em;
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--text);
}

td.right,
th.right { text-align: right; }

/* 금액·수치는 자릿수를 맞춘다 */
td.right,
.dv-num,
.summary-card strong,
.session-timer { font-variant-numeric: tabular-nums; }

/* ── 다이얼로그 ──────────────────────────────────────────── */
dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-2);
  padding: 0;
  backdrop-filter: none;
}

dialog::backdrop {
  background: rgba(16, 24, 40, 0.42);
  backdrop-filter: none;
}

.dialog-form {
  padding: 20px 22px 22px;
  min-width: min(92vw, 420px);
}

.dialog-form h3 {
  margin: 0 0 4px;
  font-size: 1.02rem;
  font-weight: 650;
  letter-spacing: -0.015em;
}

/* ── 하단 탭바 (PWA) ─────────────────────────────────────── */
.app-tab-bar {
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: none;
  backdrop-filter: none;
}

.tab-item { color: var(--faint); }

.tab-item.active {
  color: var(--accent);
  background: transparent;
}

.tab-item.active svg { stroke: var(--accent); }

/* ── 반응형 ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-header .kicker { display: none; }
}

@media (max-width: 720px) {
  .app-header-inner {
    padding: 8px 12px;
    gap: 10px;
  }
  .app-header .brand-title { font-size: 0.88rem; }
  .app-nav { order: 3; width: 100%; }
  .app-header .actions { margin-left: auto; }
  .user-menu-trigger { max-width: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
