:root {
  color-scheme: dark;
  --bg: #17191c;
  --panel: #1d2024;
  --panel-2: #24282d;
  --panel-3: #2a2f35;
  --line: #373d44;
  --line-soft: #2d3238;
  --text: #f5f6f7;
  --muted: #aeb5bd;
  --subtle: #77808a;
  --gold: #f2c94c;
  --gold-dark: #72581a;
  --gold-soft: rgba(242, 201, 76, .13);
  --ok: #8fc5a2;
  --danger: #e58a8a;
  --radius: 4px;
  --shadow: 0 24px 80px rgba(0, 0, 0, .44);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: default; opacity: .42; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { min-height: 100vh; padding: 18px 24px 16px; display: flex; flex-direction: column; gap: 12px; }
.app-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 56px; }
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 14px; }
.brand strong { display: block; color: var(--gold); font-size: clamp(1.35rem, 2vw, 2rem); line-height: 1; letter-spacing: .025em; }
.brand small { display: block; color: var(--muted); font-size: .93rem; margin-top: 10px; }
.italian-flag { width: 36px; height: 24px; border: 1px solid rgba(255,255,255,.22); display: grid; grid-template-columns: repeat(3, 1fr); flex: 0 0 auto; box-shadow: 0 3px 8px rgba(0,0,0,.28); }
.italian-flag i:nth-child(1) { background: #168348; }
.italian-flag i:nth-child(2) { background: #f2f2ed; }
.italian-flag i:nth-child(3) { background: #ce2b37; }
.header-actions { display: flex; align-items: center; gap: 14px; }
.version { color: var(--subtle); font-size: .78rem; letter-spacing: .13em; }
.nikonland-link { color: var(--text); text-decoration: none; border-bottom: 1px solid var(--gold); padding: 8px 0 6px; font-weight: 650; font-size: .9rem; }

.toolbar { display: grid; grid-template-columns: minmax(240px, 1fr) auto minmax(190px, 240px) auto; gap: 12px; align-items: center; }
.search-field { position: relative; display: block; }
.search-field svg { position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); stroke: var(--subtle); stroke-width: 1.8; fill: none; }
.search-field input, select { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); color: var(--text); padding: 0 13px; outline: none; }
.search-field input { padding-left: 42px; }
.search-field input:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(242,201,76,.11); }
.segmented { display: flex; gap: 7px; }
.filter-button { min-width: 78px; height: 42px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); color: var(--muted); font-weight: 700; }
.filter-button.active { background: #f4f4f2; color: #111417; border-color: #f4f4f2; }
.profile-count { min-width: 130px; color: var(--subtle); font-size: .88rem; }

.workspace { flex: none; display: grid; grid-template-columns: minmax(300px, .82fr) minmax(500px, 1.55fr) minmax(310px, .82fr); gap: 20px; height: clamp(620px, calc(100dvh - 270px), 790px); min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); min-width: 0; }
.panel-title-row { padding: 15px 15px 12px; display: flex; justify-content: space-between; align-items: center; }
.panel-title-row h1 { margin: 0; font-size: 1rem; letter-spacing: .015em; }
.tiny-badge { color: var(--gold); font-size: .78rem; }
.catalog-panel { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.catalog-head { display: grid; grid-template-columns: 1fr 84px 48px; gap: 8px; padding: 8px 13px; background: #f1f1ef; color: #1f2225; font-size: .78rem; font-weight: 650; }
.catalog-list { overflow-y: auto; min-height: 0; flex: 1; scrollbar-color: #626a73 var(--panel); scrollbar-width: thin; }
.catalog-row { width: 100%; min-height: 43px; display: grid; grid-template-columns: 1fr 84px 48px; gap: 8px; align-items: center; border: 0; border-bottom: 1px solid var(--line-soft); padding: 7px 13px; background: transparent; color: var(--muted); text-align: left; }
.catalog-row:hover { background: var(--panel-2); color: var(--text); }
.catalog-row.active { background: linear-gradient(90deg, #826321, #6c511a); color: #fff; }
.catalog-row .film-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catalog-row .film-type { color: var(--gold); font-size: .78rem; font-weight: 700; }
.catalog-row .film-status { color: var(--ok); font-size: .76rem; }
.catalog-empty { padding: 28px 18px; color: var(--subtle); line-height: 1.5; }

.preview-panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.sample-picker { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; flex: 0 0 auto; }
.sample-picker button { padding: 0; height: clamp(60px, 5vw, 86px); overflow: hidden; border: 2px solid var(--line); background: #101214; }
.sample-picker img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sample-picker button[aria-pressed="true"] { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.sample-picker button:hover { border-color: var(--gold); }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.preview-frame { position: relative; margin: 0; background: #101214; border: 1px solid var(--line-soft); min-height: 180px; flex: 1 1 0; overflow: hidden; }
.preview-frame img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; }
.preview-frame img[hidden], .preview-loading[hidden] { display: none; }
.preview-loading { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; text-align: center; background: #101214; color: var(--muted); font-size: .9rem; }
.preview-caption { color: var(--subtle); font-size: .8rem; font-style: italic; margin: 9px 0 0; }
.profile-info { min-height: 0; max-height: 148px; overflow-y: auto; flex-shrink: 0; padding: 12px 0; display: flex; justify-content: space-between; gap: 15px; }
.profile-info h2 { margin: 0 0 10px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.55rem, 2.2vw, 2.25rem); line-height: 1.05; }
.profile-meta { margin: 0; color: var(--muted); font-size: .88rem; line-height: 1.55; }
.profile-origin { margin: 7px 0 0; color: var(--subtle); font-size: .85rem; font-style: italic; }
.type-badge { align-self: flex-start; flex: 0 0 auto; padding: 6px 9px; border: 1px solid var(--gold-dark); color: var(--gold); font-size: .72rem; font-weight: 800; letter-spacing: .08em; }
.primary-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; flex-shrink: 0; }
.button { min-height: 46px; border-radius: var(--radius); border: 1px solid transparent; padding: 10px 15px; font-weight: 750; }
.button span { margin-left: 5px; }
.button-primary { background: #f5f5f3; color: #111417; }
.button-primary:hover:not(:disabled) { background: var(--gold); }
.button-secondary { background: transparent; color: var(--text); border-color: #edf0f2; }
.button-secondary:hover:not(:disabled) { border-color: var(--gold); color: var(--gold); }
.button-quiet { background: var(--panel-2); color: var(--muted); border-color: var(--line); }
.button-quiet:hover:not(:disabled) { color: var(--text); border-color: var(--subtle); }
.full { width: 100%; }

.filmbox-panel { padding: 16px; display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow-y: auto; }
.box-picker label { display: block; color: var(--gold); font-size: .88rem; font-weight: 850; margin-bottom: 8px; }
.box-description { min-height: 0; max-height: 0; overflow: hidden; margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.45; opacity: 0; transition: max-height .2s ease, opacity .2s ease, margin .2s ease; }
.box-description.visible { max-height: 84px; opacity: 1; margin-top: 8px; }
.filmbox-heading { display: flex; align-items: baseline; gap: 9px; margin-top: 4px; }
.filmbox-heading h2 { margin: 0; color: var(--gold); font-size: 1.06rem; letter-spacing: .02em; }
.filmbox-heading strong { color: var(--gold); }
.slot-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.slot-row { display: grid; grid-template-columns: 30px 1fr; align-items: center; min-height: 42px; border-bottom: 1px solid var(--line); color: var(--muted); cursor: pointer; }
.slot-row:hover { background: var(--panel-2); }
.slot-row.selected { background: var(--gold-soft); color: var(--text); }
.slot-number { color: var(--gold); text-align: center; font-size: .8rem; }
.slot-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; padding-right: 6px; }
.slot-actions { display: grid; grid-template-columns: 1.25fr 1fr 1fr; gap: 10px; }
.slot-actions button, .icon-button { height: 38px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); color: var(--muted); }
.slot-actions button:hover:not(:disabled), .icon-button:hover:not(:disabled) { border-color: var(--gold); color: var(--text); }
.personal-row { display: grid; grid-template-columns: 1fr 42px; gap: 8px; }
.icon-button.danger { color: var(--danger); font-size: 1.35rem; }
.button-download { margin-top: auto; background: var(--gold); color: #111417; font-size: 1rem; }
.button-download:hover:not(:disabled) { background: #ffda5c; }
.download-note { margin: -4px 2px 0; color: var(--subtle); font-size: .75rem; line-height: 1.4; }

.filmstrip-section { border-top: 1px solid var(--line); padding-top: 12px; display: grid; grid-template-columns: 210px 1fr; gap: 14px; align-items: stretch; }
.filmstrip-label { display: flex; flex-direction: column; justify-content: center; }
.filmstrip-label strong { color: var(--gold); font-size: .87rem; }
.filmstrip-label span { color: var(--subtle); font-size: .75rem; line-height: 1.4; margin-top: 5px; }
.filmstrip { display: grid; grid-template-columns: repeat(12, minmax(72px, 1fr)); gap: 6px; min-width: 0; }
.filmstrip button { position: relative; aspect-ratio: 3 / 2; padding: 0; border: 2px solid var(--line); background: var(--panel); overflow: hidden; }
.filmstrip button:hover, .filmstrip button.active { border-color: var(--gold); }
.filmstrip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.filmstrip span { position: absolute; inset: auto 0 0; padding: 16px 5px 4px; color: #fff; font-size: .62rem; background: linear-gradient(transparent, rgba(0,0,0,.84)); opacity: 0; transition: opacity .15s; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filmstrip button:hover span, .filmstrip button:focus span { opacity: 1; }
.app-footer { display: flex; justify-content: space-between; gap: 20px; color: var(--subtle); font-size: .73rem; }

dialog { border: 1px solid #4a5057; color: var(--text); background: var(--bg); padding: 0; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(3px); }
.note-dialog { width: min(1420px, calc(100vw - 42px)); max-height: calc(100vh - 42px); }
.dialog-shell { padding: clamp(22px, 3vw, 44px); }
.dialog-header { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; }
.eyebrow { color: var(--gold); font-size: .83rem; font-weight: 850; letter-spacing: .08em; }
.dialog-header h2, .save-shell h2 { margin: 12px 0 10px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 3vw, 3.2rem); }
.dialog-close { width: 42px; height: 42px; border: 0; background: transparent; color: var(--muted); font-size: 2rem; line-height: 1; }
.note-layout { display: grid; grid-template-columns: minmax(360px, .9fr) minmax(460px, 1.3fr); gap: clamp(30px, 4vw, 64px); margin-top: 26px; }
.note-image { display: block; width: 100%; aspect-ratio: 3/2; object-fit: cover; background: #101214; }
.note-origin { color: var(--muted); font-style: italic; line-height: 1.5; }
.note-copy { font-size: 1.05rem; }
.note-copy section + section { margin-top: 26px; }
.note-copy h3 { color: var(--gold); font-size: 1rem; margin: 0 0 10px; letter-spacing: .015em; }
.note-copy p { margin: 0; line-height: 1.62; color: #e4e7e9; }
.note-copy .caution { margin-top: 8px; color: var(--muted); }
.dialog-footer { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin-top: 28px; }
.font-controls { display: flex; align-items: center; gap: 8px; color: var(--subtle); font-size: .8rem; }
.font-controls button { min-width: 42px; height: 35px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); }
.dialog-done { min-width: 150px; }

.save-dialog { width: min(520px, calc(100vw - 34px)); }
.save-shell { padding: 30px; }
.save-shell h2 { font-size: 2rem; }
.save-shell p { color: var(--muted); line-height: 1.5; }
.save-shell label { display: grid; gap: 8px; margin-top: 22px; color: var(--gold); font-weight: 750; }
.save-shell input { width: 100%; height: 46px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); padding: 0 12px; outline: none; }
.save-shell input:focus { border-color: var(--gold); }
.save-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.save-actions .button { min-width: 110px; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 28px; transform: translate(-50%, 18px); min-width: min(460px, calc(100vw - 32px)); padding: 13px 18px; background: #f5f5f3; color: #15181b; border-left: 5px solid var(--gold); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; text-align: center; font-weight: 700; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1260px) {
  .workspace { height: auto; grid-template-columns: minmax(280px, .75fr) minmax(460px, 1.25fr); }
  .catalog-panel, .preview-panel { height: clamp(540px, calc(100dvh - 250px), 700px); }
  .filmbox-panel { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(260px, .8fr) minmax(400px, 1.2fr); align-content: start; }
  .box-picker { grid-column: 1; }
  .filmbox-heading, .slot-list, .slot-actions { grid-column: 2; }
  .filmbox-heading { grid-row: 1; }
  .slot-list { grid-row: 2 / span 5; }
  .slot-actions { grid-row: 7; }
  .button-download { margin-top: 0; }
  .filmstrip { grid-template-columns: repeat(8, 1fr); }
  .filmstrip button:nth-child(n+9) { display: none; }
}

@media (max-width: 820px) {
  .app-shell { padding: 18px 16px 14px; }
  .app-header { align-items: flex-start; }
  .brand small, .version { display: none; }
  .nikonland-link { font-size: .78rem; }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .segmented { overflow-x: auto; }
  .filter-button { min-width: 70px; }
  .profile-count { text-align: right; min-width: 0; }
  .workspace { display: flex; flex-direction: column; }
  .catalog-panel { height: 430px; }
  .preview-panel { height: auto; }
  .preview-frame { flex: none; min-height: 240px; height: min(65vh, 520px); }
  .filmbox-panel { display: flex; }
  .primary-actions { grid-template-columns: 1fr; }
  .filmstrip-section { grid-template-columns: 1fr; }
  .filmstrip-label span { display: none; }
  .filmstrip { overflow-x: auto; grid-template-columns: repeat(8, 118px); padding-bottom: 6px; }
  .filmstrip button:nth-child(n) { display: block; }
  .app-footer { flex-direction: column; gap: 6px; }
  .note-layout { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .brand strong { font-size: 1.12rem; }
  .italian-flag { width: 27px; height: 18px; }
  .header-actions { display: none; }
  .toolbar { grid-template-columns: 1fr; }
  .segmented { width: 100%; }
  .filter-button { flex: 1; }
  .profile-count { text-align: left; }
  .catalog-head, .catalog-row { grid-template-columns: 1fr 72px 38px; padding-left: 10px; padding-right: 10px; }
  .profile-info { min-height: 0; }
  .profile-origin { display: none; }
  .note-dialog { width: 100vw; max-height: 100vh; border: 0; }
  .dialog-shell { padding: 20px 16px; }
  .dialog-footer { align-items: stretch; }
  .dialog-done { min-width: 110px; }
}

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