:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --border: #e5e0d8;
  --text: #1a1a1a;
  --text-muted: #6b6560;
  --accent: #2d5a3d;
  --accent-light: #e8f0eb;
  --danger: #c0392b;
  --danger-light: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
  --font: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.header-actions {
  display: flex;
  gap: .5rem;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.header-actions form,
.header-actions .btn,
.header-actions button {
  width: auto;
  margin: 0;
}
.header-import input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.header-import label {
  position: relative;
  display: inline-flex;
  margin: 0;
  width: auto;
}
.banner {
  margin: 0 0 1rem;
  padding: .75rem 1rem;
  border-radius: 8px;
  font-size: .875rem;
}
.banner.success {
  background: var(--accent-light);
  color: var(--accent);
}
.banner.error {
  background: var(--danger-light);
  color: var(--danger);
}
.stats-badge {
  font-size: .8rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: .3rem .75rem;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  overflow-x: auto;
}
.tab-btn {
  padding: .85rem 1.25rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-family: inherit;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.main-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem;
}
.main-content.wide { max-width: 1480px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 1.25rem; }
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
}
.card-body { padding: 1.25rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: .875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  background: transparent;
  color: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #234a32; }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg); }
.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
  border-color: #f5c6c2;
}
.btn-danger:hover { background: #f9d5d2; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group.full { grid-column: 1 / -1; }
.form-group label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .875rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.form-hint, .muted {
  font-size: .75rem;
  color: var(--text-muted);
}
.error { color: var(--danger); font-size: .875rem; margin-bottom: .75rem; }

.form-actions {
  margin-top: 1.25rem;
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  cursor: pointer;
  position: relative;
  min-height: 140px;
  display: grid;
  place-items: center;
  background: var(--bg);
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.dropzone-content {
  text-align: center;
  color: var(--text-muted);
  font-size: .875rem;
  pointer-events: none;
}
.dropzone-preview {
  pointer-events: none;
}
.dropzone-preview img,
.preview {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #eee;
}

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
table.data thead th {
  background: var(--bg);
  padding: .65rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: .8rem;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data tbody td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover td { background: #faf9f7; }
table.data td.num, table.data th.num { text-align: center; }
table.data td.nowrap, table.data th.nowrap { white-space: nowrap; }

.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: .85rem;
  color: var(--text-muted);
}
.measure-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}
.tag-gray {
  background: #f0eeeb;
  color: var(--text-muted);
}
.cell-sub {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: .15rem;
}
.col-actions { text-align: right; width: 1%; white-space: nowrap; }
table.data thead th.col-actions,
table.data tbody td.col-actions {
  position: sticky;
  right: 0;
  background: var(--surface);
  box-shadow: -8px 0 8px rgba(0,0,0,.04);
}
table.data thead th.col-actions { background: var(--bg); }
table.data tbody tr:hover td.col-actions { background: #faf9f7; }
.row-actions.stacked {
  flex-direction: column;
  align-items: flex-end;
  gap: .35rem;
}

.thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
}

.tag {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 4px;
  font-size: .75rem;
  font-weight: 500;
  background: var(--accent-light);
  color: var(--accent);
}
.row-actions {
  display: flex;
  gap: .4rem;
  align-items: center;
}
.row-actions form { margin: 0; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.auth .card { width: min(420px, 92vw); }
.auth h1 {
  font-size: 1.15rem;
  color: var(--accent);
}

@media (max-width: 700px) {
  .app-header, .tabs, .main-content { padding-left: 1rem; padding-right: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
}
