:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #162029;
  --muted: #657487;
  --line: #dbe3ea;
  --soft: #edf5f3;
  --accent: #08746f;
  --accent-dark: #075b57;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --amber: #9a6700;
  --amber-soft: #fff7df;
  --shadow: 0 10px 28px rgba(17, 31, 44, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101820;
  --panel: #17222c;
  --ink: #edf5f7;
  --muted: #9fb0bf;
  --line: #2d3b47;
  --soft: #183531;
  --accent: #20a39a;
  --accent-dark: #17857f;
  --danger: #e05247;
  --danger-soft: #351d1e;
  --amber: #e0b84d;
  --amber-soft: #332b17;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

#app {
  min-height: 100vh;
  display: block;
}

.app-title,
.brand {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  margin-top: 0;
  display: block;
  border-radius: 10px;
  object-fit: cover;
}

.app-title > div:last-child {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
  flex-wrap: wrap;
}

.shell {
  min-width: 0;
  padding: 22px 28px;
}

.scan-progress {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: -18px 0 18px;
  border: 1px solid #b9d9d4;
  border-radius: 8px;
  background: #ecf8f6;
  box-shadow: 0 8px 20px rgba(17, 31, 44, 0.08);
  padding: 10px 12px;
}

.scan-progress-text {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: #23534d;
}

.scan-progress-text span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.topbar,
.section-head,
.subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.section-head .button.primary {
  min-height: 42px;
  padding-inline: 18px;
  box-shadow: 0 8px 18px rgba(8, 116, 111, 0.18);
}

.topbar h1,
.section-head h2,
.subhead h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 28px;
}

.section-head p {
  margin: 5px 0 0;
  color: var(--muted);
}

.top-actions {
  position: relative;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 8px 14px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.button.primary:hover {
  background: var(--accent-dark);
}

.button.secondary:hover {
  border-color: #aec0cc;
}

.button.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: white;
}

.account-button {
  min-height: 42px;
  max-width: 170px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  padding: 5px 11px 5px 5px;
  font-weight: 800;
}

.account-button.signed-in {
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  justify-content: center;
  padding: 5px;
}

.account-button:hover {
  border-color: #aec0cc;
}

.account-avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  background-position: center;
  background-size: cover;
  font-size: 13px;
}

.account-avatar.has-image {
  color: transparent;
}

#accountLabel {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-button.signed-in #accountLabel {
  display: none;
}

.account-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  width: min(320px, calc(100vw - 28px));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.account-menu-profile {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
}

.account-menu-profile img {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  object-fit: cover;
}

.account-menu-profile strong,
.account-menu-profile span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-menu-profile span,
.account-menu-note {
  color: var(--muted);
  font-size: 13px;
}

.account-menu-note {
  margin: 0;
  padding: 8px;
}

.account-client-field {
  margin: 6px 8px 8px;
}

.account-menu-item {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-weight: 750;
}

.account-menu-item:hover,
.account-menu-item:focus-visible {
  background: #f4f8fb;
  outline: none;
}

.account-menu-item.primary {
  color: var(--accent-dark);
}

.account-menu-item.danger {
  color: var(--danger);
}

.account-menu-item:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.52;
}

.account-menu-item + .account-menu-item {
  margin-top: 2px;
}

.account-menu-links {
  display: flex;
  gap: 10px;
  padding: 8px;
  border-top: 1px solid var(--line);
  margin-top: 6px;
}

.account-menu-links a {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-decoration: none;
}

.account-menu-links a:hover,
.account-menu-links a:focus-visible {
  color: var(--accent-dark);
  text-decoration: underline;
}

.folderbar {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.folderbar-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.folderbar-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.folderbar-main strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folderbar-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.icon-button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.icon-button:disabled {
  opacity: 0.44;
  cursor: not-allowed;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.button.large {
  min-height: 46px;
  padding-inline: 18px;
}

.button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.stats {
  margin: 10px 0 12px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.stat-tile {
  display: block;
  width: 100%;
  min-height: 58px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
}

.stat-tile:hover:not(:disabled) {
  border-color: #b9c8d3;
  box-shadow: 0 8px 20px rgba(17, 31, 44, 0.06);
}

.stat-tile.attention {
  border-color: rgba(8, 116, 111, 0.35);
}

.stat-tile.danger {
  border-color: rgba(180, 35, 24, 0.35);
}

.stat-tile.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(8, 116, 111, 0.12);
}

.stat-tile:disabled {
  cursor: default;
  opacity: 0.68;
}

.stat-tile span,
.stat-tile small,
.stat-tile strong {
  display: block;
}

.stat-tile span {
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.stat-tile small {
  color: var(--muted);
  margin-top: 1px;
  font-size: 11px;
}

.stat-tile strong {
  margin-top: 4px;
  color: var(--accent-dark);
  font-size: 11px;
}

.stat-tile.danger strong {
  color: var(--danger);
}

.quick-apply {
  width: 100%;
  min-height: 46px;
  margin: -2px 0 14px;
  border: 1px solid rgba(180, 35, 24, 0.34);
  border-radius: 8px;
  background: var(--danger);
  color: white;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 10px 24px rgba(180, 35, 24, 0.16);
}

.quick-apply:hover:not(:disabled) {
  background: #9f1f17;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view.active.empty-state-hidden {
  display: none;
}

.empty-panel {
  min-height: 430px;
  border: 2px dashed #c9d7df;
  border-radius: 8px;
  background: var(--panel);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  text-align: center;
  padding: 34px;
}

.empty-icon {
  width: 54px;
  height: 54px;
  display: block;
  border-radius: 8px;
  object-fit: cover;
}

.empty-panel h2,
.empty-panel p {
  max-width: 620px;
  margin: 0;
}

.empty-panel p {
  color: var(--muted);
  line-height: 1.55;
}

.empty-panel.remembered-folder {
  min-height: 0;
  place-items: start;
  align-content: start;
  gap: 8px;
  padding: 18px;
  text-align: left;
}

.empty-panel.remembered-folder .empty-icon {
  display: none;
}

.empty-panel.remembered-folder h2 {
  font-size: 20px;
}

.empty-panel.remembered-folder p {
  max-width: none;
}

.support {
  min-height: 20px;
  font-size: 13px;
}

.duplicate-list,
.photo-grid,
.review-list,
.plan-list {
  margin-top: 14px;
}

.duplicate-list {
  display: grid;
  gap: 14px;
}

.duplicate-section-label {
  margin-top: 8px;
}

.duplicate-section-label h3,
.duplicate-section-label p {
  margin: 0;
}

.duplicate-section-label p {
  margin-top: 4px;
  color: var(--muted);
}

.bottom-action {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
  padding-bottom: 12px;
}

.duplicate-group {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.duplicate-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.duplicate-title h3 {
  margin: 0;
  font-size: 16px;
}

.duplicate-title span {
  color: var(--muted);
  font-size: 13px;
}

.duplicate-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.photo-card,
.duplicate-card,
.review-card,
.plan-row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.duplicate-card {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.duplicate-card.keep,
.photo-card.keep {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(8, 116, 111, 0.12);
}

.duplicate-card.suspect {
  border-color: #e8c55a;
  box-shadow: 0 0 0 2px rgba(232, 197, 90, 0.16);
}

.duplicate-card.delete {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px rgba(204, 50, 50, 0.12);
}

.possible-duplicate-group {
  border-style: dashed;
}

.thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #d7e1e8;
  display: block;
}

.thumb-button {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
}

.thumb-button:focus-visible {
  outline: 3px solid rgba(8, 116, 111, 0.32);
  outline-offset: -3px;
}

.card-body {
  padding: 10px;
}

.photo-card .card-body {
  padding: 9px;
}

.file-name {
  font-weight: 750;
  font-size: 13px;
  overflow-wrap: anywhere;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  line-height: 1.35;
}

.duplicate-card .meta {
  min-height: 32px;
}

.review-reasons {
  display: grid;
  gap: 5px;
  margin-top: 8px;
}

.review-reason {
  display: grid;
  gap: 2px;
  padding: 6px 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.review-reason span {
  font-size: 11px;
  font-weight: 800;
  color: var(--ink);
}

.review-reason small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.review-reason.possible {
  border-color: #e7c06a;
  background: var(--amber-soft);
}

.review-reason.possible span {
  color: #6c4900;
}

.review-reason.whatsapp {
  border-color: #99d6bd;
  background: #eefaf4;
}

.review-reason.whatsapp span {
  color: #08613f;
}

.review-reason.duplicate {
  border-color: #f2b8b5;
  background: var(--danger-soft);
}

.review-reason.duplicate span {
  color: var(--danger);
}

.review-reason.date,
.review-reason.manual {
  border-color: #cbd8e2;
  background: #f4f8fb;
}

.meta-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.meta-block strong {
  display: block;
  color: var(--ink);
  font-size: 11px;
}

.meta-block span {
  display: block;
  margin-top: 2px;
  white-space: nowrap;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.mini {
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f8fafb;
  font-weight: 700;
}

.mini.keep {
  color: var(--accent-dark);
}

.mini.place {
  color: #4d5c68;
}

.mini.delete {
  color: var(--danger);
}

.mini:disabled {
  cursor: default;
  opacity: 0.45;
}

.mini.trash {
  color: var(--danger);
  border-color: #f2b8b5;
  background: var(--danger-soft);
}

.choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: auto;
  padding-top: 10px;
}

.choice-button {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  color: var(--muted);
  font-weight: 800;
}

.choice-button.keep.selected {
  border-color: rgba(8, 116, 111, 0.42);
  background: #ecf8f5;
  color: var(--accent-dark);
}

.choice-button.delete.selected {
  border-color: #f2b8b5;
  background: var(--danger-soft);
  color: var(--danger);
}

.choice-tick {
  width: 15px;
  height: 15px;
  display: inline-block;
  position: relative;
  border: 2px solid currentColor;
  border-radius: 999px;
  opacity: 0.42;
}

.choice-button.selected .choice-tick {
  opacity: 1;
  background: currentColor;
}

.choice-button.selected .choice-tick::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border-right: 2px solid white;
  border-bottom: 2px solid white;
  transform: rotate(45deg);
}

.segmented {
  display: flex;
  padding: 3px;
  background: #e9eef2;
  border-radius: 8px;
}

.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  min-height: 32px;
  padding: 5px 12px;
  font-weight: 700;
  color: var(--muted);
}

.segmented svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.segmented button.active {
  background: var(--panel);
  color: var(--accent-dark);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.sequence-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

.subhead {
  margin-top: 0;
  margin-bottom: 10px;
}

.subhead h3 {
  margin-bottom: 2px;
}

.subhead span {
  color: var(--muted);
  font-size: 13px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.photo-card {
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 270px;
}

.photo-card.dragging {
  opacity: 0.5;
}

.sequence-number {
  position: absolute;
  top: 8px;
  left: 8px;
  min-width: 30px;
  height: 26px;
  display: grid;
  place-items: center;
  padding-inline: 7px;
  border-radius: 999px;
  background: rgba(7, 91, 87, 0.94);
  color: white;
  font-weight: 800;
  font-size: 12px;
  border: 0;
  cursor: pointer;
}

.sequence-number.armed {
  background: #9a6700;
  box-shadow: 0 0 0 3px rgba(154, 103, 0, 0.22);
}

.review-tray {
  position: sticky;
  top: 16px;
  min-width: 0;
  max-height: calc(100vh - 32px);
  background: #f9fbfc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.review-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px;
  border-radius: 8px;
  background: #e9eef2;
}

.review-tab {
  min-width: 0;
  min-height: 48px;
  border: 0;
  border-radius: 6px;
  padding: 6px 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.review-tab span,
.review-tab small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.review-tab span {
  color: inherit;
  font-weight: 800;
}

.review-tab small {
  margin-top: 2px;
  font-size: 12px;
}

.review-tab.active {
  background: var(--panel);
  color: var(--accent-dark);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.review-panel {
  display: none;
  min-height: 0;
  flex: 1;
}

.review-panel.active {
  display: flex;
  flex-direction: column;
}

.review-list {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding-right: 2px;
  display: grid;
  align-content: start;
  gap: 10px;
}

.deleted-list {
  max-height: none;
}

.review-card {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 10px;
  padding: 8px;
}

.review-thumb {
  width: 76px;
  height: 60px;
  border: 0;
  border-radius: 6px;
  padding: 0;
  background: #d7e1e8;
  overflow: hidden;
  cursor: zoom-in;
}

.review-thumb img,
.review-card > img {
  width: 76px;
  height: 60px;
  object-fit: contain;
  background: #d7e1e8;
  display: block;
}

.deleted-card {
  opacity: 0.82;
}

.apply-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.apply-summary-grid {
  grid-template-columns: 1fr;
}

.apply-grid h3 {
  margin: 18px 0 0;
}

.photo-card .card-body,
.duplicate-card .card-body {
  display: flex;
  flex: 1;
  flex-direction: column;
}

.file-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
}

.file-row .file-name {
  min-width: 0;
  flex: 1;
}

.manual-badge {
  flex: 0 0 auto;
  border: 1px solid #d6b56d;
  border-radius: 999px;
  padding: 2px 6px;
  background: #fff7d7;
  color: #73510b;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
}

.photo-card .card-actions {
  margin-top: auto;
  padding-top: 6px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  justify-content: space-between;
  align-items: center;
  gap: 4px;
}

.photo-card .card-actions .mini {
  min-height: 36px;
  height: 36px;
  padding: 0;
  white-space: nowrap;
}

.sequence-button {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  border-color: #cfdce5;
  background: #f7fafc;
}

.sequence-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.35;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sequence-button.icon-remove {
  color: #52616d;
  border-color: #cfdce5;
  background: #f7fafc;
}

.sequence-button.icon-delete {
  color: var(--danger);
  border-color: #f2b8b5;
  background: #fff7f6;
}

.sequence-button.text-button {
  width: 100%;
  min-width: 0;
  padding: 0 2px;
  color: var(--accent-dark);
  font-size: 10.5px;
  font-weight: 850;
  line-height: 1;
}

.sequence-button.text-button.armed {
  color: white;
  border-color: var(--accent);
  background: var(--accent);
}

.plan-list {
  display: grid;
  gap: 8px;
}

.plan-row {
  padding: 10px 12px;
  display: grid;
  gap: 3px;
}

.plan-row strong {
  overflow-wrap: anywhere;
}

.plan-row span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  background: #132029;
  color: white;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(11, 22, 31, 0.52);
}

.modal {
  width: min(460px, 100%);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.22);
  padding: 24px;
}

.modal h2 {
  margin: 0 0 8px;
}

.modal p {
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}

.workspace-modal {
  width: min(640px, 100%);
}

.source-tabs {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 8px;
  background: #e9eef2;
}

.source-tab {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 850;
}

.source-tab.active {
  background: var(--panel);
  color: var(--accent-dark);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.source-panel {
  display: none;
  margin-top: 14px;
}

.source-panel.active {
  display: block;
}

.source-panel.disabled {
  opacity: 0.58;
}

.drive-picker {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.selected-folder {
  display: grid;
  gap: 3px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.selected-folder span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.selected-folder strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drive-picker-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.drive-breadcrumb {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.drive-breadcrumb button {
  flex: 0 0 auto;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  background: #f8fafb;
  color: var(--muted);
  font-weight: 800;
}

.drive-breadcrumb button:last-child {
  color: var(--accent-dark);
  background: #eefaf8;
  border-color: rgba(8, 116, 111, 0.24);
}

.drive-browser {
  display: grid;
  max-height: min(300px, 42vh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.drive-folder-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 46px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 8px 11px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-weight: 800;
}

.drive-folder-row:last-child {
  border-bottom: 0;
}

.drive-folder-row:hover,
.drive-folder-row:focus-visible {
  background: #f4f8fb;
}

.drive-folder-row span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drive-folder-icon {
  position: relative;
  width: 24px;
  height: 18px;
  border-radius: 5px;
  background: #d5a936;
}

.drive-folder-icon::before {
  content: "";
  position: absolute;
  left: 2px;
  top: -4px;
  width: 10px;
  height: 6px;
  border-radius: 4px 4px 0 0;
  background: #e8c96f;
}

.drive-browser-empty {
  padding: 16px;
  color: var(--muted);
  font-size: 13px;
}

.account-profile {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.account-profile img {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 999px;
  object-fit: cover;
}

.account-profile strong,
.account-profile span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-profile span {
  color: var(--muted);
  font-size: 13px;
}

.settings-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.settings-row strong,
.settings-row span {
  display: block;
}

.settings-row span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.settings-row .button {
  flex: 0 0 auto;
}

.danger-row {
  background: var(--danger-soft);
  border-color: rgba(180, 35, 24, 0.24);
}

:root[data-theme="dark"] .stat-tile,
:root[data-theme="dark"] .review-tray,
:root[data-theme="dark"] .review-panel,
:root[data-theme="dark"] .photo-card,
:root[data-theme="dark"] .duplicate-group,
:root[data-theme="dark"] .source-tabs,
:root[data-theme="dark"] .selected-folder,
:root[data-theme="dark"] .drive-browser,
:root[data-theme="dark"] .settings-row,
:root[data-theme="dark"] .account-profile,
:root[data-theme="dark"] .folderbar,
:root[data-theme="dark"] .plan-list,
:root[data-theme="dark"] .review-reason,
:root[data-theme="dark"] .empty-panel {
  background: var(--panel);
}

:root[data-theme="dark"] .source-tab.active,
:root[data-theme="dark"] .drive-folder-row:hover,
:root[data-theme="dark"] .drive-folder-row:focus-visible,
:root[data-theme="dark"] .account-menu-item:hover,
:root[data-theme="dark"] .account-menu-item:focus-visible,
:root[data-theme="dark"] .choice-button,
:root[data-theme="dark"] .mini,
:root[data-theme="dark"] .field-label input {
  background: #1d2a35;
}

.field-label {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.field-label span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.field-label input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: var(--panel);
  color: var(--ink);
}

.field-label input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8, 116, 111, 0.12);
  outline: none;
}

.modal-actions {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.photo-viewer-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(7, 15, 22, 0.72);
}

.photo-viewer {
  width: min(1180px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  display: grid;
  grid-template-rows: auto minmax(240px, 1fr) auto auto;
  gap: 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #101922;
  color: white;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.38);
  padding: 14px;
}

.viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.viewer-head > div:first-child {
  min-width: 0;
}

.viewer-head h2 {
  margin: 0;
  max-width: 72vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}

.viewer-head p {
  margin: 4px 0 0;
  color: #aebbc8;
  font-size: 13px;
}

.viewer-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.viewer-zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.viewer-icon-button,
.viewer-fit-button,
.viewer-nav {
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: white;
  background: rgba(255, 255, 255, 0.08);
}

.viewer-icon-button {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  font-size: 28px;
  line-height: 1;
}

.viewer-icon-button.small {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  font-size: 20px;
  font-weight: 800;
}

.viewer-fit-button {
  min-width: 44px;
  height: 32px;
  border-radius: 999px;
  padding: 0 10px;
  font-weight: 800;
}

.viewer-icon-button:disabled,
.viewer-fit-button:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}

.viewer-stage {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 54px;
  align-items: center;
  gap: 12px;
}

.viewer-image-frame {
  min-width: 0;
  min-height: 0;
  height: min(68vh, 720px);
  max-height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    #071017;
  background-size: 22px 22px;
  overscroll-behavior: contain;
  touch-action: none;
}

.viewer-image-frame img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  cursor: zoom-in;
  transition: transform 160ms ease;
}

.viewer-image-frame.zoomed {
  overflow: auto;
  cursor: grab;
  user-select: none;
}

.viewer-image-frame.zoomed.panning {
  cursor: grabbing;
}

.viewer-image-frame img.zoomed {
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  cursor: inherit;
  user-select: none;
  -webkit-user-drag: none;
}

.viewer-image-frame.panning img.zoomed {
  cursor: grabbing;
}

.viewer-nav {
  width: 54px;
  height: 96px;
  border-radius: 8px;
  font-size: 46px;
  line-height: 1;
}

.viewer-nav:disabled,
.viewer-actions .button:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}

.viewer-thumb-strip {
  display: flex;
  gap: 8px;
  min-height: 72px;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 2px 8px;
  scrollbar-width: thin;
}

.viewer-thumb {
  position: relative;
  flex: 0 0 86px;
  height: 66px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 0;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.viewer-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.viewer-thumb span {
  position: absolute;
  left: 4px;
  bottom: 4px;
  min-width: 28px;
  padding: 2px 5px;
  border-radius: 999px;
  background: rgba(7, 15, 22, 0.76);
  color: white;
  font-size: 11px;
  font-weight: 800;
}

.viewer-thumb.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.24);
}

.viewer-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.viewer-actions .button {
  min-height: 44px;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 4px solid #d8e5e3;
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
  margin-bottom: 14px;
}

.progress {
  height: 8px;
  margin-top: 18px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7eef2;
}

.progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 160ms ease;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.hidden {
  display: none !important;
}

@media (min-width: 901px) {
  .photo-viewer-overlay {
    place-items: center;
    padding: 28px;
    background: rgba(7, 15, 22, 0.66);
  }

  .photo-viewer {
    width: min(1680px, calc(100vw - 56px));
    height: min(920px, calc(100vh - 56px));
    max-height: calc(100vh - 56px);
  }

  .viewer-image-frame {
    height: 100%;
  }
}

@media (max-width: 900px) {
  .shell {
    padding: 18px 14px max(18px, env(safe-area-inset-bottom));
  }

  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    align-items: center;
  }

  .top-actions {
    justify-content: flex-end;
  }

  .top-actions .button,
  .section-head .button {
    width: 100%;
  }

  .account-button {
    width: 48px;
    min-width: 48px;
    max-width: 48px;
    justify-content: center;
    padding: 5px;
  }

  .account-button #accountLabel {
    display: none;
  }

  .drive-picker-actions {
    display: grid;
  }

  .drive-picker-actions .button {
    width: 100%;
  }

  .sequence-layout,
  .apply-grid {
    grid-template-columns: 1fr;
  }

  .review-tray {
    position: static;
    max-height: min(520px, 70vh);
  }

  .photo-viewer {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    padding: 12px;
  }

  .viewer-stage {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 8px;
  }

  .viewer-nav {
    width: 44px;
    height: 82px;
    font-size: 38px;
  }

  .viewer-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .topbar h1 {
    font-size: 24px;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
  }

  .app-title {
    align-items: center;
    min-width: 0;
  }

  .app-title h1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand-mark {
    margin-top: 0;
  }

  .folderbar {
    align-items: stretch;
  }

  .folderbar-actions {
    align-items: center;
  }

  .stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .stat-tile {
    min-height: 54px;
    padding: 6px;
  }

  .stat-tile span {
    font-size: 17px;
  }

  .stat-tile small,
  .stat-tile strong {
    font-size: 10px;
    line-height: 1.15;
  }

  .quick-apply {
    min-height: 48px;
    margin-bottom: 12px;
  }

  .segmented {
    padding: 2px;
  }

  .segmented button {
    min-width: 38px;
    min-height: 34px;
    padding: 5px 8px;
  }

  .segmented button span {
    display: none;
  }

  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
    gap: 10px;
  }

  .photo-card {
    min-height: 246px;
  }

  .review-card {
    grid-template-columns: 68px minmax(0, 1fr);
  }

  .review-thumb,
  .review-thumb img,
  .review-card > img {
    width: 68px;
    height: 56px;
  }

  .photo-viewer-overlay {
    padding: 8px;
  }

  .photo-viewer {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    grid-template-rows: auto minmax(190px, 1fr) auto auto;
  }

  .viewer-stage {
    grid-template-columns: 1fr;
  }

  .viewer-nav {
    position: absolute;
    top: 50%;
    z-index: 2;
    width: 42px;
    height: 72px;
    transform: translateY(-50%);
    background: rgba(16, 25, 34, 0.78);
  }

  .viewer-nav.prev {
    left: 14px;
  }

  .viewer-nav.next {
    right: 14px;
  }

  .viewer-stage {
    position: relative;
  }

  .viewer-image-frame {
    height: min(58dvh, 620px);
  }

  .viewer-thumb-strip {
    min-height: 62px;
  }

  .viewer-thumb {
    flex-basis: 74px;
    height: 56px;
  }

  .viewer-actions {
    grid-template-columns: 1fr;
  }
}
