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

:root {
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --border-light: #f1f5f9;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --accent:       #3b82f6;
  --accent-dark:  #2563eb;
  --accent-faint: #eff6ff;
  --danger:       #ef4444;
  --warning-bg:   #fffbeb;
  --warning-border: #fcd34d;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.1), 0 4px 8px rgba(0,0,0,.06);
  --header-h: 52px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ── Login ───────────────────────────────────────────────────────────────── */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.login-card {
  background: var(--surface);
  padding: 2.5rem;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 360px;
}

.login-icon {
  font-size: 2rem;
  text-align: center;
  margin-bottom: 0.5rem;
}

.login-card h1 {
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 1.75rem;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 20;
  position: relative;
}

.app-title {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  letter-spacing: -.01em;
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 420px;
}

.search-wrap input {
  width: 100%;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.88rem;
  outline: none;
  background: var(--bg);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}

.search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
  background: var(--surface);
}

#search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  width: 460px;
  max-width: 92vw;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  max-height: 360px;
  overflow-y: auto;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background .1s;
}

.search-result-item:hover { background: var(--bg); }
.search-result-item:last-child { border-bottom: none; }

.sr-name { font-size: 0.88rem; font-weight: 500; }
.sr-loc  { font-size: 0.78rem; color: var(--text-muted); margin-top: 1px; }
.sr-qty  { margin-left: auto; font-size: 0.82rem; color: var(--text-muted); white-space: nowrap; }

.header-actions { display: flex; gap: 0.5rem; margin-left: auto; }

/* ── App Layout ──────────────────────────────────────────────────────────── */

#app { display: flex; flex-direction: column; height: 100vh; }

#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

#map-container {
  flex: 1;
  overflow: hidden;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

#office-map {
  width: 100%;
  max-height: calc(100vh - var(--header-h) - 3rem);
  display: block;
}

#map-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Detail Panel ────────────────────────────────────────────────────────── */

#detail-panel {
  width: 390px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#detail-panel.hidden { display: none; }

#detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#detail-rack-name { font-size: 1.05rem; font-weight: 700; }

#section-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.section-tab {
  padding: 0.55rem 1rem;
  font-size: 0.83rem;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  transition: color .15s, border-color .15s;
  user-select: none;
}
.section-tab:hover { color: var(--text); }
.section-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

#section-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem;
}

/* ── Shelves & Items ─────────────────────────────────────────────────────── */

.shelf {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  margin-bottom: 0.7rem;
  overflow: hidden;
}

.shelf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  background: var(--border);
  transition: background .2s;
}

.shelf-header-actions { display: flex; align-items: center; gap: 0.25rem; }

.shelf-done-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #94a3b8;
  background: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  color: transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .15s, background .15s, color .15s;
}
.shelf-done-btn:hover {
  border-color: #22c55e;
  color: rgba(34,197,94,.45);
}
.shelf-done-btn.done {
  border-color: #22c55e;
  background: #22c55e;
  color: #fff;
}

.shelf.done { border-color: #86efac; }
.shelf.done .shelf-header { background: #dcfce7; }

.shelf-header span {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.shelf-name {
  cursor: text;
  border-radius: 3px;
  padding: 1px 3px;
  transition: background .12s;
}
.shelf-name:hover { background: rgba(59,130,246,.12); }

.shelf-name-input {
  background: transparent;
  border: none;
  border-bottom: 1.5px solid var(--accent);
  outline: none;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 0 2px;
  min-width: 60px;
  max-width: 100%;
}

.shelf-body { padding: 0.4rem 0.5rem 0.5rem; }

.item-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.25rem;
  border-bottom: 1px solid var(--border-light);
}
.item-row:last-child { border-bottom: none; }

.item-name { flex: 1; font-size: 0.88rem; }
.item-qty  { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.item-qty.low { color: var(--danger); }
.item-qty.unknown { font-weight: 400; font-style: italic; }

.item-actions { display: flex; gap: 0.2rem; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 5px;
  font-size: 0.78rem;
  color: var(--text-muted);
  transition: background .12s, color .12s;
  line-height: 1;
}
.btn-icon:hover            { background: var(--border); color: var(--text); }
.btn-icon.danger:hover     { background: #fee2e2; color: var(--danger); }

.btn-dashed {
  display: block;
  width: 100%;
  padding: 0.38rem;
  text-align: center;
  font-size: 0.8rem;
  cursor: pointer;
  border: 1.5px dashed var(--border);
  border-radius: 7px;
  background: none;
  color: var(--text-muted);
  margin-top: 0.45rem;
  transition: border-color .15s, color .15s, background .15s;
}
.btn-dashed:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-faint); }

.btn-add-shelf {
  margin-top: 0.75rem;
}

/* ── Low Stock Side Panel ────────────────────────────────────────────────── */

#low-stock-panel {
  position: fixed;
  inset: 0 0 0 auto;
  width: 380px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 40;
  display: flex;
  flex-direction: column;
  box-shadow: -6px 0 20px rgba(0,0,0,.08);
}
#low-stock-panel.hidden { display: none; }

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.side-panel-header h2 { font-size: 1rem; font-weight: 700; }

#low-stock-list { flex: 1; overflow-y: auto; padding: 0.9rem; }

.ls-item {
  padding: 0.75rem;
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: 9px;
  margin-bottom: 0.65rem;
}
.ls-item .ls-name { font-weight: 600; font-size: 0.9rem; }
.ls-item .ls-loc  { font-size: 0.78rem; color: var(--text-muted); margin-top: 3px; }
.ls-item .ls-qty  { font-size: 0.82rem; color: var(--danger); margin-top: 4px; font-weight: 500; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5rem 1.1rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  transition: background .15s;
}
.btn-primary:hover  { background: var(--accent-dark); }
.btn-primary.full-width { width: 100%; padding: 0.6rem; }

.btn-secondary {
  background: none;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.4rem 0.9rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.83rem;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--bg); }

.btn-ghost {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem 0.75rem;
  border-radius: 7px;
  font-size: 0.83rem;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.icon-btn { padding: 0.3rem 0.55rem; font-size: 0.9rem; }

/* ── Fields ──────────────────────────────────────────────────────────────── */

.field { margin-bottom: 1rem; }

.field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.label-hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.field input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.9rem;
  outline: none;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}

.field-row { display: flex; gap: 0.75rem; }
.field-row .field { flex: 1; }

/* ── Modal ───────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  padding: 1.6rem;
  width: 430px;
  max-width: 95vw;
  box-shadow: var(--shadow-lg);
}

.modal h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 1.3rem; }

.modal-wide { width: 620px; max-height: 80vh; overflow-y: auto; }

.layout-rack {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.layout-rack-meta { display: flex; gap: 0.75rem; align-items: flex-end; margin-bottom: 0.85rem; }
.layout-rack-meta .field { margin-bottom: 0; }
.layout-rack-meta .field:first-child { flex: 1; }
.layout-rack-meta .field input[type="number"] { width: 70px; }

.layout-sections-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 0.4rem;
}

.layout-sections-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.layout-sections-grid input {
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  outline: none;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s;
}
.layout-sections-grid input:focus { border-color: var(--accent); }

.layout-group-row {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border);
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.25rem;
}

/* ── SVG Map ─────────────────────────────────────────────────────────────── */

.rack-group text { pointer-events: none; user-select: none; }

.rack-bg             { fill: #dde3ed; transition: fill .15s; }
.rack-bg.selected    { fill: #bfdbfe; }
.rack-bg.has-results { fill: #fde68a; }

.rack-outline             { fill: none; stroke: #94a3b8; stroke-width: 1.5; }
.rack-outline.selected    { stroke: #3b82f6; stroke-width: 2; }
.rack-outline.has-results { stroke: #f59e0b; stroke-width: 2; }

.section-bg        { fill: transparent; cursor: pointer; transition: fill .12s; }
.section-bg:hover  { fill: rgba(59,130,246,.12); }
.section-bg.active { fill: rgba(59,130,246,.22); }

.rack-label     { font-size: 12px; font-weight: 700; fill: #334155; }
.section-label  { font-size: 9px; fill: #475569; }
.rack-divider { stroke: #94a3b8; stroke-width: .75; stroke-dasharray: 3 2; }
.rack-split   { stroke: #64748b; stroke-width: 1.5; }
.room-outline   { fill: #f8fafc; stroke: #cbd5e1; stroke-width: 2; }
.room-label     { font-size: 11px; fill: #94a3b8; }

/* ── Utilities ───────────────────────────────────────────────────────────── */

.hidden { display: none !important; }
.error  { color: var(--danger); font-size: 0.82rem; padding: 0.5rem 0.6rem; background: #fee2e2; border-radius: 6px; }

/* ── Dark Mode ───────────────────────────────────────────────────────────── */

@media (prefers-color-scheme: dark) {
  :root {
    --bg:             #0f172a;
    --surface:        #1e293b;
    --border:         #334155;
    --border-light:   #1e293b;
    --text:           #f1f5f9;
    --text-muted:     #94a3b8;
    --accent-faint:   #1e3a5f;
    --warning-bg:     #1c1400;
    --warning-border: #78350f;
    --shadow:    0 1px 3px rgba(0,0,0,.35);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.45);
  }

  .search-wrap input { background: #0f172a; }
  .search-wrap input:focus { background: var(--surface); }

  .rack-bg              { fill: #334155; }
  .rack-bg.selected     { fill: #1d4ed8; }
  .rack-bg.has-results  { fill: #78350f; }
  .rack-outline         { stroke: #475569; }
  .rack-outline.selected { stroke: #60a5fa; }
  .rack-outline.has-results { stroke: #f59e0b; }
  .section-bg:hover     { fill: rgba(96,165,250,.15); }
  .section-bg.active    { fill: rgba(96,165,250,.28); }
  .rack-label    { fill: #e2e8f0; }
  .section-label { fill: #94a3b8; }
  .rack-divider { stroke: #475569; }
  .rack-split   { stroke: #94a3b8; }
  .room-outline         { fill: #1e293b; stroke: #334155; }

  .shelf.done { border-color: #166534; }
  .shelf.done .shelf-header { background: #14532d; }
  .shelf-done-btn { border-color: #475569; }
  .shelf-done-btn:hover { border-color: #4ade80; color: rgba(74,222,128,.45); }
  .shelf-done-btn.done { border-color: #4ade80; background: #4ade80; color: #0f172a; }
}
