:root {
  color-scheme: light;
  --ink: #292a27;
  --muted: #88877f;
  --soft-ink: #56574f;
  --paper: #f8f6f1;
  --surface: #fffefa;
  --line: #ebe8df;
  --gold: #a87932;
  --gold-dark: #805c27;
  --gold-wash: #f6efe2;
  --green: #587d62;
  --green-wash: #edf3ed;
  --red: #a45d52;
  --red-wash: #f8eeeb;
  font-family: "Avenir Next", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --ink: #f4f2ec;
  --muted: #b8b5ae;
  --soft-ink: #d1cdc4;

  --paper: #121212;
  --surface: #1d1d1d;

  --line: #353535;

  --gold: #d0a25a;
  --gold-dark: #e6bb77;
  --gold-wash: #2f2516;

  --green: #8fb392;
  --green-wash: #253126;

  --red: #d68b85;
  --red-wash: #342120;

  /* Softer text for the item dialog: pure --ink is too bright on the dark fields */
  --field-text: #d6d2c9;
  --field-label: #a8a49b;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  color: var(--ink);
  /* Enhanced light theme gold gradient background glow */
  background:
    radial-gradient(ellipse at 85% 4%, rgba(218, 185, 131, 0.35), transparent 30rem),
    var(--paper);
  font-size: 15px;
}

button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 3px solid rgba(168, 121, 50, .32);
  outline-offset: 2px;
}

.app-shell { width: min(1440px, 100%); margin: 0 auto; padding: 0 56px 44px; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid rgba(219, 215, 205, .8);
  background: var(--surface);
  padding-top: max(12px, env(safe-area-inset-top));
}
.topbar:has(.actions-menu[open]) { z-index: 130; }
.topbar-main {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
}
/* Full-width status strip at the bottom of the topbar */
.save-state-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end; /* Aligns the status text to the right */
  width: 100%;
  padding: 6px 0 10px 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.save-state-bar .save-state {
  font-size: 14px;
  text-align: right;
}
.brand { display: inline-flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; cursor: default;}
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid #e8ddc8; border-radius: 12px; background: #fcfaf5; }
.brand-mark svg { width: 23px; stroke: var(--gold); stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.35; }
.brand-copy { display: grid; gap: 3px; }
.brand-copy strong { font-family: Georgia, "Times New Roman", serif; font-size: 17px; font-weight: 600; letter-spacing: -.2px; }
.brand-copy span, .eyebrow { color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: 1.2px; }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.theme-toggle {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 18px;
}
.theme-toggle:hover {
  opacity: 0.9;
}
.actions-menu {
  position: relative;
}
.actions-menu summary { list-style: none; }
.actions-menu summary::-webkit-details-marker { display: none; }
.actions-menu-trigger { min-height: 40px; }
.actions-menu-panel { position: absolute; z-index: 15; top: calc(100% + 8px); right: 0; width: min(270px, calc(100vw - 28px)); display: grid; gap: 12px; padding: 14px; border: 1px solid #e7e3da; border-radius: 10px; background: var(--surface); box-shadow: 0 10px 28px rgba(37, 34, 27, .16); }
.actions-menu-group { display: grid; gap: 6px; }
.actions-menu-group + .actions-menu-group { padding-top: 11px; border-top: 1px solid var(--line); }
.actions-menu-heading { padding: 0 4px 2px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; }
.actions-menu-collapsible > .actions-menu-heading { display: flex; align-items: center; justify-content: space-between; cursor: pointer; user-select: none; }
.actions-menu-collapsible > .actions-menu-heading::after { width: 7px; height: 7px; margin: -3px 3px 0 10px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; content: ""; transform: rotate(45deg); transition: transform .15s ease, margin .15s ease; }
.actions-menu-collapsible[open] > .actions-menu-heading::after { margin-top: 3px; transform: rotate(225deg); }
.actions-menu-collapsible > .actions-menu-heading:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 3px; }
.actions-menu-panel .button { width: 100%; min-height: 42px; justify-content: flex-start; }
.actions-menu-panel #workdrive-button:not(.workdrive-signout),
.actions-menu-panel #workdrive-button:not(.workdrive-signout):hover:not(:disabled) { color: var(--gold-dark); }
.actions-menu-panel #workdrive-button.workdrive-signout,
.actions-menu-panel #workdrive-button.workdrive-signout:hover:not(:disabled) { color: var(--red); }
.actions-menu-panel #app-reset-button,
.actions-menu-panel #app-reset-button:hover:not(:disabled) { color: var(--red); }
.app-actions-heading .app-version { margin-left: auto; font-size: 10px; font-weight: 500; letter-spacing: .2px; text-transform: none; }
.save-state { display: inline-flex; flex-direction: row-reverse; align-items: center; gap: 8px; color: var(--soft-ink); font-size: 14px; }
.save-dot { width: 7px; height: 7px; border-radius: 50%; background: #78a07f; box-shadow: 0 0 0 3px #e8f0e8; }
.save-state.is-saving .save-dot { background: #c4934b; box-shadow: 0 0 0 3px #f7efdf; }
.save-state.is-error .save-dot { background: #b86153; box-shadow: 0 0 0 3px #f8e9e6; }

main { padding-top: 40px; }
.intro { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 27px; }
.intro-copy .eyebrow { margin: 0 0 9px; color: var(--gold); }
h1, h2, h3, p { margin-top: 0; }
h1, .dialog-heading h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; letter-spacing: -.6px; }
h1 { margin-bottom: 6px; font-size: clamp(31px, 4vw, 40px); line-height: 1.15; }
.intro-description { margin: 0; color: var(--muted); font-size: 14px; }
.button { min-height: 39px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 14px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; font-size: 12px; font-weight: 600; transition: background .15s, border-color .15s, transform .15s; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .55; }
.button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.5; }
.button-quiet { border-color: #e7e3da; background: var(--surface); color: #55564f; }
.button-quiet:hover:not(:disabled) { border-color: #d7c8aa; background: #fff; }
.button-primary { background: #9c7134; color: #fff; box-shadow: 0 2px 6px rgba(100, 72, 32, .12); }
.button-primary:hover:not(:disabled) { background: #865f2a; }
.button-danger { border-color: #eed9d4; background: #fff8f6; color: #9a5147; }
.button-danger:hover:not(:disabled) { border-color: #ddb8b0; background: #fdf0ed; }
.button-primary > span { font-size: 20px; font-weight: 400; line-height: 1; }
.import-button { cursor: pointer; }

.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 25px; }
.summary-card { min-height: 91px; display: flex; align-items: center; gap: 14px; padding: 17px 18px; border: 1px solid #eeebe4; border-radius: 11px; background: rgba(255, 254, 250, .88); box-shadow: 0 2px 8px rgba(61, 52, 33, .025); }
.summary-card p { margin: 0 0 6px; color: var(--muted); font-size: 11px; }
.summary-card strong { font-size: 21px; font-weight: 600; letter-spacing: -.4px; }
.summary-card strong small { padding-left: 4px; color: var(--muted); font-size: 12px; font-weight: 500; }
.summary-icon { width: 38px; height: 38px; display: grid; flex: 0 0 38px; place-items: center; border-radius: 10px; }
.summary-icon svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.5; }
.summary-icon-items { background: #f5efe5; color: #a87932; }
.summary-icon-weight { background: #eff2e9; color: #718050; }
.summary-icon-stored { background: #f5efe5; color: #a87932; }
.summary-icon-in-use { background: #f6f0e5; color: #a87932; }

.summary-card {
  position: relative;
}

.summary-card .summary-content-wrap {
  flex: 1;
  min-width: 0;
}

.summary-card .summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.summary-card .summary-header p {
  margin: 0;
}

.privacy-toggle {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.privacy-toggle svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.privacy-toggle:hover {
  color: var(--ink);
  background: var(--paper);
}

.ledger-panel { overflow: hidden; border: 1px solid #ebe8e0; border-radius: 12px; background: var(--surface); box-shadow: 0 4px 18px rgba(61, 52, 33, .035); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 23px 24px 18px; }
.panel-tools { width: min(440px, 55%); display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 9px; }
.panel-tools > .status-filter { grid-column: 2; grid-row: 1; justify-self: end; }
.panel-tools > .search-wrap { grid-column: 1; grid-row: 1; width: 100%; }
.panel-heading h2 { margin: 0 0 5px; font-family: Georgia, "Times New Roman", serif; font-size: 21px; font-weight: 500; letter-spacing: -.2px; color: var(--gold); }
.panel-heading p { margin: 0; color: var(--muted); font-size: 11px; }
.search-wrap { width: min(300px, 45%); height: 38px; display: flex; flex: 1 1 auto; align-items: center; gap: 9px; padding: 0 10px; border: 1px solid #e9e6df; border-radius: 8px; background: #fff; }
.filter-row > #add-button { flex: 0 0 auto; white-space: nowrap; }
.search-wrap > svg { width: 16px; height: 16px; flex: 0 0 auto; fill: none; stroke: #96948c; stroke-linecap: round; stroke-width: 1.5; }
.search-wrap input { width: 100%; min-width: 0; padding: 0; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 12px; }
.search-wrap input::placeholder { color: #a09e96; }
.search-wrap kbd { min-width: 18px; padding: 2px 5px; border: 1px solid #ece9e2; border-radius: 4px; color: #a09e96; font-size: 10px; text-align: center; }
.filter-row { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 24px; border-top: 1px solid #f0eee8; }
.filter-group { display: flex; gap: 5px; }
.filter-chip { min-height: 29px; padding: 0 11px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: #85837b; cursor: pointer; font-size: 11px; }
.filter-chip:hover { background: #f8f6f1; }
.filter-chip.is-active { border-color: #e0b84a; background: #fbf0cc; color: #8a5f00; font-weight: 600; }
.filter-chip.is-active[data-category="Silver"] { border-color: #b4bcc4; background: #eceff2; color: #5a646d; }
.filter-chip.is-active[data-category="Diamond"] { border-color: #c4a6ea; background: #f1e8fb; color: #6b3fb5; }
.status-filter { position: relative; display: inline-flex; align-items: center; }
.status-filter select { min-width: 128px; height: 38px; appearance: none; padding: 0 27px 0 10px; border: 1px solid #e9e6df; border-radius: 6px; background: white; color: #66655e; cursor: pointer; font-size: 12px; }
.status-filter svg { position: absolute; right: 9px; width: 13px; pointer-events: none; fill: none; stroke: #89877f; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.4; }
.table-wrap { min-height: 160px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
thead { background: #fbfaf7; }
th { height: 37px; padding: 0 13px; border-top: 1px solid #f0eee8; border-bottom: 1px solid #f0eee8; color: #929087; font-size: 9px; font-weight: 600; letter-spacing: .55px; white-space: nowrap; }
th:first-child, td:first-child { padding-left: 24px; }
th:last-child, td:last-child { padding-right: 20px; }
td { height: 61px; padding: 9px 13px; border-bottom: 1px solid #f1efe9; color: var(--soft-ink); font-size: 11px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fdfcf9; }
.item-cell { min-width: 230px; }
.item-media { width: 56px; display: flex; flex: 0 0 56px; flex-direction: column; align-items: center; gap: 3px; }
.item-copy { min-width: 0; }
.item-thumbnail { width: 48px; height: 48px; display: block; border: 1px solid #ebe8df; border-radius: 8px; background: #f8f6f1; object-fit: cover; }
.item-thumbnail-default { padding: 5px; object-fit: contain; }
.item-thumb-button { display: block; padding: 0; border: 0; border-radius: 10px; background: transparent; cursor: pointer; line-height: 0; -webkit-tap-highlight-color: transparent; }
.item-thumb-button:hover .item-thumbnail { border-color: var(--gold); }
.item-thumb-button:active .item-thumbnail { transform: scale(.96); }
.item-thumbnail { transition: border-color .15s, transform .15s; }
.item-cell { display: flex; align-items: center; gap: 10px; }
.item-title { display: flex; align-items: center; gap: 7px; min-width: 0; }
.item-name { display: block; max-width: 245px; overflow: hidden; color: #34352f; font-size: 12px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.desktop-category-tag { flex: 0 0 auto; white-space: nowrap; }
.item-meta { display: none; }
.item-detail { display: block; max-width: 240px; overflow: hidden; margin-top: 4px; color: #a09e96; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.owner-name { color: #4a4b45; font-weight: 500; }
.category-tag { display: inline-flex; min-width: 42px; align-items: center; justify-content: center; padding: 3px 7px; border: 1px solid #ddd9cf; border-radius: 5px; background: #f3f1ec; color: #77756d; font-size: 9px; font-weight: 700; letter-spacing: .3px; }
.category-tag[data-category="Gold"] { border-color: #e0b84a; background: #fbf0cc; color: #8a5f00; }
.category-tag[data-category="Silver"] { border-color: #b4bcc4; background: #eceff2; color: #5a646d; }
.category-tag[data-category="Diamond"] { border-color: #c4a6ea; background: #f1e8fb; color: #6b3fb5; }
.mobile-category-tag { display: none; }
.weight-cell { color: #41423c; font-weight: 600; white-space: nowrap; }
.location-cell { max-width: 155px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-badge { display: inline-flex; align-items: center; gap: 5px; color: #72736a; white-space: nowrap; }
.status-badge::before { width: 6px; height: 6px; display: inline-block; border-radius: 50%; background: #8ca18d; content: ""; }
.status-badge[data-status="exchanged"] { color: var(--red); }
.status-badge[data-status="exchanged"]::before { background: #c07c6d; }
.status-badge[data-status="in-use"]::before { background: #c49a52; }
.row-actions { display: flex; align-items: center; gap: 2px; }
.row-edit { width: 29px; height: 29px; display: grid; place-items: center; border: 1px solid transparent; border-radius: 6px; background: transparent; color: #96948d; cursor: pointer; }
.row-edit:hover { border-color: #ece5d7; background: #f9f5ec; color: #83622f; }
.row-edit svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.45; }
.row-view { color: #76766f; }
.row-view:hover { color: #587d62; }
.purchase-date-cell { min-width: 115px; color: #55564f; white-space: nowrap; }
.action-cell { min-width: 78px; }
.empty-state { padding: 42px 16px; text-align: center; }
.empty-icon { width: 40px; height: 40px; display: inline-grid; place-items: center; margin-bottom: 11px; border-radius: 50%; background: #f6f2e9; color: #a9834d; font-size: 24px; }
.empty-state h3 { margin-bottom: 6px; font-family: Georgia, "Times New Roman", serif; font-size: 18px; font-weight: 500; }
.empty-state p { margin-bottom: 14px; color: var(--muted); font-size: 12px; }
.empty-state .button { min-height: 33px; }
.loading-state { padding: 37px; color: var(--muted); font-size: 12px; text-align: center; }
.panel-footer { min-height: 43px; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; border-top: 1px solid #f0eee8; color: #9a988f; font-size: 10px; }
.panel-footer strong { color: #64645d; font-weight: 600; }
.privacy-note { display: inline-flex; align-items: center; gap: 6px; }
.privacy-note svg { width: 14px; height: 14px; fill: none; stroke: #82927d; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.25; }
.page-note { margin: 16px 0 0; color: #a09e96; font-size: 10px; text-align: center; }

.edit-dialog { width: min(600px, calc(100% - 28px)); max-width: 600px; max-height: min(90vh, 800px); padding: 0; overflow: auto; border: 1px solid #e9e4d8; border-radius: 14px; background: #fffefa; color: var(--ink); box-shadow: 0 24px 80px rgba(37, 34, 27, .22); }
.edit-dialog::backdrop { background: rgba(38, 37, 32, .36); backdrop-filter: blur(2px); }
.edit-dialog form { padding: 25px; display: flex; flex-direction: column;}
.install-dialog { width: min(440px, calc(100% - 28px)); }
.install-dialog-content { padding: 25px; }
.install-dialog #install-instructions { line-height: 1.55; }
.dialog-heading { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.dialog-heading .eyebrow { margin: 0 0 8px; color: var(--gold); }
.dialog-heading h2 { margin: 0 0 5px; font-size: 25px; }
.dialog-heading p:last-child { margin: 0; color: var(--muted); font-size: 12px; }
.icon-button { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: white; color: #77766f; cursor: pointer; font-size: 22px; line-height: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px 13px; padding: 21px 0 24px; }
.form-field { display: grid; gap: 7px; min-width: 0; }
.form-field.is-wide { grid-column: 1 / -1; }
.form-field label { color: #66665f; font-size: 10px; font-weight: 600; }
.form-field input { width: 100%; min-width: 0; height: 44px; padding: 0 12px; border: 1px solid #e8e5dd; border-radius: 7px; background: white; color: var(--ink); font-size: 16px; }
.form-field input[type="date"] { display: block; max-width: 100%; min-width: 0; line-height: normal; -webkit-appearance: none; appearance: none; }
.form-field input:read-only { background: #f8f6f1; color: #66655e; }
.edit-dialog form.is-readonly .form-field input:read-only { background: #fff; color: var(--ink); }
.image-upload-field.is-readonly > input, .image-upload-field.is-readonly > p { display: none; }
.image-upload-field { display: grid; gap: 8px; padding-bottom: 20px; }
.image-upload-field > label { color: #66665f; font-size: 10px; font-weight: 600; }
.image-upload-field > input { width: 100%; padding: 10px; border: 1px solid #e8e5dd; border-radius: 7px; background: white; color: var(--soft-ink); font-size: 12px; }
.image-upload-field > p { margin: 0; color: var(--muted); font-size: 10px; }
.image-previews { display: flex; flex-wrap: wrap; gap: 7px; }
.image-preview-item { position: relative; }
.image-previews img { width: 54px; height: 54px; display: block; border: 1px solid #ebe8df; border-radius: 7px; background: #f8f6f1; object-fit: cover; }
.remove-image-button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; display: grid; place-items: center; padding: 0; border: 1px solid #e8e4da; border-radius: 50%; background: #fffefa; color: #8d554d; box-shadow: 0 1px 4px rgba(37, 34, 27, .14); cursor: pointer; font-size: 17px; line-height: 1; }
.remove-image-button:hover { border-color: #ddb8b0; background: #fdf0ed; }
.image-viewer-dialog { width: min(900px, calc(100% - 28px)); max-width: 900px; }
.image-viewer-content { padding: 25px; }
.image-viewer-gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 14px; max-height: min(72vh, 700px); overflow: auto; padding-top: 20px; }
.image-viewer-image { width: 100%; height: min(55vh, 480px); border: 1px solid #ebe8df; border-radius: 9px; background: #f8f6f1; object-fit: contain; }
.suggestion-field { position: relative; }
.suggestion-field.opens-up .suggestion-list { top: auto; bottom: calc(100% + 5px); }
.suggestion-field input { padding-right: 48px; }
.suggestion-toggle { position: absolute; z-index: 1; top: 2px; right: 2px; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 5px; background: #fff; color: #77766f; cursor: pointer; touch-action: manipulation; }
.suggestion-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.6; }
.suggestion-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.suggestion-list { position: absolute; z-index: 5; top: calc(100% + 5px); right: 0; left: 0; max-height: min(280px, 42vh); overflow-y: auto; overscroll-behavior: contain; border: 1px solid #e7e1d4; border-radius: 9px; background: white; box-shadow: 0 8px 24px rgba(37, 34, 27, .16); -webkit-overflow-scrolling: touch; }
.suggestion-option { width: 100%; min-height: 46px; display: block; padding: 10px 13px; border: 0; border-bottom: 1px solid #f1efe9; background: white; color: var(--ink); cursor: pointer; font: inherit; font-size: 16px; text-align: left; touch-action: manipulation; }
.suggestion-option:last-child { border-bottom: 0; }
.suggestion-option:hover, .suggestion-option[aria-selected="true"] { background: #f8f3e9; color: #795a2d; }
.suggestion-empty { padding: 13px; color: var(--muted); font-size: 14px; }
/*.dialog-actions { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 9px; padding: 17px 0 0; border-top: 1px solid var(--line); background: #fffefa; }*/
.dialog-actions {
  position: sticky;
  bottom: 0;
  z-index: 10; /* Added z-index to stay above form inputs & arrows */
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding: 17px 0 0;
  border-top: 1px solid var(--line);
  background: var(--surface); /* Keeps light/dark theme surface color */
}
.toast { position: fixed; z-index: 120; top: calc(env(safe-area-inset-top) + 104px); right: auto; left: 50%; width: min(1328px, calc(100vw - 112px)); max-width: none; min-height: 32px; box-sizing: border-box; display: flex; align-items: center; gap: 10px; padding: 6px 12px; transform: translate(-50%, -20px); border: 1px solid var(--line); border-radius: 0; background: var(--surface); color: var(--soft-ink); box-shadow: 0 8px 30px rgba(30, 30, 20, .18); font-size: 14px; line-height: 20px; opacity: 0; pointer-events: none; user-select: text; transition: opacity .4s ease, transform .55s cubic-bezier(.22, .8, .2, 1); }
.toast.is-visible { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.toast-message { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.toast-dismiss { flex: 0 0 auto; display: grid; place-items: center; width: 28px; height: 28px; margin-left: auto; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: inherit; font: inherit; font-size: 18px; line-height: 1; cursor: pointer; }
.toast-dismiss:hover { background: color-mix(in srgb, currentColor 8%, transparent); }
.toast-dismiss[hidden] { display: none; }
.toast:not(.is-error) { color: var(--green); }
.toast.is-error { border-color: #eed9d4; color: #9a5147; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

@media (max-width: 1000px) {
  .toast { width: calc(100vw - 64px); }
  .app-shell { padding-right: 32px; padding-left: 32px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  th, td { padding-right: 9px; padding-left: 9px; }
  th:first-child, td:first-child { padding-left: 18px; }
}
@media (max-width: 700px) {
  .app-shell {
    padding: 0 14px calc(30px + env(safe-area-inset-bottom));
  }

  .topbar {
    padding: max(8px, env(safe-area-inset-top)) 0 0 0;
  }

  .topbar-main {
    min-height: 48px;
    padding-bottom: 6px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .save-state-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    /* was space-between */
    width: 100%;
    box-sizing: border-box;
    padding: 6px 12px 8px 12px;
    border-top: 1px solid var(--line);
    background: var(--surface);
  }

  .save-state-bar .save-state {
    display: flex;
    flex-direction: row-reverse;
    /* dot on the right of the text */
    align-items: center;
    width: 100%;
    flex: 1;
    min-width: 0;
    font-size: 14px;
    text-align: right;
    /* was left */
  }

  .save-state-bar .save-state span:last-child {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
    /* add this */
  }
  .brand { min-width: 0; flex: 1 1 auto; gap: 8px; }
  .brand-mark { width: 36px; height: 36px; }
  .brand-copy { min-width: 0; flex: 1 1 auto;}
  .brand-copy strong { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
  .brand-copy span { font-size: 8px; }
  .save-state { min-height: 32px; font-size: 14px; }
  .toast { left: 14px; right: 14px; width: auto; min-height: 47px; padding: 10px 12px; transform: translateY(-20px); font-size: 14px; }
  .toast.is-visible { transform: translateY(0); }
  .topbar-actions { width: auto; flex: 0 0 auto; gap: 6px; margin-left: auto; }
  .actions-menu-trigger { width: 44px; min-height: 44px; padding: 0; font-size: 0; }
  main { padding-top: 24px; }
  .intro { align-items: flex-start; flex-direction: column; gap: 18px; margin-bottom: 20px; }
  .actions-menu-panel { max-height: min(70vh, 480px); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .actions-menu-panel .button { min-height: 46px; font-size: 14px; }
  .summary-grid { gap: 8px; margin-bottom: 16px; }
  .summary-card { min-height: 79px; gap: 9px; padding: 11px; }
  .summary-icon { width: 30px; height: 30px; flex-basis: 30px; }
  .summary-icon svg { width: 16px; height: 16px; }
  .summary-card p { margin-bottom: 4px; font-size: 12px; }
  .summary-card strong { font-size: 20px; }
  .panel-heading { align-items: stretch; flex-direction: column; padding: 18px 14px 14px; gap: 13px; }
  .panel-heading h2 { font-size: 23px; }
  .panel-heading p { font-size: 13px; }
  .panel-tools { width: 100%; gap: 7px; }
  .search-wrap { width: auto; min-width: 0; height: 46px; }
  .search-wrap input { font-size: 16px; }
  .search-wrap kbd { display: none; }
  .filter-row > #add-button { min-height: 46px; padding: 0 11px; font-size: 12px; }
  .filter-row { align-items: center; flex-wrap: wrap; padding: 10px 12px; gap: 6px; }
  .filter-group { flex-wrap: wrap; gap: 3px; }
  .filter-chip { min-height: 38px; padding: 0 9px; font-size: 12px; }
  .status-filter select { min-width: 118px; height: 40px; font-size: 12px; }
  .table-wrap { overflow: visible; }
  table, tbody { display: block; width: 100%; }
  thead { display: none; }
  tbody { padding: 0 10px 10px; }
  tbody tr { position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; margin-bottom: 10px; padding: 14px; border: 1px solid #eeebe4; border-radius: 12px; background: #fff; box-shadow: 0 2px 8px rgba(61, 52, 33, .035); }
  tbody tr:last-child { margin-bottom: 0; }
  td { min-width: 0; height: auto; display: block; padding: 0; border: 0; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
  td:nth-child(1) { grid-column: 1 / -1; grid-row: 1; padding: 0 0 12px 0; border-bottom: 1px solid #f0eee8; }
  td:nth-child(2) { display: none; }
  td:nth-child(3) { grid-column: 2; grid-row: 3; }
  td:nth-child(4) { grid-column: 1; grid-row: 2; }
  td:nth-child(5) { grid-column: 2; grid-row: 2; }
  td:nth-child(6) { grid-column: 1; grid-row: 3; overflow: visible; white-space: normal; }
  td:nth-child(7) { position: absolute; top: 10px; right: 9px; width: auto; padding: 0; }
  .item-cell { min-width: 0; }
  .item-media { width: 64px; flex-basis: 64px; }
  .item-thumbnail { width: 60px; height: 60px; border-radius: 10px; }
  .item-title { align-items: flex-start; flex-wrap: wrap; gap: 5px 7px; padding-right: 74px; }
  .item-name { max-width: 100%; font-size: 16px; white-space: normal; overflow-wrap: anywhere; }
  .desktop-category-tag { display: none; }
  .item-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-top: 7px; }
  .mobile-category-tag { display: inline-flex; gap: 4px; min-width: 0; min-height: 25px; padding: 2px 6px; font-size: 11px; }
  .mobile-category-tag svg { width: 14px; height: 14px; flex: 0 0 14px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.5; }
  .mobile-category-tag[data-category="Diamond"] svg { fill: currentColor; stroke: none; }
  .item-weight { color: #626159; font-size: 12px; font-weight: 600; }
  .item-detail { max-width: 100%; margin-top: 3px; font-size: 13px; white-space: normal; overflow-wrap: anywhere; }
  .owner-name, .purchase-cell, .purchase-date-cell, .location-cell { min-height: 58px; padding: 9px 10px; border-radius: 8px; background: #fbfaf7; }
  .owner-name::before, .purchase-cell::before, .purchase-date-cell::before, .location-cell::before { display: block; margin-bottom: 5px; color: #929087; content: attr(data-label); font-size: 10px; font-weight: 600; letter-spacing: .25px; }
  .location-cell { max-width: none; }
  .location-cell br { display: none; }
  .status-badge { margin-top: 5px; font-size: 12px; }
  .purchase-date-cell { min-width: 0; white-space: normal; }
  .row-edit { width: 38px; height: 38px; }
  .row-actions { gap: 1px; }
  .panel-footer { min-height: 48px; padding: 0 13px; font-size: 12px; }
  .page-note { margin-top: 13px; font-size: 12px; line-height: 1.6; }
  .edit-dialog { width: calc(100% - 16px); max-height: 94vh; max-height: 94dvh; border-radius: 12px; }
  .edit-dialog form { padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; }
  .install-dialog-content { padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); }
  .image-viewer-content { padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); }
  .image-viewer-gallery { grid-template-columns: 1fr; max-height: 72dvh; padding-top: 16px; }
  .image-viewer-image { height: min(58dvh, 520px); }
  .dialog-heading { gap: 10px; padding-bottom: 16px; }
  .dialog-heading h2 { font-size: 24px; }
  .dialog-heading p:last-child { font-size: 14px; }
  .icon-button { width: 42px; height: 42px; flex: 0 0 42px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 10px; padding: 18px 0; }
  .form-field.is-wide { grid-column: 1 / -1; }
  /* Keep text clear of the suggestion arrow (the generic .form-field input padding would otherwise override it) */
  .form-field .suggestion-field input { padding-right: 52px; }
  .form-field:not(.is-wide) input { padding-left: 11px; padding-right: 11px; }
  .form-field:not(.is-wide) .suggestion-field input { padding-right: 40px; }
  .form-field:not(.is-wide) .suggestion-toggle { width: 36px; }
  .suggestion-option { overflow-wrap: anywhere; }
  .form-field { gap: 6px; }
  .form-field label { font-size: 13px; }
  .form-field input { height: 50px; font-size: 16px; }
  .image-upload-field { padding-bottom: 18px; }
  .image-upload-field > label { font-size: 13px; }
  .image-upload-field > input { font-size: 16px; }
  .image-upload-field > p { font-size: 13px; }
  .suggestion-toggle { width: 46px; height: 46px; }
  .dialog-actions { gap: 10px; padding-top: 12px; }
  .dialog-actions .button { min-height: 46px; flex: 1; font-size: 14px; }
  .dialog-actions .button-danger[hidden] { display: none; }
}

@media (max-width: 380px) {
  .app-shell { padding-right: 10px; padding-left: 10px; }
  .brand-copy strong { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .summary-card { gap: 7px; padding: 9px; }
  .summary-icon { width: 26px; height: 26px; flex-basis: 26px; }
  .summary-icon svg { width: 14px; height: 14px; }
  .summary-card p { font-size: 11px; }
  .summary-card strong { font-size: 18px; }
  .filter-row { padding-right: 8px; padding-left: 8px; }
  .filter-chip { padding: 0 7px; font-size: 11px; }
  .status-filter select { min-width: 108px; padding-left: 8px; }
  tbody { padding-right: 7px; padding-left: 7px; }
  tbody tr { gap: 9px; padding: 12px 10px; }
  .owner-name, .purchase-cell, .purchase-date-cell, .location-cell { padding: 8px; }
  .item-cell { gap: 8px; }
  .item-media { width: 54px; flex-basis: 54px; }
  .item-thumbnail { width: 50px; height: 50px; }
  .item-title { padding-right: 70px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

[data-theme="dark"] body {
  background:
    radial-gradient(
      ellipse at 85% 4%,
      rgba(208,162,90,.12),
      transparent 30rem
    ),
    var(--paper);
}

[data-theme="dark"] .summary-card,
[data-theme="dark"] .ledger-panel,
[data-theme="dark"] .edit-dialog {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
[data-theme="dark"] .toast.is-error {
  background: #342120;
  border-color: #613632;
  color: #f8e9e6;
}
[data-theme="dark"] .actions-menu-panel,
[data-theme="dark"] tbody tr {
  background: var(--surface);
  border-color: var(--line);
}

[data-theme="dark"] .search-wrap,
[data-theme="dark"] .status-filter select,
[data-theme="dark"] .form-field input,
[data-theme="dark"] .image-upload-field > input,
[data-theme="dark"] .suggestion-list,
[data-theme="dark"] .suggestion-option {
  background: #252525;
  border-color: var(--line);
  color: var(--ink);
}

[data-theme="dark"] thead {
  background: #242424;
}

[data-theme="dark"] tbody tr:hover {
  background: #2a2a2a;
}

[data-theme="dark"] .button-quiet,
[data-theme="dark"] .icon-button {
  background: #252525;
  border-color: var(--line);
  color: var(--ink);
}

body,
.summary-card,
.ledger-panel,
.edit-dialog,
.toast {
  transition:
    background-color 0.25s ease,
    color 0.25s ease,
    border-color 0.25s ease;
}

/* List item text */
[data-theme="dark"] .item-name {
  color: #f4f2ec;
}

[data-theme="dark"] .item-detail {
  color: #c0bbb1;
}

[data-theme="dark"] .owner-name,
[data-theme="dark"] .purchase-date-cell,
[data-theme="dark"] .weight-cell,
[data-theme="dark"] .location-cell,
[data-theme="dark"] td {
  color: #e0dbd2;
}

/* Table headers */
[data-theme="dark"] th {
  color: #bdb8af;
}

/* Footer and secondary text */
[data-theme="dark"] .panel-footer,
[data-theme="dark"] .page-note,
[data-theme="dark"] #result-count {
  color: #b8b5ae;
}

/* Mobile cards */
[data-theme="dark"] .owner-name,
[data-theme="dark"] .purchase-cell,
[data-theme="dark"] .purchase-date-cell,
[data-theme="dark"] .location-cell {
  background: #252525;
}

/* Search icon */
[data-theme="dark"] .search-wrap svg {
  stroke: #d0cbc2;
}

/* Placeholder text */
[data-theme="dark"] input::placeholder {
  color: #8f8b84;
}

[data-theme="dark"] .button-quiet:hover:not(:disabled) {
  background: #2c2c2c;
  border-color: #4a4a4a;
  color: #f4f2ec;
}

[data-theme="dark"] .actions-menu-panel .button-quiet {
  background: transparent;
  border-color: transparent;
}

[data-theme="dark"] .actions-menu-panel .button-quiet:hover:not(:disabled) {
  background: #2a2a2a;
  border-color: #383838;
  color: #ffffff;
}

[data-theme="dark"] .actions-menu-heading {
  color: #98938b;
}

[data-theme="dark"] .dialog-actions {
  background: var(--surface);
}

[data-theme="dark"] .edit-dialog form.is-readonly .form-field input:read-only {
  background: #252525;
  color: var(--ink);
}

[data-theme="dark"] .category-tag {
  background: #262626;
  border-color: #3d3d3d;
  color: #a9a59d;
}

[data-theme="dark"] .category-tag[data-category="Gold"] {
  background: #33290f;
  border-color: #7a5f1f;
  color: #f0c75e;
}

[data-theme="dark"] .category-tag[data-category="Silver"] {
  background: #25292d;
  border-color: #5b656d;
  color: #c9d1d8;
}

[data-theme="dark"] .category-tag[data-category="Diamond"] {
  background: #2c2238;
  border-color: #6d5190;
  color: #c7a6f0;
}

[data-theme="dark"] .item-thumbnail,
[data-theme="dark"] .image-viewer-image {
  background: #252525;
  border-color: var(--line);
}

[data-theme="dark"] .suggestion-toggle {
  background: #252525;
  color: var(--ink);
  border-color: var(--line);
}

[data-theme="dark"] .filter-chip {
  color: #b8b5ae;
}

[data-theme="dark"] .filter-chip:hover {
  background: #2a2a2a;
}

[data-theme="dark"] .filter-chip.is-active {
  border-color: #7a5f1f;
  background: #33290f;
  color: #f0c75e;
}

[data-theme="dark"] .filter-chip.is-active[data-category="Silver"] {
  border-color: #5b656d;
  background: #25292d;
  color: #c9d1d8;
}

[data-theme="dark"] .filter-chip.is-active[data-category="Diamond"] {
  border-color: #6d5190;
  background: #2c2238;
  color: #c7a6f0;
}

/* Dark theme background and icon colors for summary cards */
[data-theme="dark"] .summary-icon-weight {
  background: #253126;
  color: #8fb392;
}

[data-theme="dark"] .summary-icon-stored {
  background: #2f2516;
  color: #d0a25a;
}

[data-theme="dark"] .summary-icon-items {
  background: #2f2516;
  color: #d0a25a;
}

[data-theme="dark"] .summary-icon-in-use {
  background: #2f2516;
  color: #d0a25a;
}

[data-theme="dark"] .row-edit:hover {
  border-color: #4a3d28;
  background: #2a2419;
  color: #f4d38c;
}

[data-theme="dark"] .row-view:hover {
  background: #222d24;
  color: #8fb392;
}

[data-theme="dark"] .button-danger {
  border-color: #4a2926;
  background: #342120;
  color: #d68b85;
}

[data-theme="dark"] .button-danger:hover:not(:disabled) {
  border-color: #613632;
  background: #422b29;
}

/* Increase table data and general text readability */
td {
  font-size: 13px; /* Increased from 11px */
}

/* Increase search and input text sizes */
.search-wrap input, 
.filter-chip {
  font-size: 13px; /* Increased from 11px */
}

/* Increase summary card descriptions and numbers */
.summary-card p {
  font-size: 12px; /* Increased from 11px */
}

/* Increase form field input text inside dialogs */
.form-field input {
  font-size: 17px; /* Ensures text in dialogs is nice and clear */
}

.app-version {
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .4px;
}

[data-theme="dark"] .app-version {
  color: #b8b5ae;
}

/* ==========================================================================
   iPhone & iPhone Pro Max Optimized Mobile Styles
   ========================================================================== */

/* 1. Prevent iOS Auto-Zoom on form focus */
@media (max-width: 768px) {
  input[type="text"],
  input[type="search"],
  input[type="number"],
  input[type="date"],
  select,
  textarea {
    font-size: 16px !important; /* Disables unwanted Safari auto-zoom */
  }
}

/* 2. Specific iPhone Pro Max & Large Phone Optimization (Up to 440px) */
@media (max-width: 440px) {
  /* Remove top padding from body so the app paints edge-to-edge natively */
  body {
    padding-top: 0;
    margin: 0;
  }

  .app-shell {
    padding-right: max(14px, env(safe-area-inset-right));
    padding-left: max(14px, env(safe-area-inset-left));
    padding-bottom: max(32px, calc(16px + env(safe-area-inset-bottom)));
  }

  /* Fix the topbar to the top edge and use safe-area padding to push content below the Dynamic Island */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 64px;
    padding-top: env(safe-area-inset-top);
    background-color: var(--surface);
    border-bottom: 1px solid var(--line);
  }

  .theme-toggle,
  .actions-menu-trigger {
    min-width: 44px;
    min-height: 44px; /* Standard Apple 44pt touch target */
  }

  .actions-menu-panel {
    max-height: calc(100vh - 90px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-height: calc(100dvh - 90px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  /* 2x2 Summary Cards layout styled for Pro Max display */
  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 18px;
  }

  .summary-card {
    padding: 12px 14px;
    border-radius: 12px;
  }

  .summary-card strong {
    font-size: 19px;
  }

  /* Filter chips touch scrolling */
  .filter-row {
    padding: 10px 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Hide scrollbar for cleaner look */
  }
  
  .filter-row::-webkit-scrollbar {
    display: none;
  }

  .filter-chip {
    min-height: 40px;
    padding: 0 14px;
    font-size: 13px;
    white-space: nowrap;
  }

  /* Card view list items on mobile */
  tbody tr {
    padding: 16px;
    border-radius: 14px;
    gap: 12px;
  }

  .item-name {
    font-size: 17px;
    font-weight: 600;
  }

  /* Dialogs modal adjustments for Pro Max tall screen height */
  .edit-dialog {
    width: calc(100% - 20px);
    max-height: calc(88vh - env(safe-area-inset-top));
    border-radius: 18px;
  }

  .edit-dialog form {
    padding: 20px 18px max(20px, calc(12px + env(safe-area-inset-bottom)));
  }

  .dialog-actions {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .dialog-actions .button {
    min-height: 48px; /* Touch-friendly button height */
    font-size: 15px;
    border-radius: 10px;
  }

  .toast {
    top: calc(env(safe-area-inset-top) + 104px);
    right: max(10px, env(safe-area-inset-right));
    left: max(10px, env(safe-area-inset-left));
    width: auto;
    max-width: none;
    border-radius: 0;
  }

  /* Edit & View Dialog Modal container */
  .edit-dialog {
    width: calc(100% - 20px);
    max-height: 88dvh; /* Uses dynamic viewport height for iOS Safari toolbars */
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  }

  /* Modal Form Padding & Layout */
  .edit-dialog form {
    padding: 20px 18px max(18px, env(safe-area-inset-bottom));
  }

  /* Dialog Header styling */
  .dialog-heading {
    padding-bottom: 14px;
    margin-bottom: 4px;
  }

  .dialog-heading h2 {
    font-size: 22px;
    letter-spacing: -.4px;
  }

  /* Form Fields spacing inside the dialog */
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 10px;
    padding: 14px 0 18px;
  }

  .form-field input {
    height: 48px;
    padding: 0 14px;
    font-size: 16px; /* Prevents Safari auto-zoom on focus */
    border-radius: 9px;
  }

  /* Image Upload Previews inside Editor */
  .image-upload-field {
    padding-bottom: 14px;
  }

  .image-previews {
    gap: 10px;
  }

  .image-previews img {
    width: 60px;
    height: 60px;
    border-radius: 9px;
  }

  /* Sticky Footer Actions Bar (Delete, Cancel, Save) */
  .dialog-actions {
    position: sticky;
    bottom: 0;
    z-index: 10;
    display: flex;
    gap: 10px;
    padding: 14px 0 max(4px, env(safe-area-inset-bottom));
    margin-top: 4px;
    border-top: 1px solid var(--line);
    background: var(--surface);
  }

  .dialog-actions .button {
    min-height: 48px; /* High touch-target compliance */
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    border-radius: 11px;
  }

 /* Image Viewer Gallery Modal (when clicking view photos) */
  .image-viewer-dialog {
    width: calc(100% - 16px);
    border-radius: 20px;
  }

  .image-viewer-content {
    padding: 20px 16px max(16px, env(safe-area-inset-bottom));
  }

  .image-viewer-gallery {
    grid-template-columns: 1fr;
    max-height: 70dvh;
  }

  .image-viewer-image {
    height: min(54dvh, 440px);
    border-radius: 12px;
  }
}


/* ==========================
   Biometric Lock
   ========================== */

.app-shell.locked {
  visibility: hidden;
}

.biometric-lock-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;

  display: flex;
  align-items: center;
  justify-content: center;

  background:
    radial-gradient(
      circle at top right,
      rgba(168,121,50,.18),
      transparent 30rem
    ),
    var(--paper);
}

.biometric-card {
  width: min(360px, calc(100vw - 32px));

  padding: 32px;

  border: 1px solid var(--line);
  border-radius: 20px;

  background: var(--surface);

  text-align: center;

  box-shadow:
    0 20px 60px rgba(0,0,0,.15);
}

.biometric-card h2 {
  margin-bottom: 8px;
}

.biometric-card p {
  color: var(--muted);
  margin-bottom: 24px;
}

.biometric-card #unlock-button {
  width: 100%;
}

.biometric-card #lock-reset-prompt {
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.biometric-card #lock-reset-button {
  border: 0;
  padding: 4px;
  background: transparent;
  color: var(--red);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.biometric-card #lock-reset-button:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
  border-radius: 3px;
}

.biometric-icon {
  width: 72px;
  height: 72px;

  margin: 0 auto 16px;

  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 18px;

  background: var(--gold-wash);

  font-size: 34px;
}

[data-theme="dark"] .biometric-card {
  box-shadow:
    0 20px 60px rgba(0,0,0,.45);
}

[data-theme="dark"] .biometric-icon {
  background: #2f2516;
  color: #f4d38c;
}


/* ==========================================================================
   Mobile ledger toolbar: iPhone Pro Max / OnePlus Nord
   Layout:  [Ledger / Showing…]            [Any location ▾]
            [ Search…                    ] [+ Add an item ]
            [All pieces | Gold | Silver | Diamond]
   ========================================================================== */
@media (max-width: 700px) {
  .ledger-panel { position: relative; }

  /* Location dropdown sits at the right end of the search row. */
  .status-filter { position: relative; width: 150px; margin: 0; z-index: auto; }
  .status-filter select {
    width: 100%;
    min-width: 0;
    height: 42px;
    padding: 0 28px 0 12px;
  }
  .status-filter svg { top: 50%; right: 12px; width: 16px; height: 16px; transform: translateY(-50%); stroke: #89877f; stroke-width: 1.8; }

  /* Search and location share a row; Add stays in the heading's right corner. */
  .panel-heading > div:first-child { position: relative; max-width: none; padding-right: 164px; }
  .panel-heading > div:first-child > #add-button { position: absolute; top: 0; right: 0; width: 150px; min-height: 46px; padding: 0; }
  .panel-tools { width: 100%; grid-template-columns: minmax(0, 1fr) 150px; gap: 8px; }
  .panel-tools > .status-filter { grid-column: 2; grid-row: 1; justify-self: stretch; }
  .panel-tools > .search-wrap { grid-column: 1; grid-row: 1; min-width: 0; width: 100%; }

  /* Category chips: four equal-width chips on one line */
  .filter-row {
    display: block;
    padding: 12px 14px;
    overflow: visible;
    border-top: 1px solid var(--line); /* fixes the bright white line in dark mode */
  }
  .filter-group {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    flex-wrap: nowrap;
  }
  .filter-chip {
    min-height: 40px;
    padding: 0 4px;
    font-size: 13px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* Very narrow phones (≤ 380px) */
@media (max-width: 380px) {
  .status-filter { width: 130px; }
  .panel-heading > div:first-child { padding-right: 144px; }
  .panel-heading > div:first-child > #add-button { width: 130px; padding: 0 10px; font-size: 12px; }
  .panel-tools { grid-template-columns: minmax(0, 1fr) 130px; }
  .filter-group { gap: 4px; }
  .filter-chip { font-size: 12px; }
}

/* ==========================================================================
   Symmetry polish: matched right column + segmented category control
   ========================================================================== */
@media (max-width: 700px) {
  /* Dropdown and Add button: same width + height, right edges aligned */
  .status-filter { width: 150px; }
  .status-filter select { height: 46px; font-size: 16px !important; }
  .panel-heading > div:first-child > #add-button { width: 150px; min-height: 46px; padding: 0; }


  /* Category chips as a full-width segmented control */
  .filter-row { padding: 12px 14px 14px; }
  .filter-group {
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(127, 127, 127, .08);
  }
  .filter-chip {
    min-height: 38px;
    border-radius: 9px;
    font-size: 13px;
  }
}

@media (max-width: 380px) {
  .status-filter { width: 130px; }
  .panel-heading > div:first-child > #add-button { width: 130px; }
  .filter-chip { font-size: 12px; }
}

@media (max-width: 700px) {
  
  /* Where scrollIntoView lands the Ledger: just below the notch / Dynamic Island */
  .ledger-panel { scroll-margin-top: calc(env(safe-area-inset-top, 0px) + 8px); }

  /* Hide the header with a transform: it keeps its space, so nothing shifts */
  .topbar { transition: transform .2s ease; }
  body.search-active .topbar,
  body.search-has-text .topbar { transform: translateY(-100%); }

  /* Extra room at the bottom so filtering can't pull the scroll position back */
  body.search-active .app-shell { padding-bottom: 50dvh; }
  
  /* ---------- Animated search expand / Add button collapse (mobile) ---------- */
  .panel-heading > div:first-child > #add-button {
    overflow: hidden;
    white-space: nowrap;
    transition: width .25s ease, margin .25s ease, padding .25s ease,
                border-width .25s ease, opacity .18s ease;
  }
  body.search-active .panel-heading > div:first-child > #add-button,
  body.search-has-text .panel-heading > div:first-child > #add-button {
    width: 0;
    min-width: 0;
    margin-left: -8px;
    padding: 0;
    border-width: 0;
    opacity: 0;
    pointer-events: none;
  }

  body.search-active .panel-tools,
  body.search-has-text .panel-tools {
    grid-template-columns: minmax(0, 1fr);
  }
  body.search-active .panel-tools > .status-filter,
  body.search-has-text .panel-tools > .status-filter {
    display: none;
  }
  body.search-active .panel-tools > .search-wrap,
  body.search-has-text .panel-tools > .search-wrap {
    grid-column: 1;
    grid-row: 1;
  }
}

/* ==========================================================================
   Dark theme: soften bright separator lines
   ========================================================================== */
:root[data-theme="dark"] {
  --row-line: rgba(255, 255, 255, .07);
}

:root[data-theme="dark"] .topbar { border-bottom-color: var(--line); }
:root[data-theme="dark"] .filter-row,
:root[data-theme="dark"] .panel-footer { border-top-color: var(--row-line); }
:root[data-theme="dark"] th {
  border-top-color: var(--row-line);
  border-bottom-color: var(--row-line);
}
:root[data-theme="dark"] td { border-bottom-color: var(--row-line); }
:root[data-theme="dark"] tbody tr:last-child td { border-bottom: 0; }

/* ---------- Clear (×) button inside the search box ---------- */
.search-clear {
  display: none;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  margin: -6px -6px -6px 0;         /* larger tap target, same visual size */
  padding: 0;
  border: 0;
  background: transparent;
  place-items: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.search-clear svg { width: 20px; height: 20px; }
.search-clear circle { fill: #b9b6ad; stroke: none; }
.search-clear path { fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; }
:root[data-theme="dark"] .search-clear circle { fill: #77736c; }
:root[data-theme="dark"] .search-clear path { stroke: #1d1d1d; }
.search-clear:active circle { opacity: .75; }

/* Show it only when the box has text; hide the "/" hint then */
.search-wrap input:not(:placeholder-shown) ~ .search-clear { display: grid; }
.search-wrap input:focus ~ .search-clear { display: grid; }
.search-wrap input:not(:placeholder-shown) ~ kbd { display: none; }
.search-wrap input:focus ~ kbd { display: none; }

/* Hide the browser's own clear icon so there aren't two */
.search-wrap input[type="search"]::-webkit-search-cancel-button,
.search-wrap input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}



@media (prefers-reduced-motion: reduce) {
  .panel-heading > div:first-child > #add-button { transition: none; }
}

@media (max-width: 700px) {
  /* Mobile cards: divider under the item name/thumbnail */
  :root[data-theme="dark"] td:nth-child(1) { border-bottom-color: var(--row-line); }
  :root[data-theme="dark"] tbody tr { border-color: var(--line); }

  .summary-card:has(.summary-icon-items),
  .summary-card:has(.summary-icon-in-use) {
    display: none !important;
  }

  .intro,
  .summary-grid {
    overflow: hidden;
    opacity: 1;
    transform: translateY(0);
    max-height: 500px;
    transition:
      opacity .25s ease,
      transform .25s ease,
      max-height .25s ease,
      margin .25s ease;
  }

  body.search-active .intro,
  body.search-has-text .intro,
  body.search-active .summary-grid,
  body.search-has-text .summary-grid {
    opacity: 0;
    transform: translateY(-12px);
    max-height: 0;
    margin-bottom: 0;
    pointer-events: none;
  }

  /* Hide the category chips only */
  .filter-group { display: none; }

  /* Keep the category row collapsed on mobile. */
  .filter-row {
    display: block;
    min-height: 0;
    height: 0;
    padding: 0;
    border: 0;
    overflow: visible;
  }

}

/* Other light edges that can glow in dark mode */
:root[data-theme="dark"] .brand-mark { border-color: var(--line); background: #252525; }
:root[data-theme="dark"] .dialog-heading,
:root[data-theme="dark"] .actions-menu-group + .actions-menu-group { border-color: var(--row-line); }
:root[data-theme="dark"] .suggestion-option { border-bottom-color: var(--row-line); }

/* Dark theme: calmer text in the view / edit item dialog */
:root[data-theme="dark"] .form-field input,
:root[data-theme="dark"] .edit-dialog form.is-readonly .form-field input:read-only,
:root[data-theme="dark"] .image-upload-field > input,
:root[data-theme="dark"] .suggestion-option,
:root[data-theme="dark"] .suggestion-toggle { color: var(--field-text); }
:root[data-theme="dark"] .form-field label,
:root[data-theme="dark"] .image-upload-field > label { color: var(--field-label); }
:root[data-theme="dark"] .dialog-heading h2 { color: var(--gold); } /* matches the eyebrow label above it */
:root[data-theme="dark"] .suggestion-option:hover,
:root[data-theme="dark"] .suggestion-option[aria-selected="true"] { background: var(--gold-wash); color: var(--gold-dark); }

/* Very narrow phones (<=340px): half-width fields get too cramped, so stack them */
@media (max-width: 340px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-field:not(.is-wide) input { padding-left: 14px; padding-right: 14px; }
  .form-field:not(.is-wide) .suggestion-field input { padding-right: 52px; }
  .form-field:not(.is-wide) .suggestion-toggle { width: 46px; }
}

/* Item category field in the view / edit dialog: tinted like its list tag */
.edit-dialog form .form-field input.category-input[data-category="Gold"] { border-color: #e0b84a; background: #fbf0cc; color: #8a5f00; font-weight: 600; }
.edit-dialog form .form-field input.category-input[data-category="Silver"] { border-color: #b4bcc4; background: #eceff2; color: #5a646d; font-weight: 600; }
.edit-dialog form .form-field input.category-input[data-category="Diamond"] { border-color: #c4a6ea; background: #f1e8fb; color: #6b3fb5; font-weight: 600; }
:root[data-theme="dark"] .edit-dialog form .form-field input.category-input[data-category="Gold"] { border-color: #7a5f1f; background: #33290f; color: #f0c75e; }
:root[data-theme="dark"] .edit-dialog form .form-field input.category-input[data-category="Silver"] { border-color: #5b656d; background: #25292d; color: #c9d1d8; }
:root[data-theme="dark"] .edit-dialog form .form-field input.category-input[data-category="Diamond"] { border-color: #6d5190; background: #2c2238; color: #c7a6f0; }
