:root { --radius-s: 8px; --radius-m: 14px; --radius-l: 20px; --gap: 14px; --header-h: 56px; --nav-h: 64px; --transition: 160ms ease; }
html[data-theme="dark"] { --bg: #0f1115; --bg-elevated: #171a21; --bg-card: #1c2029; --bg-hover: #232734; --text: #eef0f4; --text-muted: #9aa1b0; --border: #2a2f3a; --accent: #3b82f6; --accent-text: #ffffff; --danger: #ef4444; --overlay: rgba(5, 6, 9, 0.65); --scroll-thumb: #3a4051; --scroll-track: transparent; color-scheme: dark; }
html[data-theme="light"] { --bg: #f6f7fb; --bg-elevated: #ffffff; --bg-card: #ffffff; --bg-hover: #eef0f6; --text: #14161c; --text-muted: #676d7d; --border: #e2e5ee; --accent: #3b82f6; --accent-text: #ffffff; --danger: #d92d20; --overlay: rgba(20, 22, 28, 0.45); --scroll-thumb: #c7cbd8; --scroll-track: transparent; color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; height: 100dvh; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; -webkit-tap-highlight-color: transparent; overflow: hidden; }
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) var(--scroll-track); }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: var(--scroll-track); }
*::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 8px; }
svg.icon { width: 20px; height: 20px; display: inline-block; vertical-align: middle; flex-shrink: 0; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; color: var(--text); background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-s); padding: 10px 12px; font-size: 15px; outline: none; transition: border-color var(--transition); }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.app { display: flex; height: 100%; width: 100%; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); overflow: hidden; }

.auth-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100%; padding: 24px; gap: 20px; overflow: hidden; }
.auth-logo { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 700; }
.auth-logo svg { width: 36px; height: 36px; color: var(--accent); }
.auth-card { width: 100%; max-width: 380px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-l); padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.auth-warning { display: flex; gap: 10px; align-items: flex-start; background: color-mix(in srgb, var(--danger) 12%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); color: var(--text); padding: 12px; border-radius: var(--radius-m); font-size: 13.5px; line-height: 1.4; }
.auth-warning svg { color: var(--danger); flex-shrink: 0; margin-top: 1px; }
.link-btn { color: var(--accent); background: none; padding: 4px 0; font-size: 14px; align-self: flex-start; }
.btn { padding: 11px 16px; border-radius: var(--radius-m); font-weight: 600; font-size: 14.5px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: background var(--transition), opacity var(--transition), transform var(--transition); }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn-block { width: 100%; }

.shell { display: flex; width: 100%; height: 100%; position: relative; }
.side-nav { display: flex; flex-direction: column; width: 68px; background: var(--bg-elevated); border-right: 1px solid var(--border); padding: 18px 0; align-items: center; gap: 6px; transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); z-index: 60; overflow: hidden; }
.side-nav.expanded { width: 220px; align-items: flex-start; padding: 18px 12px; }
.side-nav .brand { margin-bottom: 18px; color: var(--accent); display: flex; align-items: center; gap: 12px; width: 100%; padding-left: 19px; box-sizing: border-box; cursor: pointer; }
.side-nav .brand svg { width: 30px; height: 30px; flex-shrink: 0; }
.side-nav .brand span { display: none; font-weight: 700; font-size: 18px; color: var(--text); opacity: 0; transition: opacity 0.2s; }
.side-nav.expanded .brand span { display: block; opacity: 1; }
.nav-item { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 12px; border-radius: var(--radius-m); width: 44px; color: var(--text-muted); font-size: 14px; font-weight: 500; transition: background 0.15s, color 0.15s, width 0.2s; box-sizing: border-box; flex-shrink: 0; overflow: hidden; }
.side-nav.expanded .nav-item { width: 100%; justify-content: flex-start; padding: 12px 14px; }
.nav-item.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.nav-item svg { width: 22px; height: 22px; flex-shrink: 0; }
.nav-item span { display: none; white-space: nowrap; }
.side-nav.expanded .nav-item span { display: block; }
.menu-overlay { display: none; position: fixed; inset: 0; background: var(--overlay); z-index: 50; backdrop-filter: blur(2px); }

@media (max-width: 767px) {
  .side-nav { position: fixed; top: 0; bottom: 0; right: 0; left: auto; transform: translateX(100%); border-right: none; border-left: 1px solid var(--border); width: 260px; align-items: flex-start; padding: 18px 12px; }
  .side-nav .nav-item { width: 100%; justify-content: flex-start; padding: 12px 14px; }
  .side-nav .nav-item span { display: block; }
  .side-nav .brand span { display: block; opacity: 1; }
  body.menu-open .side-nav { transform: translateX(0); }
  body.menu-open .menu-overlay { display: block; }
}

.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100%; position: relative; }
.topbar { height: var(--header-h); display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--border); background: var(--bg-elevated); flex-shrink: 0; z-index: 30; }
.topbar .title { font-size: 17px; font-weight: 700; flex-shrink: 0; }
.search-box { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-m); padding: 8px 12px; }
.search-box svg { color: var(--text-muted); width: 18px; height: 18px; flex-shrink: 0; }
.search-box input { border: none; background: none; padding: 0; flex: 1; font-size: 14px; min-width: 0; }
.icon-btn { width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--text-muted); flex-shrink: 0; }
.icon-btn:active { background: var(--bg-hover); }
.item-count-pill { font-size: 11.5px; color: var(--text-muted); padding: 3px 9px; border: 1px solid var(--border); border-radius: 999px; flex-shrink: 0; }

.content { flex: 1; overflow-y: auto; padding: 14px; padding-bottom: 100px; -webkit-overflow-scrolling: touch; }
@media (min-width: 768px) { .content { padding: 20px 24px; padding-bottom: 100px; } }

.items-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
@media (min-width: 900px) { .items-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; } }
.item-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-m); overflow: hidden; position: relative; display: flex; flex-direction: column; cursor: pointer; }
.item-photo { aspect-ratio: 1 / 1; background: var(--bg-hover); position: relative; overflow: hidden; }
.item-photo img { width: 100%; height: 100%; object-fit: cover; }
.item-photo .no-photo { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.item-select-circle { position: absolute; top: 8px; left: 8px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.85); background: rgba(0,0,0,0.25); display: flex; align-items: center; justify-content: center; z-index: 2; }
.item-select-circle.checked { background: var(--accent); border-color: var(--accent); }
.item-select-circle svg { width: 13px; height: 13px; color: #fff; }
.item-body { padding: 9px 10px 11px; display: flex; flex-direction: column; gap: 4px; }
.item-name { font-size: 13.5px; font-weight: 600; line-height: 1.25; }
.item-meta { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--text-muted); }
.item-division-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg-hover); width: fit-content; }
.chip-icon { display: flex; color: inherit; opacity: 0.8; }
.chip-icon svg { width: 12px; height: 12px; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 60px 20px; color: var(--text-muted); text-align: center; }
.empty-state svg { width: 48px; height: 48px; opacity: 0.5; }

.fab { position: fixed; right: 20px; bottom: calc(24px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent); z-index: 45; transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
.fab.hide { transform: scale(0) translateY(40px); }
.fab:active { transform: scale(0.94); }
.fab svg { width: 26px; height: 26px; }
@media (min-width: 768px) { .fab { right: 32px; bottom: 32px; } }
.selection-bar { position: fixed; left: 14px; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-l); padding: 10px 14px; display: flex; align-items: center; gap: 10px; z-index: 46; box-shadow: 0 8px 24px rgba(0,0,0,0.25); }
@media (min-width: 768px) { .selection-bar { left: auto; right: 32px; bottom: 32px; width: 340px; } }
.selection-bar .count { font-weight: 600; font-size: 14px; flex: 1; }

.divisions-list { display: flex; flex-direction: column; gap: 10px; }
.division-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-m); cursor: pointer; }
.division-row.drag-over { border-color: var(--accent); background: var(--bg-hover); }
.division-icon { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); flex-shrink: 0; background: var(--bg-hover); border-radius: 50%; }
.division-info { flex: 1; min-width: 0; }
.division-name { font-weight: 600; font-size: 14.5px; }
.division-sub { font-size: 12px; color: var(--text-muted); }
.division-actions { display: flex; gap: 4px; }
.division-children { margin-left: 26px; display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.icon-swatch { width: 40px; height: 40px; border-radius: var(--radius-s); border: 2px solid transparent; display:flex; align-items:center; justify-content:center; color: var(--text-muted); background: var(--bg-hover); }
.icon-swatch.selected { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); }

.modal-overlay { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: flex-end; justify-content: center; z-index: 100; backdrop-filter: blur(2px); }
@media (min-width: 640px) { .modal-overlay { align-items: center; } }
.modal-sheet { background: var(--bg-elevated); width: 100%; max-width: 480px; border-radius: var(--radius-l) var(--radius-l) 0 0; max-height: 92dvh; overflow-y: auto; padding: 20px 18px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
@media (min-width: 640px) { .modal-sheet { border-radius: var(--radius-l); max-height: 88dvh; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-header h2 { font-size: 17px; margin: 0; }
.modal-small { max-width: 380px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.photo-upload-area { display: flex; flex-direction: column; align-items: center; gap: 10px; border: 1.5px dashed var(--border); border-radius: var(--radius-m); padding: 12px; position: relative; min-height: 150px; justify-content: center; background: var(--bg-hover); overflow: hidden; width: 100%; box-sizing: border-box; }
.photo-upload-area img { max-width: 100%; max-height: 200px; object-fit: contain; border-radius: var(--radius-s); box-sizing: border-box; }
.discreet-rotate { position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border-radius: 50%; background: rgba(0,0,0,0.5); color: #fff; display: flex; align-items: center; justify-content: center; z-index: 5; border: 1px solid rgba(255,255,255,0.2); }
.photo-actions { display: flex; gap: 10px; margin-top: 4px; }
.photo-actions .btn-secondary { padding: 9px 12px; font-size: 13px; }
.tags-input { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius-s); background: var(--bg-elevated); position: relative; }
.tag-chip { display: inline-flex; align-items: center; gap: 5px; background: var(--bg-hover); padding: 4px 8px; border-radius: 999px; font-size: 12.5px; }
.tag-chip button { display: flex; color: var(--text-muted); }
.tags-input input { border: none; background: none; flex: 1; min-width: 80px; padding: 4px; font-size: 13.5px; }
.tag-suggestions { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-s); z-index: 5; overflow: hidden; box-shadow: 0 8px 20px rgba(0,0,0,0.2); }
.tag-suggestion { padding: 9px 12px; font-size: 13.5px; }
.tag-suggestion:hover, .tag-suggestion.active { background: var(--bg-hover); }

.photo-modal-overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; backdrop-filter: blur(4px); }
.photo-modal-content { background: var(--bg-card); border-radius: var(--radius-m); overflow: hidden; max-width: 90vw; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 12px 32px rgba(0,0,0,0.4); position: relative; width: 100%; pointer-events: none; }
.photo-modal-img-wrap { position: relative; background: #000; flex: 1; display: flex; align-items: center; justify-content: center; min-height: 300px; pointer-events: auto; }
.photo-modal-content img { max-width: 100%; max-height: calc(85vh - 70px); object-fit: contain; }
.photo-modal-footer { padding: 14px 16px; background: var(--bg-elevated); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 3px; pointer-events: auto; }

.settings-section { display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }
.settings-section h3 { font-size: 12.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; margin: 0 0 2px; }
.settings-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-m); overflow: hidden; }
.settings-row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--border); width: 100%; text-align: left; }
.settings-row:last-child { border-bottom: none; }
.settings-row .row-label { flex: 1; }
.settings-row .row-title { font-size: 14.5px; font-weight: 500; }
.settings-row .row-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.settings-row svg { color: var(--text-muted); }
.toggle { width: 46px; height: 26px; border-radius: 999px; background: var(--bg-hover); border: 1px solid var(--border); position: relative; flex-shrink: 0; transition: background var(--transition); }
.toggle.on { background: var(--accent); border-color: var(--accent); }
.toggle .knob { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform var(--transition); }
.toggle.on .knob { transform: translateX(20px); }
.theme-switch { display: flex; gap: 6px; background: var(--bg-hover); border-radius: var(--radius-m); padding: 4px; }
.theme-switch button { flex: 1; display: flex; align-items: center; justify-content: center; padding: 8px; border-radius: var(--radius-s); color: var(--text-muted); }
.theme-switch button.active { background: var(--bg-elevated); color: var(--text); }
.theme-switch svg { width: 18px; height: 18px; }
.stat-row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--border); }
.stat-row:last-child { border-bottom: none; }
.stat-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.stat-info { flex: 1; min-width: 0; }
.stat-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.admin-badge { font-size: 10px; background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); padding: 1px 7px; border-radius: 999px; font-weight: 700; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat-count { font-size: 15px; font-weight: 700; }

.toast-stack { position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 300; pointer-events: none; }
.toast { background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text); padding: 11px 16px; border-radius: var(--radius-m); font-size: 13.5px; box-shadow: 0 6px 18px rgba(0,0,0,0.25); display: flex; align-items: center; gap: 8px; max-width: 90%; }
.toast.error { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.toast svg { width: 17px; height: 17px; flex-shrink: 0; }
.confirm-body { font-size: 14px; color: var(--text-muted); line-height: 1.5; margin-bottom: 8px; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn { flex: 1; }
