/* Neutral Darkroom: shared product tokens and components, loaded last by base.html.
 * Content-first layout follows Apple HIG hierarchy; photograph surrounds remain neutral. */
@layer imago.application {
  :root {
    /* Neutral surrounds for judging photographs. */
    --im3-canvas: #ffffff;
    --im3-canvas-strong: #f2f2f2;
    --im3-surface: #ffffff;
    --im3-surface-raised: #ffffff;
    --im3-surface-subtle: #f7f7f7;
    --im3-surface-muted: #ededed;
    --im3-control: #ffffff;
    --im3-control-hover: #f0f0f0;
    --im3-ink: #1c1c1c;
    --im3-ink-soft: #454545;
    --im3-muted: #626262;
    --im3-faint: #707070;
    --im3-line: #e5e5e5;
    --im3-line-strong: #bdbdbd;
    --im3-accent: #242424;
    --im3-accent-hover: #080808;
    --im3-accent-soft: #ededed;
    --im3-accent-50: #f6f6f6;
    --im3-accent-100: #ededed;
    --im3-accent-200: #d8d8d8;
    --im3-accent-300: #b6b6b6;
    --im3-accent-400: #8a8a8a;
    --im3-accent-500: #626262;
    --im3-accent-600: #242424;
    --im3-accent-700: #080808;
    --im3-success: #14633d;
    --im3-warning: #86551b;
    --im3-danger: #af3440;
    --im3-focus: #2563eb;
    --im3-focus-outer: #ffffff;
    --im3-focus-ring: 0 0 0 4px #2563eb24;
    --im3-radius-xs: 6px;
    --im3-radius-sm: 8px;
    --im3-radius: 10px;
    --im3-radius-lg: 14px;
    --im3-radius-xl: 18px;
    --im3-radius-2xl: 24px;
    --im3-dialog-radius: 20px;
    --im3-shadow-1: 0 1px 3px #00000008;
    --im3-shadow-2: 0 6px 24px -12px #00000024;
    --im3-shadow-3: 0 24px 72px -20px #00000038;
    --im3-shadow-soft: var(--im3-shadow-1);
    --im3-shadow-lift: var(--im3-shadow-2);
    --im3-shadow-float: var(--im3-shadow-3);
    --im3-text-body: 14px;
    --im3-text-page: 30px;
    --im3-leading-body: 1.6;
    --im3-content-gap: clamp(16px, 2vw, 28px);
    --im3-control-gap: 8px;
    --im3-motion-reveal: 180ms;
    --im3-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
    --im3-font-editorial: "Iowan Old Style", "Palatino Linotype", "Noto Serif CJK SC", "Songti SC", serif;
    --im3-product-gutter: clamp(16px, 2.6vw, 40px);
    --im3-product-on-accent: #ffffff;
    color-scheme: light;
  }
  html { scroll-padding-block: 80px; }
  body { color: var(--im3-ink); background: var(--im3-canvas); font-family: var(--im3-font-sans); }
  body :is(button, input, select, textarea) { font-family: inherit; }
  body :is(h1, h2, h3, h4, p) { overflow-wrap: break-word; }
  body :is(h1, .im-page-title, .gallery-view-heading .title) { font-weight: 650; letter-spacing: -.015em; line-height: 1.3; }
  body :is(.subtitle, .im-dialog__subtitle, .admin-route-desc, .share-gate-desc) { line-height: 1.7; }
  body :is(.im-kicker, .picker-label, .share-section-label) { font-weight: 650; letter-spacing: .06em; }
  body :is(.value, .sidebar-stat strong, .review-summary strong, .upload-task-progress) { font-variant-numeric: tabular-nums; }
  body :is(button, a, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--im3-focus); outline-offset: 3px; box-shadow: var(--im3-focus-ring);
  }
  body :is(input, textarea, select)[aria-invalid="true"] { border-color: var(--im3-danger); }
  body :is(input, textarea)::placeholder { color: var(--im3-muted); opacity: 1; }
  body :is(button, input, select, textarea):disabled { cursor: not-allowed; }
  body :is(.btn, .small-btn, .im-button, .share-toolbar-btn) {
    min-height: 44px; border-radius: var(--im3-radius); font-weight: 550;
    transition: background-color 140ms, border-color 140ms, box-shadow 140ms;
  }
  body :is(.btn.primary, .im-button--primary, #login-submit, .share-gate-submit:not(.share-gate-submit-ghost)) {
    color: var(--im3-product-on-accent); background: var(--im3-accent); border-color: var(--im3-accent);
  }
  body :is(.btn.primary, .im-button--primary, #login-submit, .share-gate-submit:not(.share-gate-submit-ghost)):hover:not(:disabled) {
    background: var(--im3-accent-hover); border-color: var(--im3-accent-hover);
  }
  body :is(input:not([type]), input[type="text"], input[type="search"], input[type="password"], input[type="email"],
    input[type="url"], input[type="number"], input[type="date"], input[type="datetime-local"], select, textarea) {
    min-height: 44px; border-radius: var(--im3-radius); border-color: var(--im3-line-strong);
    color: var(--im3-ink); background-color: var(--im3-control);
  }
  body :is(input[type="checkbox"], input[type="radio"], input[type="range"], progress) { accent-color: var(--im3-accent); }
  body textarea { resize: vertical; line-height: 1.65; }
  body :is(.pn-empty, .im-empty, .share-empty, .review-empty) {
    color: var(--im3-muted); border-radius: var(--im3-radius-lg); text-align: center;
  }
  body :is(.pn-empty__icon, .im-empty__icon, .share-empty-icon) { color: var(--im3-accent); opacity: .75; }
  body :is(.pn-empty__title, .im-empty__title) { color: var(--im3-ink); font-weight: 600; }
  body :is(.pn-empty__desc, .im-empty__desc) { max-width: 48ch; margin-inline: auto; line-height: 1.7; }
  body :is(.im-dialog__status, .upload-modal-status, .share-modal-status, .share-page-load-state, .review-save-status) { line-height: 1.65; }
  body [hidden] { display: none !important; }

  /* Navigation and library. */
  body.page-gallery .gallery-v2 .gallery-rail {
    background: var(--im3-surface); border-right: 1px solid var(--im3-line); box-shadow: none;
  }
  body.page-gallery .gallery-brand .brand-title { font-size: 23px; letter-spacing: .035em; font-weight: 650; }
  body.page-gallery .gallery-rail-header { padding-top: 28px; }
  body.page-gallery .gallery-rail-search { margin-top: 28px; }
  body.page-gallery .gallery-search-btn { border-radius: 10px; border-color: var(--im3-line); background: var(--im3-surface-subtle); }
  body.page-gallery .gallery-rail-section { border: 0; background: transparent; box-shadow: none; }
  body.page-gallery .gallery-rail-section .picker-label { font-size: 12px; color: var(--im3-muted); }
  body.page-gallery .picker-pill:is(.active, .is-active, [aria-pressed="true"]) {
    color: var(--im3-accent); background: var(--im3-accent-soft); border-color: var(--im3-accent-200); box-shadow: none;
  }
  body.page-gallery .gallery-admin-entry { border-radius: 12px; border-color: var(--im3-line); background: var(--im3-surface-subtle); }
  body.page-gallery .gallery-admin-entry__avatar { background: var(--im3-accent); color: var(--im3-product-on-accent); border-radius: 10px; }
  body.page-gallery .gallery-view-heading { padding-block: 12px 24px; }
  body.page-gallery .gallery-view-heading .title { font-size: 30px; }
  body.page-gallery .gallery-view-heading .subtitle { margin-top: 8px; color: var(--im3-muted); }
  body.page-gallery :is(.album-card, .year-card, .source-card) { border-radius: 14px; border-color: var(--im3-line); box-shadow: var(--im3-shadow-1); }
  body.page-gallery :is(.photo-card, .photo-tile) { border-radius: 8px; }
  body.page-gallery .gallery-fab__actions { border-radius: 18px; box-shadow: var(--im3-shadow-3); border-color: var(--im3-line); }
  body.page-gallery :is(.gallery-search-panel, .mobile-bottom-sheet) { background: var(--im3-surface); }
  body.page-gallery .mobile-sheet-header { border-bottom: 1px solid var(--im3-line); }

  /* Management. */
  body.page-admin .admin-sidebar { background: var(--im3-surface); border-color: var(--im3-line); }
  body.page-admin .admin-operator-card { border-radius: 12px; background: var(--im3-surface-subtle); border: 1px solid var(--im3-line); }
  body.page-admin .admin-header-v2 { padding-block: 20px 28px; border-bottom: 1px solid var(--im3-line); margin-bottom: 24px; }
  body.page-admin .admin-route-desc { margin-top: 10px; max-width: 65ch; color: var(--im3-muted); }
  body.page-admin :is(.card, .overview-item, .storage-capacity-card, .status-card, .admin-overview-panel) {
    border: 1px solid var(--im3-line); border-radius: var(--im3-radius-lg); box-shadow: var(--im3-shadow-1);
    background: var(--im3-surface);
  }
  body.page-admin :is(.overview-item h4, .admin-operator-card__label) { color: var(--im3-muted); font-size: 12px; font-weight: 550; }
  body.page-admin .overview-item .value { font-size: 30px; font-weight: 650; letter-spacing: -.04em; }
  body.page-admin .overview-item .overview-meta { line-height: 1.6; }
  body.page-admin :is(.admin-panel-head, .admin-section-head) { padding-bottom: 16px; border-bottom: 1px solid var(--im3-line); margin-bottom: 20px; }
  body.page-admin :is(.admin-panel-head, .admin-section-head) h3 { margin: 0; font-size: 19px; }
  body.page-admin :is(.table-wrap, .tag-admin-table-wrap, .ai-table-scroll) {
    border: 1px solid var(--im3-line); border-radius: 12px; overflow-x: auto; overscroll-behavior-x: contain;
  }
  body.page-admin table { border-collapse: separate; border-spacing: 0; }
  body.page-admin table th { background: var(--im3-surface-subtle); color: var(--im3-muted); font-size: 12px; font-weight: 650; }
  body.page-admin table :is(th, td) { border-bottom-color: var(--im3-line); line-height: 1.6; }
  body.page-admin table tbody tr:hover { background: var(--im3-accent-50); }
  body.page-admin table tbody tr:last-child td { border-bottom: 0; }
  body.page-admin :is(.checkbox-list, .tag-admin-pane, .settings-mount-panel, .share-filter-panel, .media-detail-pane) {
    border-color: var(--im3-line); border-radius: 12px; background: var(--im3-surface-subtle);
  }
  body.page-admin :is(.update-log, .audit-details, .media-job-log) {
    border-radius: 10px; background: var(--im3-surface-subtle); border: 1px solid var(--im3-line); line-height: 1.75; overflow-wrap: anywhere;
  }
  body.page-admin :is(.admin-nav-item, .media-subtab, .tab-btn)[aria-selected="true"] {
    color: var(--im3-accent); background: var(--im3-accent-soft); border-color: var(--im3-accent-200);
  }

  /* Dialogs and task center. */
  body .modal-mask { background: #00000061; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
  body :is(.modal-card, .im-dialog, .share-watermark-card, .tag-filter-card, .entry-name-modal-card) {
    border-color: var(--im3-line); border-radius: var(--im3-dialog-radius);
    background: var(--im3-surface); box-shadow: var(--im3-shadow-3);
  }
  body :is(.modal-head, .im-dialog__header) { border-bottom-color: var(--im3-line); }
  body :is(.modal-title, .im-dialog__title) { color: var(--im3-ink); font-size: 21px; line-height: 1.35; font-weight: 650; }
  body :is(.im-dialog__footer, .upload-modal-actions) { border-top-color: var(--im3-line); background: var(--im3-surface-subtle); }
  body :is(.im-dialog__close, .gallery-modal-close, .modal-icon-close, .mobile-sheet-close) {
    min-width: 44px; min-height: 44px; border-radius: 10px; background: var(--im3-surface-subtle); color: var(--im3-muted);
  }
  body :is(.upload-modal-block, .share-modal-block, .share-link-card, .share-all-card, .tag-modal-results) {
    border-color: var(--im3-line); border-radius: 12px;
  }
  body :is(.upload-dropzone, .upload-drop-zone, .upload-source-dropzone) {
    border: 1.5px dashed var(--im3-accent-300); background: var(--im3-accent-50); border-radius: 14px;
  }
  body :is(.upload-dropzone, .upload-drop-zone, .upload-source-dropzone):hover { border-color: var(--im3-accent); }
  body .upload-task-center { background: var(--im3-surface); border-color: var(--im3-line); box-shadow: var(--im3-shadow-3); }
  body .upload-task-center__header { background: var(--im3-surface-subtle); border-bottom-color: var(--im3-line); }
  body :is(.upload-task-card, .upload-task-center__task, .upload-task-row) { border-color: var(--im3-line); border-radius: 12px; }
  body :is(.upload-task-center, .upload-modal-card) progress { height: 6px; border: 0; border-radius: 999px; overflow: hidden; }
  body :is(.share-watermark-preview, .share-mask-grid) { background: var(--im3-surface-subtle); border-radius: 12px; }

  /* Delivery and review. */
  body.page-share:not(.page-share-gate) .share-hero-v2 { border-bottom: 1px solid var(--im3-line); }
  body.page-share .share-hero-name { font-size: 34px; font-weight: 650; letter-spacing: -.04em; line-height: 1.28; }
  body.page-share .share-hero-v2__status-row { color: var(--im3-muted); }
  body.page-share :is(.share-folder-tab, .share-photo-sort-btn) { border-radius: 999px; min-height: 40px; }
  body.page-share :is(.share-folder-card, .share-photo-card) { border-radius: 10px; }
  body.page-share-review .review-header { border-bottom: 1px solid var(--im3-line); background: var(--im3-surface); }
  body.page-share-review .review-album-meta { color: var(--im3-muted); }
  body.page-share-review .review-summary { border-radius: 12px; background: var(--im3-surface-subtle); border-color: var(--im3-line); }
  body.page-share-review :is(.review-save-status, .review-expired-state) { border-color: var(--im3-line); border-radius: 12px; }
  body.page-share-review .review-photo { border-radius: 10px; }
  body :is(.lightbox, .share-lightbox, .review-lightbox) {
    --im3-ink: #f5f5f5; --im3-ink-soft: #d6d6d6; --im3-muted: #bcbcbc;
    --im3-line: #ffffff26; --im3-line-strong: #ffffff47;
    --im3-surface: #181818; --im3-surface-subtle: #242424; --im3-control: #2b2b2b;
    --im3-accent: #ededed; --im3-accent-hover: #ffffff; --im3-product-on-accent: #151515;
    --im3-focus: #93b4ff; --im3-focus-ring: 0 0 0 4px #93b4ff36;
    color-scheme: dark;
  }
  body :is(.lb-side-panel, .share-lightbox-caption-sheet) { background: #181818f5; color: #f5f5f5; border-color: #ffffff26; }
  body :is(.lb-head, .share-lightbox-head, .review-lightbox__head) { color: #f5f5f5; }

  /* Login. */
  body.page-login { background: var(--im3-canvas); }
  body.page-login .login-shell { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); align-items: center; gap: clamp(32px, 6vw, 64px); width: min(960px, 100%); }
  body.page-login .login-intro { padding: 32px 0; align-self: center; }
  .login-eyebrow { display: flex; align-items: center; gap: 12px; font-size: 12px; letter-spacing: .15em; font-weight: 650; color: var(--im3-accent); }
  .login-eyebrow::before { content: ""; width: 32px; height: 1px; background: currentColor; }
  body.page-login .login-intro h2 { margin: 28px 0 20px; font-family: var(--im3-font-sans); font-size: 38px; font-weight: 600; line-height: 1.4; letter-spacing: -.015em; }
  body.page-login .login-intro p { max-width: 30em; margin: 0; color: var(--im3-muted); font-size: 16px; line-height: 1.9; }
  body.page-login .login-intro .login-intro-foot { margin-top: 44px; font-size: 12px; letter-spacing: .04em; }
  body.page-login .panel { padding: 36px; border-radius: 22px; border: 1px solid var(--im3-line); background: var(--im3-surface); box-shadow: var(--im3-shadow-2); }
  body.page-login .brand h1 { font-size: 25px; letter-spacing: .03em; }
  body.page-login .sub { margin-bottom: 28px; }
  body.page-login :is(.password-wrap, input:not([type="hidden"])) { border-radius: 10px; }
  body.page-login .password-wrap input { border-radius: 10px 0 0 10px; }
  body.page-login .login-watermark { grid-column: 1 / -1; margin: -40px 0 0; color: var(--im3-muted); font-size: 12px; }
  body.page-share-gate .share-gate-shell { width: min(440px, 100%); }
  body.page-share-gate .share-gate-card { padding: 36px; border: 1px solid var(--im3-line); background: var(--im3-surface); border-radius: 22px; box-shadow: var(--im3-shadow-2); }
  body.page-share-gate .share-gate-brand { padding-bottom: 24px; border-bottom: 1px solid var(--im3-line); margin-bottom: 28px; }
  body.page-share-gate .share-gate-illustration { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 18px; background: var(--im3-accent-soft); color: var(--im3-accent); margin-bottom: 24px; }
  body.page-share-gate .share-gate-title { font-size: 24px; }
  body.page-share-gate .share-gate-submit-ghost { border-color: var(--im3-line-strong); color: var(--im3-accent); background: var(--im3-surface-subtle); }
  body.page-share-gate .share-gate-footer { padding-top: 20px; border-top: 1px solid var(--im3-line); }
  body .share-gate-next-step { margin: 0 0 24px; color: var(--im3-muted); line-height: 1.75; }

  /* Native disclosure remains keyboard-operable without a second state owner. */
  .im-disclosure { border-block-start: 1px solid var(--im3-line); margin-block-start: 24px; }
  .im-disclosure > summary {
    display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px;
    min-height: 48px; padding-block: 12px; cursor: pointer; list-style: none;
    color: var(--im3-ink); font-size: 14px; font-weight: 600;
  }
  .im-disclosure > summary::-webkit-details-marker { display: none; }
  .im-disclosure > summary::after {
    content: ""; width: 7px; height: 7px; margin-inline: auto 5px;
    border-inline-end: 1.5px solid currentColor; border-block-end: 1.5px solid currentColor;
    transform: rotate(45deg); transition: transform var(--im3-fast) var(--im3-ease);
  }
  .im-disclosure[open] > summary::after { transform: rotate(225deg); }
  .im-disclosure-hint { color: var(--im3-muted); font-size: 12px; font-weight: 400; }
  @keyframes im3-disclosure-reveal { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
  @media (prefers-reduced-motion: no-preference) {
    .im-disclosure[open] > :not(summary) { animation: im3-disclosure-reveal var(--im3-motion-reveal) var(--im3-ease); }
  }
  @media (prefers-reduced-transparency: reduce) {
    body :is(.modal-mask, .gallery-fab__actions, .gallery-bottom-nav, .share-toolbar-v2) {
      backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
    }
    body :is(.gallery-fab__actions, .gallery-bottom-nav, .share-toolbar-v2) { background: var(--im3-surface) !important; }
  }

  @media (hover: hover) and (pointer: fine) {
    body.page-gallery :is(.album-card, .year-card, .source-card):hover { border-color: var(--im3-line-strong); box-shadow: var(--im3-shadow-2); }
    body :is(.im-dialog__close, .gallery-modal-close, .modal-icon-close):hover { background: var(--im3-control-hover); color: var(--im3-ink); }
  }
  @media (max-width: 820px) {
    body.page-login .login-shell { display: block; width: min(440px, 100%); }
    /* Returning visitors should reach the form before promotional copy. */
    body.page-login .login-intro { display: none; }
    body.page-login .login-intro h2 { margin: 16px 0 10px; font-size: 30px; }
    body.page-login .login-intro p { font-size: 14px; max-width: none; }
    body.page-login .login-intro .login-intro-foot { display: none; }
    body.page-login .panel, body.page-share-gate .share-gate-card { padding: 24px; border-radius: 18px; }
    body.page-login .login-watermark { margin: 24px 0 0; text-align: center; }
    body.page-admin .admin-header-v2 { padding-block: 16px 20px; margin-bottom: 16px; }
    body.page-gallery .gallery-view-heading { padding-block: 8px 18px; }
    body :is(.modal-card, .im-dialog, .mobile-bottom-sheet) { max-width: 100%; }
    body :is(.im-dialog__footer, .upload-modal-actions) { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
    body :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea) { font-size: 16px; }
    body :is(.modal-title, .im-dialog__title) { font-size: 20px; }
    body :is(.share-folder-tab, .share-photo-sort-btn) { min-height: 44px; }
  }
  @media (max-width: 360px) {
    body.page-login .panel, body.page-share-gate .share-gate-card { padding: 20px; }
    body.page-login .login-intro h2 { font-size: 27px; }
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --im3-canvas: #121212; --im3-canvas-strong: #0c0c0c;
      --im3-surface: #1b1b1b; --im3-surface-raised: #262626;
      --im3-surface-subtle: #222222; --im3-surface-muted: #2c2c2c;
      --im3-control: #222222; --im3-control-hover: #343434;
      --im3-ink: #f5f5f5; --im3-ink-soft: #d6d6d6; --im3-muted: #b3b3b3; --im3-faint: #a3a3a3;
      --im3-line: #363636; --im3-line-strong: #666666;
      --im3-accent: #ededed; --im3-accent-hover: #ffffff; --im3-accent-soft: #333333;
      --im3-accent-50: #272727; --im3-accent-100: #333333; --im3-accent-200: #505050;
      --im3-accent-300: #757575; --im3-accent-400: #a3a3a3; --im3-accent-500: #cccccc;
      --im3-accent-600: #ededed; --im3-accent-700: #ffffff;
      --im3-success: #9cdeb5; --im3-warning: #ecc38b; --im3-danger: #ffabb0;
      --im3-focus: #93b4ff; --im3-focus-outer: #121212; --im3-focus-ring: 0 0 0 4px #93b4ff2b;
      --im3-product-on-accent: #151515;
      --im3-shadow-1: 0 1px 4px #00000019; --im3-shadow-2: 0 12px 32px -12px #00000055;
      --im3-shadow-3: 0 24px 72px -12px #00000099;
      color-scheme: dark;
    }
    body .modal-mask { background: #0000008c; }
  }
  @media (prefers-contrast: more) {
    :root { --im3-muted: #454545; --im3-faint: #555555; --im3-line: #909090; --im3-line-strong: #626262; }
  }
  @media (prefers-color-scheme: dark) and (prefers-contrast: more) {
    :root { --im3-muted: #e0e0e0; --im3-faint: #cccccc; --im3-line: #909090; --im3-line-strong: #bcbcbc; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  }
  @media (forced-colors: active) {
    body :is(.btn, .im-button, .modal-card, .im-dialog, .panel, .share-gate-card) { border: 1px solid ButtonText; }
    body :focus-visible { outline: 2px solid Highlight; box-shadow: none; }
  }
}
