:root {
  --bg: #f5f2eb;
  --panel: #ffffff;
  --ink: #24211c;
  --muted: #6f6a61;
  --line: #d9d3c8;
  --accent: #6d302c;
  --accent-dark: #55231f;
  --warning: #fff2cc;
  --warning-line: #d8b651;
  --success: #eaf4ea;
  --danger: #8a2424;
  --shadow: 0 2px 10px rgba(40, 34, 28, 0.08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; }
button, input, select { min-height: 44px; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 0.9rem; margin-top: 6px; }

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 1.6rem; }
.brand-mark { width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: white; display: flex; align-items: center; justify-content: center; margin-bottom: 16px; font-family: Georgia, serif; font-size: 1.6rem; }
.login-card label, .field label { display: block; font-weight: 600; margin: 14px 0 5px; }
.login-card input, .field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid #bfb8ad;
  border-radius: 7px;
  background: #fff;
  padding: 10px 11px;
  color: var(--ink);
}
textarea { resize: vertical; }
.form-message { min-height: 22px; padding-top: 8px; color: var(--danger); }
.demo-note { margin-top: 16px; padding: 9px 10px; background: #f2efe9; border-radius: 6px; font-size: 0.9rem; color: var(--muted); }

.button, .icon-button, .text-button, .nav-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 9px 13px;
}
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:active { background: var(--accent-dark); }
.button.danger { color: var(--danger); border-color: #dcb3b3; }
.button.small { min-height: 36px; padding: 6px 9px; font-size: 0.9rem; }
.full { width: 100%; margin-top: 20px; }
.icon-button, .text-button { background: transparent; border-color: transparent; }
.text-button { color: var(--accent); }

.topbar {
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) 12px 0;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
}
.topbar-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shell { min-height: 100vh; padding-top: 56px; }
.sidebar {
  position: fixed;
  top: 56px;
  bottom: 0;
  left: 0;
  width: 245px;
  background: #eee9df;
  border-right: 1px solid var(--line);
  padding: 14px 12px;
  z-index: 15;
  overflow-y: auto;
}
.nav-item { width: 100%; text-align: left; margin-bottom: 7px; background: transparent; border-color: transparent; }
.nav-item.active { background: var(--panel); border-color: var(--line); font-weight: 650; }
.badge { float: right; min-width: 22px; text-align: center; background: var(--accent); color: white; border-radius: 12px; padding: 1px 7px; font-size: 0.8rem; line-height: 20px; }
.sidebar-footer { position: absolute; bottom: 14px; left: 16px; color: var(--muted); font-size: 0.85rem; }
.main { margin-left: 245px; padding: 24px; max-width: 1280px; }
.view { display: none; }
.view.active { display: block; }

.search-box { display: flex; max-width: 820px; }
.search-box input { flex: 1; min-width: 0; border: 1px solid #aaa298; border-radius: 8px 0 0 8px; padding: 10px 12px; }
.search-box .button { border-radius: 0 8px 8px 0; }
#search-help { margin: 8px 0 18px; }

.page-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; }
.page-heading h2 { margin: 0 0 3px; }
.page-heading p { margin: 0; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card h3 { margin: 0 0 9px; }
.result-card { cursor: pointer; }
.result-card:active { background: #faf8f3; }
.result-title { display: flex; justify-content: space-between; align-items: baseline; }
.result-title strong { font-size: 1.1rem; }
.pill { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; font-size: 0.8rem; background: #f7f5f1; }
.pill.warning { background: var(--warning); border-color: var(--warning-line); }
.pill.success { background: var(--success); }

.detail-header { margin-bottom: 18px; }
.detail-header h2 { margin-bottom: 4px; font-size: 1.7rem; }
.detail-meta { color: var(--muted); }
.detail-actions { margin-top: 12px; }
.detail-actions .button { margin-right: 7px; margin-bottom: 7px; }
.section-title { margin: 26px 0 10px; font-size: 1.2rem; }
.piece-card { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; margin-bottom: 12px; overflow: hidden; }
.piece-head { padding: 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.piece-body { padding: 14px; }
.fragment-row { border-top: 1px solid #ebe6de; padding: 11px 0; }
.fragment-row:first-child { border-top: 0; }
.fragment-main { display: flex; align-items: center; justify-content: space-between; }
.fragment-id { font-weight: 650; }
.fragment-sub { font-size: 0.88rem; color: var(--muted); margin-top: 3px; }
.location-line { padding: 8px 10px; background: #f7f4ee; border-radius: 6px; margin-bottom: 10px; }
.measurements { font-size: 0.92rem; color: #4d4841; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 16px; row-gap: 0; max-width: 850px; }
.span-2 { grid-column: span 2; }
.form-actions { margin-top: 16px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: 10px 11px; border-bottom: 1px solid #e5dfd6; text-align: left; vertical-align: top; }
th { background: #f0ece4; font-size: 0.88rem; }
.warning-panel { background: var(--warning); border: 1px solid var(--warning-line); border-radius: 7px; padding: 11px 12px; margin-bottom: 14px; }
.empty-state { background: var(--panel); border: 1px dashed #c8c0b4; border-radius: 8px; padding: 24px; text-align: center; color: var(--muted); }

.xml-editor { width: 100%; min-height: 260px; font-family: Menlo, Consolas, monospace; font-size: 13px; white-space: pre; overflow: auto; }
.photo-grid { display: flex; flex-wrap: wrap; margin: -5px; }
.photo-card { width: 180px; margin: 5px; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: #fff; }
.photo-card img { width: 100%; height: 130px; object-fit: cover; display: block; }
.photo-caption { padding: 6px 8px; font-size: 0.85rem; color: var(--muted); }

.modal-backdrop { position: fixed; z-index: 50; inset: 0; background: rgba(20, 17, 14, .48); display: flex; align-items: center; justify-content: center; padding: 18px; }
.modal { width: 100%; max-width: 620px; max-height: 90vh; overflow-y: auto; background: var(--panel); border-radius: 10px; padding: 18px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 18px; }
.modal-actions .button { margin-left: 8px; }
.checkbox-list label { display: block; padding: 10px 4px; border-bottom: 1px solid #eee8de; }
.checkbox-list input { min-height: 0; margin-right: 8px; }

@media (max-width: 760px) {
  .sidebar { transform: translateX(-102%); transition: transform .16s ease-out; width: 86%; max-width: 300px; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding: 15px 12px 34px; }
  .search-box { width: 100%; }
  .page-heading { display: block; }
  .page-heading .button { margin-top: 10px; }
  .form-grid { display: block; }
  .field { margin-bottom: 10px; }
  .piece-head { align-items: flex-start; }
  .fragment-main { display: block; }
  .fragment-main .pill { margin-top: 5px; }
  .photo-card { width: calc(50% - 10px); }
  .modal { max-height: 92vh; padding: 15px; }
}

@media (max-width: 380px) {
  body { font-size: 15px; }
  .login-screen { padding: 14px; }
  .login-card { padding: 20px; }
  .main { padding-left: 10px; padding-right: 10px; }
  .detail-header h2 { font-size: 1.45rem; }
  .button { padding-left: 10px; padding-right: 10px; }
}
