:root {
  --bg: #f4f6f9;
  --card: #fff;
  --text: #1a1d21;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --tag-measured: #059669;
  --tag-estimated: #d97706;
  --tag-unknown: #6b7280;
  --pad: 1rem;
  --topbar-h: auto;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.65rem var(--pad) 0;
}

.topbar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  min-height: 2.5rem;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.user-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  min-width: 0;
  white-space: nowrap;
}

.user-area .muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 9rem;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.55rem 0 0.65rem;
}

.nav a {
  flex: 0 0 auto;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.82rem;
  border: 1px solid var(--border);
  background: #fff;
  white-space: nowrap;
}

.nav a.active,
.nav a:hover {
  color: var(--primary);
  background: #eff6ff;
  border-color: #bfdbfe;
}

.muted {
  color: var(--muted);
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--pad);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.card.scroll {
  padding: 0;
  overflow: hidden;
}

.card.scroll .table-wrap {
  padding: 0;
}

h1 {
  font-size: clamp(1.15rem, 4vw, 1.35rem);
  margin: 0 0 0.75rem;
  word-break: keep-all;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 0.5rem;
  word-break: keep-all;
}

/* Tables: desktop = table, mobile = stacked cards */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

table.data th,
table.data td {
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 0.45rem;
  text-align: left;
  vertical-align: middle;
}

table.data th {
  background: #f9fafb;
  font-weight: 600;
  white-space: nowrap;
}

table.data.detail th {
  width: 38%;
  max-width: 10rem;
}

table.data.detail td {
  word-break: break-word;
}

.tag {
  display: inline-block;
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  margin-left: 0.25rem;
  vertical-align: middle;
  font-weight: 600;
  white-space: nowrap;
}

.tag-measured {
  background: #d1fae5;
  color: var(--tag-measured);
}

.tag-estimated {
  background: #fef3c7;
  color: var(--tag-estimated);
}

.tag-unknown {
  background: #f3f4f6;
  color: var(--tag-unknown);
}

.money {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0.25rem;
  word-break: keep-all;
}

.money .hint {
  display: block;
  width: 100%;
  font-size: 0.7rem;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.stat {
  background: #f9fafb;
  border-radius: 8px;
  padding: 0.75rem;
  min-width: 0;
}

.stat .value {
  font-size: clamp(1rem, 4.5vw, 1.35rem);
  font-weight: 700;
  word-break: break-word;
}

.stat .label {
  color: var(--muted);
  font-size: 0.75rem;
}

form.stack label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
}

form.stack input,
form.stack select,
.cost-form input {
  display: block;
  width: 100%;
  max-width: 100%;
  margin-top: 0.25rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 1rem; /* avoid iOS zoom */
}

button,
.btn {
  display: inline-block;
  padding: 0.55rem 0.95rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}

button:hover,
.btn:hover {
  background: var(--primary-hover);
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  padding: 0.25rem;
  white-space: nowrap;
}

.inline {
  display: inline;
}

.cost-form {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: 100%;
}

.cost-form button {
  width: 100%;
}

.flash {
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.flash.ok {
  background: #ecfdf5;
  color: #065f46;
}

.flash.error {
  background: #fef2f2;
  color: #991b1b;
}

.login-wrap {
  width: 100%;
  max-width: 360px;
  margin: 1.5rem auto;
  padding: 0;
}

.login-wrap .card {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.toolbar label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  width: 100%;
  max-width: 220px;
}

.toolbar select {
  width: 100%;
  padding: 0.5rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 1rem;
  background: #fff;
}

/* —— Phone only: stacked data cards. Tablet+ uses scrollable table —— */
@media (max-width: 639px) {
  table.data.responsive thead {
    display: none;
  }

  table.data.responsive,
  table.data.responsive tbody,
  table.data.responsive tr,
  table.data.responsive td {
    display: block;
    width: 100%;
  }

  table.data.responsive tr {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 0.85rem;
    margin-bottom: 0.75rem;
  }

  table.data.responsive td {
    border: none;
    border-bottom: 1px solid #f3f4f6;
    padding: 0.45rem 0;
    display: grid;
    grid-template-columns: minmax(5.5rem, 34%) 1fr;
    gap: 0.5rem;
    align-items: center;
  }

  table.data.responsive td:last-child {
    border-bottom: none;
  }

  table.data.responsive td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--muted);
    padding-top: 0.15rem;
  }

  table.data.responsive td[data-label=''] {
    grid-template-columns: 1fr;
  }

  .card > table.data.responsive,
  .table-wrap > table.data.responsive {
    border: none;
  }

  .card:has(> table.data.responsive) {
    background: transparent;
    border: none;
    padding: 0;
  }
}

@media (min-width: 640px) {
  :root {
    --pad: 1.25rem;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .user-area .muted {
    max-width: 14rem;
  }

  .cost-form {
    flex-direction: row;
    align-items: stretch;
  }

  .cost-form input {
    flex: 1;
    margin-top: 0;
  }

  .cost-form button {
    width: auto;
    flex-shrink: 0;
  }

  .login-wrap {
    margin: 3rem auto;
  }

  /* Tablet: keep table, allow horizontal scroll without breaking page */
  .card:has(> table.data.responsive) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table.data.responsive {
    min-width: 720px;
  }

  table.data.responsive th:nth-child(1),
  table.data.responsive td:nth-child(1),
  table.data.responsive th:nth-child(2),
  table.data.responsive td:nth-child(2) {
    position: sticky;
    left: 0;
    background: #fff;
    z-index: 1;
  }

  table.data.responsive th:nth-child(1),
  table.data.responsive th:nth-child(2) {
    background: #f9fafb;
    z-index: 2;
  }

  table.data.responsive td:nth-child(1) {
    left: 0;
  }

  table.data.responsive th:nth-child(2),
  table.data.responsive td:nth-child(2) {
    left: 4.5rem;
  }
}

@media (min-width: 900px) {
  .stats {
    grid-template-columns: repeat(4, 1fr);
  }

  .topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1.25rem;
    padding: 0.7rem var(--pad);
  }

  .topbar-row {
    flex: 0 0 auto;
  }

  .nav {
    flex: 1 1 auto;
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  .nav a {
    border-radius: 6px;
    border-color: transparent;
    background: transparent;
  }

  .nav a.active,
  .nav a:hover {
    border-color: transparent;
  }

  .user-area {
    margin-left: auto;
  }

  form.stack input,
  form.stack select {
    max-width: 320px;
  }

  table.data.responsive {
    min-width: 0;
  }

  table.data.responsive th:nth-child(1),
  table.data.responsive td:nth-child(1),
  table.data.responsive th:nth-child(2),
  table.data.responsive td:nth-child(2) {
    position: static;
  }
}

@media (min-width: 1100px) {
  table.data tr:hover td {
    background: #fafbff;
  }
}

/* Frosted workspace: keep data surfaces bright and text fully opaque. */
:root {
  --bg: #edf3fb;
  --card: rgba(255, 255, 255, 0.78);
  --text: #17243b;
  --muted: #53647d;
  --border: rgba(118, 145, 182, 0.22);
  --primary: #235ed8;
  --primary-hover: #174cb8;
  --pad: clamp(1rem, 3vw, 2rem);
  --glass-shadow: 0 18px 48px rgba(47, 75, 125, 0.09), 0 2px 8px rgba(47, 75, 125, 0.04);
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 4%, rgba(151, 195, 255, 0.48), transparent 30rem),
    radial-gradient(circle at 96% 18%, rgba(188, 177, 255, 0.36), transparent 27rem),
    radial-gradient(circle at 52% 94%, rgba(153, 230, 218, 0.25), transparent 32rem),
    #edf3fb;
  background-attachment: fixed;
}

a, button, input, select { transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease, transform 160ms ease; }
:focus-visible { outline: 3px solid rgba(35, 94, 216, 0.42); outline-offset: 2px; }

.topbar {
  background: rgba(246, 250, 255, 0.78);
  border-bottom: 1px solid rgba(255, 255, 255, 0.84);
  box-shadow: 0 8px 30px rgba(42, 72, 124, 0.07);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.topbar-row { min-width: 0; }
.brand { display: inline-flex; align-items: center; gap: 0.7rem; }
.brand-mark {
  display: block;
  width: 2.45rem;
  height: 2.45rem;
  flex: none;
  border-radius: 0.85rem;
  box-shadow: 0 7px 18px rgba(47, 88, 190, 0.25);
}
.brand-copy { display: flex; flex-direction: column; line-height: 1.12; }
.brand-copy strong { font-size: 0.99rem; letter-spacing: -0.03em; }
.brand-copy small { margin-top: 0.27rem; color: #6680a8; font-size: 0.59rem; font-weight: 700; letter-spacing: 0.18em; }

.nav a {
  border-color: transparent;
  background: transparent;
  color: #50617c;
  font-weight: 600;
}
.nav a.active, .nav a:hover {
  border-color: rgba(90, 135, 228, 0.2);
  background: rgba(255,255,255,0.72);
  color: #174ba9;
  box-shadow: 0 3px 12px rgba(56, 94, 164, 0.08);
}
.nav a.active { box-shadow: inset 0 -2px #4c77db, 0 3px 12px rgba(56, 94, 164, 0.08); }

.container { max-width: 1320px; padding-top: clamp(1.25rem, 3vw, 2.5rem); padding-bottom: 3rem; }
h1 { font-size: clamp(1.5rem, 3vw, 2.1rem); line-height: 1.2; letter-spacing: -0.045em; }
h2 { color: #1d3151; font-size: 1.06rem; letter-spacing: -0.025em; }
.container > .muted, .container > p.muted { margin-top: -0.2rem; margin-bottom: 1.35rem; }

.card, .stat {
  border: 1px solid rgba(255,255,255,0.8);
  background: var(--card);
  box-shadow: var(--glass-shadow);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.card { border-radius: 1.15rem; padding: clamp(1rem, 2vw, 1.5rem); }
.stat { border-radius: 1rem; padding: 1.05rem 1.2rem; }
.stat .value { margin-bottom: 0.2rem; color: #214ca3; font-size: clamp(1.12rem, 2.3vw, 1.65rem); letter-spacing: -0.04em; }
.stat .label { color: var(--muted); font-weight: 600; }
.stats { gap: 0.85rem; margin-bottom: 1.2rem; }

table.data { font-variant-numeric: tabular-nums; }
table.data th { background: rgba(223, 234, 249, 0.5); color: #4b607e; font-size: 0.78rem; }
table.data td { border-color: rgba(115, 145, 184, 0.16); }
table.data tr:last-child td { border-bottom: 0; }
.tag { border-radius: 999px; padding: 0.17rem 0.5rem; }
.tag-measured { background: #d9f5e9; color: #086949; }
.tag-estimated { background: #fff0cc; color: #8c5105; }
.tag-unknown { background: #e8edf4; color: #495a70; }

button, .btn { border-radius: 0.7rem; background: linear-gradient(135deg, #4179e9, #2757c7); box-shadow: 0 5px 13px rgba(42, 91, 199, 0.18); font-weight: 650; }
button:hover, .btn:hover { background: linear-gradient(135deg, #326cdd, #1f4db7); transform: translateY(-1px); }
.link-btn, .link-btn:hover { background: transparent; box-shadow: none; transform: none; color: var(--primary); }
form.stack input, form.stack select, .cost-form input, .toolbar select {
  border-color: rgba(104, 136, 179, 0.28);
  border-radius: 0.7rem;
  background: rgba(255,255,255,0.86);
  color: var(--text);
}
form.stack input:focus, form.stack select:focus, .cost-form input:focus, .toolbar select:focus { border-color: #5684e5; box-shadow: 0 0 0 3px rgba(70, 120, 225, 0.14); outline: 0; }
.flash { border: 1px solid rgba(255,255,255,0.8); border-radius: 0.8rem; }
.demo-banner { padding: 0.8rem 1rem; border: 1px solid #e8c97b; border-radius: 0.8rem; background: #fff5d8; color: #6b4b0d; font-weight: 650; }
.login-wrap { max-width: 420px; margin-top: clamp(3rem, 10vh, 7rem); }
.login-wrap .card { padding: clamp(1.35rem, 4vw, 2.2rem); box-shadow: 0 25px 65px rgba(48, 76, 127, 0.15); }

@media (max-width: 899px) {
  .nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; -webkit-overflow-scrolling: touch; margin-right: calc(-1 * var(--pad)); padding-right: var(--pad); }
  .nav a { background: rgba(255,255,255,0.48); border-color: rgba(255,255,255,0.65); }
}
@media (max-width: 639px) {
  .topbar { padding-top: 0.55rem; }
  .brand-copy small { font-size: 0.52rem; }
  .user-area { justify-self: end; gap: 0.3rem; }
  .user-area .muted { max-width: 5rem; }
  .user-area .link-btn { padding: 0.25rem 0; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 0.85rem; }
  .stat .value { font-size: clamp(1rem, 4.4vw, 1.25rem); }
  .toolbar label { max-width: none; }
  .card:has(> table.data.responsive) { box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
  table.data.responsive tr { background: rgba(255,255,255,0.82); border-color: rgba(255,255,255,0.85); border-radius: 1rem; box-shadow: var(--glass-shadow); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
  table.data.responsive td { min-width: 0; grid-template-columns: minmax(4.5rem, 32%) minmax(0, 1fr); overflow-wrap: anywhere; }
}
@media (max-width: 360px) {
  .brand-copy small { display: none; }
  .user-area .muted { max-width: 3.7rem; }
  table.data.responsive td { grid-template-columns: minmax(4rem, 30%) minmax(0, 1fr); }
}
@media (min-width: 640px) and (max-width: 899px) {
  table.data.responsive { min-width: 1100px; }
  table.data.responsive th:nth-child(1), table.data.responsive td:nth-child(1),
  table.data.responsive th:nth-child(2), table.data.responsive td:nth-child(2) { position: static; }
}
@media (min-width: 900px) {
  .topbar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; }
  .topbar-row { display: contents; }
  .brand { grid-column: 1; grid-row: 1; }
  .nav { grid-column: 2; grid-row: 1; justify-content: center; }
  .user-area { grid-column: 3; grid-row: 1; }
}
@media (prefers-reduced-motion: reduce) { a, button, input, select { transition: none; } }
