@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Playfair+Display:ital,wght@0,600;0,700;1,600&display=swap");

:root {
  --bg: #100d0e;
  --bg-soft: #181315;
  --surface: #21191c;
  --surface-2: #2b2023;
  --surface-3: #34262a;
  --ink: #f4eadc;
  --muted: #a99a91;
  --line: rgba(233, 211, 190, 0.13);
  --line-strong: rgba(233, 211, 190, 0.26);
  --wine: #7c2438;
  --wine-bright: #ad4057;
  --brass: #c3a66e;
  --green: #6f9176;
  --danger: #d56a70;
  --radius: 18px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 100% -10%, rgba(124, 36, 56, 0.22), transparent 31rem),
    var(--bg);
  color: var(--ink);
  font-family: "DM Sans", system-ui, sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

.app-shell { max-width: 1180px; margin: 0 auto; min-height: 100vh; padding-bottom: 92px; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 20px 18px 14px; background: linear-gradient(180deg, rgba(16,13,14,.98) 76%, transparent);
}
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.sync-status {
  display: flex; align-items: center; gap: 7px; max-width: 155px; color: var(--muted); font-size: 10px; font-weight: 700;
}
.sync-status i { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: var(--muted); }
.sync-synced i { background: var(--green); }
.sync-syncing i { background: var(--brass); animation: sync-pulse 1s ease-in-out infinite; }
.sync-error { color: var(--danger); }
.sync-error i { background: var(--danger); }
@keyframes sync-pulse { 50% { opacity: .25; transform: scale(.7); } }
.brand { border: 0; background: none; color: var(--ink); padding: 0; text-align: left; }
.brand span { display: block; color: var(--brass); font-size: 10px; letter-spacing: .2em; text-transform: uppercase; }
.brand strong { font: 600 20px/1.15 "Playfair Display", serif; }
.icon-button, .round-button {
  width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--line);
  border-radius: 50%; color: var(--ink); background: var(--surface);
}
.icon-button svg, .round-button svg, .nav-item svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.main { padding: 8px 16px 32px; }

h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-family: "Playfair Display", serif; }
h1 { margin-bottom: 8px; font-size: clamp(32px, 9vw, 52px); line-height: 1; }
h2 { margin-bottom: 10px; font-size: 26px; }
h3 { margin-bottom: 6px; font-size: 19px; }
.muted { color: var(--muted); }
.eyeline { color: var(--brass); font-size: 11px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; }
.section { margin-top: 30px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-heading h2 { margin: 0; }
.text-button { border: 0; padding: 8px 0; color: var(--brass); background: transparent; font-weight: 700; }
.primary, .secondary, .danger-button {
  min-height: 48px; border-radius: 999px; border: 1px solid transparent; padding: 0 18px; color: white; font-weight: 700;
}
.primary { background: var(--wine); box-shadow: 0 12px 32px rgba(124,36,56,.3); }
.primary:hover { background: var(--wine-bright); }
.secondary { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.danger-button { background: transparent; border-color: rgba(213,106,112,.4); color: var(--danger); }
.wide { width: 100%; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }

.hero { padding: 18px 0 8px; }
.hero-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; }
.hero p { max-width: 390px; margin-bottom: 0; color: var(--muted); line-height: 1.55; }
.add-fab {
  flex: 0 0 auto; width: 62px; height: 62px; border: 0; border-radius: 50%; color: white; background: var(--wine);
  font-size: 30px; box-shadow: 0 15px 36px rgba(124,36,56,.42);
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin-top: 24px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); }
.stat { padding: 18px; background: rgba(33,25,28,.92); }
.stat strong { display: block; font: 700 30px/1 "Playfair Display", serif; }
.stat span { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; }
.cloud-panel {
  display: grid; gap: 7px; margin-top: 14px; padding: 14px 16px; border: 1px solid rgba(111,145,118,.32);
  border-radius: 14px; background: rgba(111,145,118,.08);
}
.cloud-panel strong { font-size: 13px; }
.cloud-panel span { color: var(--muted); font-size: 11px; line-height: 1.5; }
.cloud-panel button { justify-self: start; margin-top: 5px; min-height: 40px; font-size: 11px; }
.cloud-panel-offline { border-color: var(--line); background: var(--surface); }

.category-rail { display: flex; gap: 10px; overflow-x: auto; padding: 2px 1px 8px; scrollbar-width: none; }
.category-rail::-webkit-scrollbar { display: none; }
.category {
  min-width: 130px; padding: 16px; border: 1px solid var(--line); border-radius: 16px; color: var(--ink);
  text-align: left; background: var(--surface); transition: transform .2s ease, border-color .2s ease;
}
.category:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.category-dot { width: 9px; height: 9px; border-radius: 50%; margin-bottom: 20px; background: var(--cat); box-shadow: 0 0 0 5px color-mix(in srgb, var(--cat) 15%, transparent); }
.category strong { display: block; font-size: 14px; }
.category span { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }

.shelf-overview {
  padding: 12px 12px 2px; border: 1px solid var(--line); border-radius: 22px; background: linear-gradient(145deg, #241a1d, #171214); box-shadow: var(--shadow);
}
.shelf-mini {
  display: grid; grid-template-columns: 72px 1fr 42px; align-items: center; gap: 10px; min-height: 54px;
  border-bottom: 1px solid rgba(195,166,110,.2);
}
.shelf-mini:last-child { border-bottom: 0; }
.shelf-mini strong { color: var(--brass); font: 600 14px "Playfair Display", serif; }
.bottle-track { display: flex; align-items: flex-end; gap: 3px; height: 28px; }
.bottle { width: 7px; height: 22px; border-radius: 3px 3px 2px 2px; background: var(--bottle, #7c2438); position: relative; opacity: .9; }
.bottle::before { content: ""; position: absolute; top: -5px; left: 2px; width: 3px; height: 7px; border-radius: 1px; background: inherit; }
.shelf-mini span { color: var(--muted); font-size: 11px; text-align: right; }

.wine-list { display: grid; gap: 10px; }
.wine-card {
  display: grid; grid-template-columns: 54px 1fr auto; gap: 13px; align-items: center; width: 100%; padding: 12px;
  border: 1px solid var(--line); border-radius: 16px; color: var(--ink); text-align: left; background: var(--surface);
}
.wine-card:hover { border-color: var(--line-strong); background: var(--surface-2); }
.wine-image {
  width: 54px; height: 68px; display: grid; place-items: center; overflow: hidden; border-radius: 10px; background: #151112;
  color: var(--brass); font: 600 25px "Playfair Display", serif;
}
.wine-image img { width: 100%; height: 100%; padding: 4px; object-fit: contain; }
.wine-meta { min-width: 0; }
.wine-meta strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wine-meta span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wine-count { min-width: 40px; text-align: center; }
.wine-count strong { display: block; font: 700 22px "Playfair Display", serif; }
.wine-count span { color: var(--muted); font-size: 10px; }
.history-actions { display: grid; justify-items: center; gap: 7px; }
.history-delete {
  border: 0; padding: 4px 2px; color: var(--danger); background: transparent;
  font-size: 11px; font-weight: 700;
}
.history-delete:hover { color: #f08d92; }

.toolbar { display: grid; gap: 10px; margin: 18px 0; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 14px; top: 15px; width: 18px; height: 18px; stroke: var(--muted); fill: none; }
.search-wrap input { padding-left: 42px; }
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.filters select { min-width: 126px; }
input, select, textarea {
  width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px;
  color: var(--ink); background: var(--surface); appearance: none;
}
textarea { min-height: 100px; resize: vertical; }
select { background-image: linear-gradient(45deg,transparent 50%,var(--brass) 50%),linear-gradient(135deg,var(--brass) 50%,transparent 50%); background-position: calc(100% - 17px) 20px,calc(100% - 12px) 20px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.photo-field { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.photo-picker { position: relative; display: grid; grid-template-columns: auto minmax(0,1fr); align-items: center; gap: 10px; min-height: 48px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; }
.photo-picker input { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; opacity: 0; pointer-events: none; }
.photo-pick-button { padding: 8px 10px; border-radius: 8px; color: var(--ink); background: var(--wine); font-size: 11px; text-align: center; }
.photo-file-name { min-width: 0; overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; }
.photo-selection { display: grid; grid-template-columns: 58px 1fr; align-items: center; gap: 10px; padding: 9px; border: 1px solid rgba(195,166,110,.35); border-radius: 12px; background: rgba(195,166,110,.06); }
.photo-selection[hidden] { display: none; }
.photo-selection img { width: 58px; height: 70px; padding: 3px; object-fit: contain; border-radius: 8px; background: #151112; }
.photo-selection strong,.photo-selection small { display: block; }
.photo-selection strong { color: var(--ink); }
.photo-selection small,.photo-help { color: var(--muted); font-size: 10px; font-weight: 500; }
.primary:disabled { opacity: .5; cursor: wait; }
.field-grid { display: grid; gap: 12px; }
.form-section { margin-top: 22px; }
.form-section h3 { border-bottom: 1px solid var(--line); padding-bottom: 9px; color: var(--brass); font-family: "DM Sans", sans-serif; font-size: 11px; letter-spacing: .15em; text-transform: uppercase; }
.suggestion { margin: 10px 0 0; padding: 12px; border-left: 2px solid var(--brass); color: var(--muted); background: rgba(195,166,110,.06); font-size: 12px; }

.shelf-grid { display: grid; gap: 12px; }
.shelf-card { padding: 17px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.shelf-card-head { display: flex; justify-content: space-between; gap: 12px; }
.shelf-card h3 { margin: 0; font-size: 22px; }
.shelf-card p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.meter { height: 5px; margin: 14px 0; overflow: hidden; border-radius: 999px; background: #100d0e; }
.meter span { display: block; height: 100%; width: var(--width); border-radius: inherit; background: linear-gradient(90deg, var(--wine), var(--brass)); }
.capacity-edit { display: flex; gap: 8px; margin-top: 14px; }
.capacity-edit input { min-width: 0; }

.empty { padding: 42px 18px; border: 1px dashed var(--line-strong); border-radius: var(--radius); text-align: center; color: var(--muted); }
.empty strong { display: block; margin-bottom: 7px; color: var(--ink); font: 600 22px "Playfair Display", serif; }
.empty-glyph { font: 600 44px "Playfair Display", serif; color: var(--brass); }

.bottom-nav {
  position: fixed; z-index: 25; left: 50%; bottom: 0; transform: translateX(-50%); display: grid; grid-template-columns: repeat(4,1fr);
  width: min(100%, 680px); padding: 8px 10px max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
  background: rgba(24,19,21,.96); backdrop-filter: blur(20px);
}
.nav-item { min-height: 58px; border: 0; color: var(--muted); background: none; font-size: 10px; font-weight: 700; }
.nav-item svg { display: block; margin: 0 auto 5px; }
.nav-item.active { color: var(--ink); }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; padding-top: 24px;
  background: rgba(4,3,3,.72); backdrop-filter: blur(6px);
}
.modal {
  width: min(100%, 720px); max-height: calc(100vh - 24px); overflow-y: auto; padding: 20px 16px 32px;
  border: 1px solid var(--line); border-radius: 24px 24px 0 0; background: var(--bg-soft); box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.modal-head h2 { margin: 0; }
.detail-photo-button { position: relative; display: grid; place-items: center; width: 100%; min-height: 360px; margin-bottom: 18px; padding: 14px; overflow: hidden; border: 0; border-radius: 18px; background: #080708; }
.detail-photo { display: block; width: 100%; height: 360px; object-fit: contain; }
.detail-photo-button span {
  position: absolute; right: 10px; bottom: 10px; padding: 7px 10px; border-radius: 999px;
  color: var(--ink); background: rgba(17,13,14,.82); backdrop-filter: blur(8px); font-size: 11px; font-weight: 700;
}
.photo-viewer {
  position: fixed; inset: 0; z-index: 70; display: grid; grid-template-rows: minmax(0,1fr) auto; place-items: center; gap: 14px;
  padding: 64px 18px max(22px,env(safe-area-inset-bottom)); color: var(--ink); background: rgba(4,3,3,.96); backdrop-filter: blur(12px);
}
.photo-viewer img { max-width: min(100%,900px); max-height: calc(100vh - 130px); object-fit: contain; border-radius: 14px; box-shadow: var(--shadow); }
.photo-viewer strong { font-family: "Playfair Display",serif; font-size: 18px; }
.photo-viewer-close { position: absolute; top: max(14px,env(safe-area-inset-top)); right: 14px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 18px 0; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--line); }
.detail-item { padding: 12px; background: var(--surface); }
.detail-item span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.detail-item strong { display: block; margin-top: 4px; font-size: 13px; }
.toast { position: fixed; z-index: 80; left: 50%; bottom: 94px; transform: translateX(-50%); padding: 12px 16px; border-radius: 999px; color: var(--ink); background: var(--surface-3); box-shadow: var(--shadow); font-size: 13px; }

@media (min-width: 700px) {
  .topbar { padding-inline: 28px; }
  .main { padding: 12px 28px 48px; }
  .category-rail { display: grid; grid-template-columns: repeat(3, 1fr); overflow: visible; }
  .shelf-grid { grid-template-columns: repeat(2, 1fr); }
  .field-grid { grid-template-columns: repeat(2, 1fr); }
  .wine-list { grid-template-columns: repeat(2, 1fr); }
  .toolbar { grid-template-columns: minmax(280px, 1fr) auto; align-items: start; }
  .modal { align-self: center; max-height: 92vh; border-radius: 24px; padding: 26px; }
}

@media (max-width: 480px) {
  .sync-status { max-width: 82px; }
}

@media (min-width: 980px) {
  .dashboard-layout { display: grid; grid-template-columns: minmax(0,1.45fr) minmax(320px,.75fr); gap: 30px; align-items: start; }
  .dashboard-side { position: sticky; top: 90px; }
  .category-rail { grid-template-columns: repeat(3, 1fr); }
  .shelf-grid { grid-template-columns: repeat(3, 1fr); }
  .bottom-nav { border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; }
}

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