/* ========== Design tokens ========== */
:root {
  --bg: #f3f1ec;
  --bg-2: #ebe8e1;
  --bg-3: #efece4;
  --text: #1a1a1a;
  --text-mute: #6a6a6a;
  --text-dim: #999;
  --line: #d8d4cb;
  --line-2: #c4c0b7;
  --accent: #c4a052;
  --danger: #c04040;
  --success: #4a8c5a;
  --rod-1: #8a8378;
  --rod-2: #5c554a;
  --serif: "Times New Roman", "ヒラギノ明朝 ProN", "Hiragino Mincho ProN", serif;
  --sans: -apple-system, "Hiragino Sans", "Noto Sans JP", "Helvetica Neue", sans-serif;

  --hanger-w: 96px;
  --hanger-gap: 6px;
  --rack-pad: 14px;
  --topbar-h: 48px;
  --row-h: calc((100vh - var(--topbar-h) - 132px) / 3);
}
@media (min-width: 768px) {
  :root {
    --hanger-w: 116px;
    --hanger-gap: 10px;
    --rack-pad: 24px;
    --topbar-h: 56px;
  }
}
@media (min-width: 1280px) {
  :root {
    --hanger-w: 132px;
    --hanger-gap: 14px;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ========== Topbar ========== */
.topbar {
  height: var(--topbar-h);
  padding: 0 var(--rack-pad);
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  position: sticky; top: 0; z-index: 20;
}
.brand {
  font-family: var(--serif);
  font-size: 16px;
  letter-spacing: 0.18em;
}
@media (min-width: 768px) { .brand { font-size: 19px; letter-spacing: 0.22em; } }
.topbar-nav { display: flex; align-items: center; gap: 6px; }
.nav-link {
  padding: 6px 8px; font-size: 12px; color: var(--text-mute);
  border-bottom: 2px solid transparent;
}
.nav-link:hover { color: var(--text); }
.nav-link.primary { color: var(--text); font-weight: 600; }
.nav-btn {
  background: none; border: 1px solid var(--line-2);
  padding: 5px 10px; font-size: 11px; color: var(--text-mute);
  border-radius: 999px;
}
.nav-btn:hover { background: #fff; color: var(--text); }
.user { font-size: 11px; color: var(--text-dim); padding: 0 4px; }
.inline { display: inline; }

@media (max-width: 480px) {
  .nav-link { padding: 6px 6px; font-size: 11px; }
  .user { display: none; }
}

/* ========== Flash ========== */
.flash-stack { padding: 8px var(--rack-pad); display: flex; flex-direction: column; gap: 4px; }
.flash { padding: 8px 12px; font-size: 12px; border-radius: 2px; }
.flash-success { background: #dfeede; color: var(--success); border-left: 3px solid var(--success); }
.flash-error   { background: #f5dcdc; color: var(--danger);  border-left: 3px solid var(--danger); }

/* ========== Main ========== */
.main { min-height: calc(100vh - var(--topbar-h)); }

/* ========== Closet (rack) ========== */
.closet { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h)); }

.types-bar {
  display: flex; gap: 2px;
  padding: 6px var(--rack-pad);
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.types-bar::-webkit-scrollbar { display: none; }
.type-tab {
  background: transparent; border: none;
  padding: 6px 12px; font-size: 12px; color: var(--text-mute);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.type-tab.active { color: var(--text); border-bottom-color: var(--text); }

.filter-bar {
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  padding: 6px var(--rack-pad);
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  font-size: 11px;
}
.filter-group { display: flex; align-items: center; gap: 4px; }
.filter-label { color: var(--text-dim); margin-right: 4px; font-size: 11px; }
.chip {
  border: 1px solid var(--line-2); background: transparent;
  padding: 3px 9px; font-size: 11px; border-radius: 999px;
  color: var(--text-mute); transition: all .15s;
}
.chip:hover { background: #fff; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* === 3 段ラック === */
.rack-wrap {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
  background: linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 8%);
  -webkit-overflow-scrolling: touch;
  padding-top: 4px;
}
.rack-rows {
  display: flex; flex-direction: column;
  height: 100%;
  min-width: max-content;
}
.rack-row {
  flex: 1 1 0;
  position: relative;
  min-height: 180px;
}
.rod {
  position: absolute; top: 22px; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(180deg, var(--rod-1), var(--rod-2));
  box-shadow: 0 1px 0 rgba(0,0,0,0.18);
  border-radius: 2px;
  margin: 0 var(--rack-pad);
}
@media (min-width: 768px) { .rod { top: 26px; height: 4px; } }

.rack {
  display: flex; gap: var(--hanger-gap);
  padding: 0 var(--rack-pad);
  height: 100%;
  align-items: flex-start;
}
.hanger {
  flex: 0 0 var(--hanger-w);
  height: calc(100% - 18px);
  display: flex; flex-direction: column; align-items: center;
  transition: transform .18s;
  text-decoration: none; color: inherit;
}
.hanger:hover { transform: translateY(4px); }
.hook {
  width: 20px; height: 26px;
  border: 2px solid #6d655a;
  border-top: none; border-right: none;
  border-radius: 0 0 0 12px;
  margin-top: 4px; margin-left: -8px;
}
@media (min-width: 768px) { .hook { width: 24px; height: 32px; margin-top: 6px; border-radius: 0 0 0 14px; } }

.garment {
  width: var(--hanger-w);
  flex: 1;
  margin-top: -4px;
  display: flex; align-items: flex-start; justify-content: center;
  filter: drop-shadow(2px 4px 6px rgba(0,0,0,0.15));
  min-height: 0;
}
.garment.is-hidden { opacity: 0.35; }
.garment svg, .garment .clothing-photo {
  width: 100%; height: 100%; max-height: 100%;
  object-fit: contain;
}
.clothing-photo { background: var(--bg-2); }

.nameplate {
  font-size: 10px; text-align: center; line-height: 1.2;
  padding: 4px 2px 8px;
  color: #4a4a4a;
}
.nameplate-name { max-width: var(--hanger-w); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nameplate-star { color: var(--accent); font-size: 9px; margin-top: 1px; }
@media (min-width: 768px) {
  .nameplate { font-size: 11px; padding: 6px 4px 10px; }
}

.empty-state {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; padding: 80px 20px; color: var(--text-dim);
  text-align: center; width: 100%;
}

.rack-hint {
  padding: 6px var(--rack-pad);
  font-size: 10px; color: var(--text-dim);
  text-align: right;
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}

/* ========== Auth ========== */
.auth-wrap {
  min-height: calc(100vh - var(--topbar-h));
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  background: #fff;
  border: 1px solid var(--line);
  padding: 32px 28px;
  width: 100%; max-width: 360px;
}
.auth-title {
  font-family: var(--serif);
  font-size: 22px; letter-spacing: 0.1em;
  margin-bottom: 20px;
}
.auth-foot { font-size: 11px; color: var(--text-dim); margin-top: 16px; text-align: center; }
.auth-foot a { color: var(--text); text-decoration: underline; }

/* ========== Forms ========== */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 11px; color: var(--text-mute); letter-spacing: 0.05em; }
.field-label small { color: var(--text-dim); font-weight: normal; margin-left: 4px; }
.field input[type="text"],
.field input[type="password"],
.field input[type="date"],
.field input[type="file"],
.field input[type="color"],
.field select,
.field textarea {
  width: 100%; padding: 8px 10px; font-size: 14px;
  background: #fff; border: 1px solid var(--line-2); border-radius: 2px;
  font-family: inherit; color: var(--text);
}
.field input[type="color"] { padding: 2px; height: 36px; }
.field input:focus, .field select:focus { outline: 2px solid var(--text); outline-offset: -1px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-hint { color: var(--text-dim); font-size: 11px; margin-top: 4px; display: block; }
.field-check { display: flex; gap: 8px; align-items: center; font-size: 13px; }

/* ===== トグルスイッチ ===== */
.toggle-field {
  display: inline-flex; align-items: center; gap: 12px;
  cursor: pointer; user-select: none;
  padding: 4px 0;
}
.toggle-field input {
  position: absolute; opacity: 0; pointer-events: none;
}
.toggle-track {
  position: relative; display: inline-block;
  width: 40px; height: 22px;
  background: var(--line-2);
  border-radius: 999px;
  transition: background .18s ease;
  flex-shrink: 0;
}
.toggle-track::after {
  content: '';
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform .18s ease;
}
.toggle-field input:checked + .toggle-track { background: var(--text); }
.toggle-field input:checked + .toggle-track::after { transform: translateX(18px); }
.toggle-field input:focus-visible + .toggle-track {
  box-shadow: 0 0 0 3px rgba(0,0,0,0.18);
}
.toggle-label { font-size: 13px; color: var(--text); }

/* ===== SVG 色ピッカー行 ===== */
.svg-color-row { gap: 8px; }
.svg-color-head { display: flex; justify-content: space-between; align-items: center; }
.svg-color-input-wrap { display: flex; gap: 8px; align-items: center; }
.svg-color-input-wrap input[type="color"] {
  width: 44px; height: 36px; padding: 2px;
  border: 1px solid var(--line-2); border-radius: 2px;
  cursor: pointer;
}
.svg-color-input-wrap input[type="text"] {
  flex: 1; padding: 7px 10px; font-size: 12px;
  border: 1px solid var(--line-2); border-radius: 2px;
  font-family: "SF Mono", Menlo, monospace;
  color: var(--text-mute);
}
.link-btn {
  background: none; border: none; padding: 0;
  font-family: inherit; font-size: 11px;
  color: var(--text-mute); cursor: pointer;
  text-decoration: underline;
}
.link-btn:hover { color: var(--text); }

fieldset { border: none; padding: 0; }
.chip-group { display: flex; flex-wrap: wrap; gap: 4px; }
.chip-check { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.chip-check input { position: absolute; opacity: 0; }
.chip-check span {
  padding: 4px 10px; border: 1px solid var(--line-2); font-size: 12px;
  border-radius: 999px; color: var(--text-mute); transition: all .15s;
}
.chip-check input:checked + span { background: var(--text); color: var(--bg); border-color: var(--text); }

.btn-primary, .btn-ghost, .btn-danger {
  padding: 9px 16px; font-size: 13px; font-family: inherit;
  border-radius: 2px; border: 1px solid var(--text); cursor: pointer;
  transition: all .12s; letter-spacing: 0.05em;
}
.btn-primary { background: var(--text); color: var(--bg); }
.btn-primary:hover { background: #000; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line-2); }
.btn-ghost:hover { background: #fff; }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

/* ========== Item form ========== */
.item-form { padding: 20px var(--rack-pad); max-width: 960px; margin: 0 auto; }
.form-title { font-family: var(--serif); font-size: 20px; letter-spacing: 0.08em; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 24px; }
.form-main { display: flex; flex-direction: column; gap: 14px; }
.form-side { display: flex; flex-direction: column; gap: 14px; }
.form-preview {
  background: var(--bg-2); padding: 20px;
  display: flex; align-items: center; justify-content: center;
  min-height: 200px;
}
.form-preview svg, .form-preview .clothing-photo { width: 100%; max-width: 220px; height: auto; }
.form-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line);
}
@media (min-width: 768px) {
  .form-grid { grid-template-columns: 1fr 280px; }
}

/* SVG picker */
.svg-picker-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.svg-picker-item {
  background: var(--bg-2); border: 1.5px solid var(--line-2);
  padding: 8px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-family: inherit;
}
.svg-picker-item svg { width: 100%; height: 60px; }
.svg-picker-item .svg-picker-label { font-size: 9px; color: var(--text-mute); }
.svg-picker-item.selected { border-color: var(--text); background: #fff; }
.svg-picker-item.selected .svg-picker-label { color: var(--text); }

/* ========== Detail ========== */
.detail {
  padding: 20px var(--rack-pad);
  max-width: 960px; margin: 0 auto;
  display: grid; grid-template-columns: 1fr; gap: 24px;
}
.detail-visual {
  background: var(--bg-2); padding: 24px;
  display: flex; align-items: center; justify-content: center;
  min-height: 240px;
}
.detail-visual svg, .detail-visual .clothing-photo { width: 100%; max-width: 280px; height: auto; }
.detail-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.detail-name { font-family: var(--serif); font-size: 22px; letter-spacing: 0.08em; }
.detail-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.detail-props {
  display: grid; grid-template-columns: 80px 1fr;
  gap: 10px 18px; font-size: 13px;
  border-top: 1px solid var(--line); padding-top: 16px;
}
.detail-props dt { color: var(--text-mute); }
.detail-props dd { color: var(--text); display: flex; align-items: center; gap: 6px; }
.color-swatch {
  display: inline-block; width: 14px; height: 14px;
  border-radius: 50%; border: 1px solid var(--line-2);
}
@media (min-width: 768px) {
  .detail { grid-template-columns: 280px 1fr; }
}

/* ========== Settings ========== */
.settings { padding: 20px var(--rack-pad); max-width: 900px; margin: 0 auto; }
.settings-title { font-family: var(--serif); font-size: 20px; letter-spacing: 0.08em; margin-bottom: 4px; }
.settings-sub { font-size: 11px; color: var(--text-dim); margin-bottom: 24px; }
.settings-section {
  background: #fff; border: 1px solid var(--line); padding: 16px 18px;
  margin-bottom: 18px;
}
.settings-section-title {
  font-size: 13px; letter-spacing: 0.1em; color: var(--text);
  margin-bottom: 12px; padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.taxo-list { list-style: none; margin-bottom: 12px; }
.taxo-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-bottom: 1px dashed var(--line);
  background: #fff;
}
.taxo-item.dragging { opacity: 0.4; }
.drag-handle {
  background: none; border: none; color: var(--text-dim);
  cursor: grab; padding: 4px 8px; font-size: 14px;
}
.drag-handle:active { cursor: grabbing; }
.taxo-edit {
  display: flex; gap: 6px; align-items: center; flex: 1;
}
.taxo-edit input[type="text"] {
  flex: 1; padding: 5px 8px; font-size: 13px;
  border: 1px solid var(--line-2); border-radius: 2px;
  font-family: inherit;
}
.taxo-edit input[type="color"] {
  width: 36px; height: 30px; padding: 2px;
  border: 1px solid var(--line-2); border-radius: 2px;
}
.taxo-add {
  display: flex; gap: 6px; align-items: center;
  margin-top: 8px; padding-top: 8px;
}
.taxo-add input[type="text"] {
  flex: 1; padding: 6px 8px; font-size: 13px;
  border: 1px solid var(--line-2); border-radius: 2px;
  font-family: inherit;
}
.taxo-add input[type="color"] {
  width: 36px; height: 30px; padding: 2px;
  border: 1px solid var(--line-2); border-radius: 2px;
}
.btn-sm, .btn-sm-primary, .btn-sm-danger {
  padding: 5px 10px; font-size: 11px; font-family: inherit;
  border-radius: 2px; cursor: pointer; letter-spacing: 0.05em;
  white-space: nowrap;
}
.btn-sm { background: #fff; color: var(--text); border: 1px solid var(--line-2); }
.btn-sm:hover { background: var(--bg-2); }
.btn-sm-primary { background: var(--text); color: var(--bg); border: 1px solid var(--text); }
.btn-sm-danger { background: transparent; color: var(--danger); border: 1px solid var(--line-2); }
.btn-sm-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
