/* Interface foundations. Loaded after component sheets. Existing selectors are
   migration adapters; new UI can use .ui-action, .ui-field and .ui-dialog.
   Layout, canvas artwork, icon palettes and thumbnail geometry stay in modules. */
:root {
    --button-height: 40px;
    --button-padding-x: 24px;
    --button-radius: var(--ui-button-radius, 999px);
    --button-font-size: 16px;
    --button-font-weight: 600;
    --button-letter-spacing: 0px;
    --text-entry-bg: var(--color-field, var(--app-color-forms-f2ede4,#f2ede4));
    --text-entry-shadow: inset 0 2px 5px var(--app-color-forms-00000022,#0002);
    --text-entry-shadow-focus: var(--text-entry-shadow);
    --ui-field-height: 40px;
    --ui-field-padding-y: 8px;
    --ui-field-font-size: 16px;
    --ui-field-radius: 999px;
    --ui-textarea-radius: 16px;
    --ui-accent: var(--app-color-forms-584eb6,#584eb6);
    --ui-secondary: var(--app-color-forms-555555,#555);
    --ui-control: var(--color-neutral, var(--app-color-forms-eee9e0,#eee9e0));
    --ui-control-hover: var(--app-color-forms-f0eeea,#f0eeea);
    --ui-dialog-radius: 36px;
    --ui-dialog-radius-mobile: 28px;
    --ui-dialog-heading: 28px;
    --ui-dialog-action-height: 48px;
    --ui-dialog-shadow: 0 20px 60px var(--app-color-forms-00000022,#0002);
}

/* Overlay foundations shared with the Design dashboard. Keep specialized media
   canvases and compact icon controls at their own sizes. */
:is(.auth-dialog, .memory-chapter-dialog, .memory-team-dialog, .capture-new-memory-dialog, .tutorial-player-dialog, .tcs-dialog) {
    --overlay-control: var(--ui-control);
    border: 0; border-radius: var(--ui-dialog-radius); background: var(--bg, var(--app-color-forms-f7f5eb,#f7f5eb)); font-family: var(--font-body);
}
.auth-dialog { padding: 29px; max-height: calc(100dvh - 48px); overflow-y: auto; }
.auth-dialog > .auth-eyebrow { margin: 0 24px 16px; text-align: center; color: var(--ui-accent); font: 800 12px/20px var(--font-body); letter-spacing: 1px; }
.auth-dialog > h3 { margin: 0 24px 24px; text-align: center; color: var(--app-color-forms-000000,#000); font: 700 28px/1.15 var(--font-body); }
.auth-dialog > .auth-close { top: 22px; right: 24px; width: 24px; height: 24px; padding: 0; line-height: 24px; color: var(--app-color-forms-555555,#555); }
:is(.auth-dialog, .memory-chapter-dialog, .memory-team-dialog, .capture-new-memory-dialog, .tutorial-player-dialog, .tcs-dialog) button:not(:disabled):hover { opacity: 1 !important; }
.auth-dialog :is(.btn-primary, .btn-outline, .btn-ghost),
.auth-dialog form > button, .auth-code-actions button { border-radius: 999px !important; font-family: var(--font-body); }
.auth-dialog :is(.btn-outline, .btn-ghost):not(:disabled):hover { background: var(--ui-control) !important; }
.auth-dialog .btn-primary.is-settings-pristine,
.auth-dialog .btn-primary.is-settings-pristine:is(:hover, :focus-visible, :active) { background: var(--ui-control) !important; color: var(--app-color-forms-555555,#555) !important; opacity: 1 !important; }
.auth-dialog > :is(.style-profile-actions, .app-dialog-actions) { display: flex; flex-direction: row; justify-content: center; gap: 16px; margin-top: 28px; }
.auth-dialog > :is(.style-profile-actions, .app-dialog-actions) > :is(.btn-primary, .btn-outline),
.memory-chapter-dialog footer button {
    flex: 0 1 160px; width: 160px !important; min-width: 0; height: 48px !important; min-height: 48px !important;
    padding: 0 var(--button-padding-x) !important; border-radius: 999px !important; font: 600 var(--button-font-size)/1.2 var(--font-body) !important;
    text-transform: none; letter-spacing: 0 !important; white-space: normal;
}
.auth-dialog > :is(.style-profile-actions, .app-dialog-actions) > .btn-outline { border: 1px solid var(--app-color-forms-000000,#000) !important; background: transparent !important; }
@media (max-width: 600px) {
    :is(.auth-dialog, .memory-chapter-dialog, .memory-team-dialog, .capture-new-memory-dialog, .tutorial-player-dialog, .tcs-dialog) { border-radius: var(--ui-dialog-radius-mobile); }
    .auth-dialog { padding: 24px 20px 20px; max-height: calc(100dvh - 24px); }
    .auth-dialog > h3 { font-size: 26px; }
    .auth-dialog > :is(.style-profile-actions, .app-dialog-actions) { gap: 12px; }
}
.memory-chapter-dialog footer { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px; }
.memory-chapter-dialog footer [data-delete] { margin-right: auto; }
#authModal form > .btn-primary {
    height: 48px !important; min-height: 48px !important; font: 600 var(--button-font-size)/1.2 var(--font-body) !important;
    letter-spacing: 0 !important; text-transform: none;
}
#memoryChapterDialog h2 { margin: 0 24px 16px; text-align: center; font: 700 28px/1.15 var(--font-body); }
#memoryChapterDialog footer button { text-transform: none; }
#memoryChapterDialog footer [data-close] { border: 1px solid var(--app-color-forms-000000,#000); background: transparent; }

/* Text actions: shared type and shape, separate semantic colors below. */
:is(.ui-action, .pl-primary, .pl-secondary, .pl-danger, .pl-new, .pl-delete-list, .pl-suggestion,
    .rm-plans-cta,
    .memory-team-compose button[type="submit"], .content-group-actions button, .ai-sticker-upload-choice, .sticker-library-panel > .btn-secondary,
    .memory-team-request, .memory-team-add, .memory-team-photo button, .memory-team-reply-action) {
    box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center;
    gap: 8px; min-height: var(--ui-dialog-action-height); padding: 10px var(--button-padding-x);
    border: 0; border-radius: var(--button-radius); box-shadow: var(--ui-button-stroke, none);
    font: var(--button-font-weight) var(--button-font-size)/1.25 var(--font-body);
    letter-spacing: 0; text-transform: none; text-decoration: none; text-align: center;
    cursor: pointer; white-space: normal; overflow-wrap: anywhere;
}
.sticker-library-panel > .btn-secondary { background: var(--ui-control); color: var(--app-color-forms-111111,#111); }
.ui-action { background: var(--ui-control); color: var(--app-color-forms-111111,#111); }
.ui-action--compact, .pl-suggestion,
.memory-team-request, .memory-team-add, .memory-team-photo button, .memory-team-reply-action { min-height: var(--button-height); }
:root .ui-action.ui-action--outline,
:is(.ui-action--outline, .pl-secondary) { border: 1px solid var(--app-color-forms-111111,#111); background: transparent; color: var(--app-color-forms-111111,#111); }
:is(.ui-action--primary, .memory-team-compose button[type="submit"]) { background: var(--green,var(--app-color-forms-00b252,#00b252)); color: var(--bg,var(--app-color-forms-f7f5eb,#f7f5eb)); }
.ui-action--danger { background: var(--app-color-forms-ef4444,#ef4444); color: var(--bg,var(--app-color-forms-f7f5eb,#f7f5eb)); }
/* Match the existing Figma footer without inheriting the legacy 40px button rule. */
.content-group-actions :is(.btn-primary,.btn-outline) {
    height: auto !important; min-height: var(--ui-dialog-action-height) !important;
    flex: 0 1 160px; width: 160px; padding: 10px var(--button-padding-x) !important; line-height: 1.25 !important;
    letter-spacing: 0 !important; text-transform: none; white-space: normal;
}
.content-group-actions .btn-outline { border: 1px solid var(--app-color-forms-111111,#111) !important; background: transparent !important; }
.content-group-actions .btn-primary.is-settings-dirty:not(:disabled) { background: var(--green,var(--app-color-forms-00b252,#00b252)) !important; color: var(--bg,var(--app-color-forms-f7f5eb,#f7f5eb)) !important; }
:is(.ui-action, .memory-team-compose button[type="submit"]):disabled { background: var(--ui-control); color: var(--ui-secondary); cursor: default; }
/* Preserve icon/text contrast. Selected/primary/danger surfaces retain meaning. */
:root :is(.btn-outline,.btn-ghost,.ui-action--outline,.pl-secondary,.pl-suggestion,
    .memory-team-reply-action,
    .memory-team-photo button,.sticker-library-panel > .btn-secondary):not(:disabled):hover {
    background-color: var(--ui-control-hover) !important; opacity: 1 !important;
}
:root :is(.ui-action,.pl-primary,.pl-secondary,.pl-danger,.pl-new,.pl-delete-list,.pl-suggestion,
    .rm-plans-cta):not(:disabled):hover { opacity: 1 !important; }

/* Input surfaces do not apply to contenteditable canvas prose or native toggles.
   Important declarations bridge older form rules; each removed module exception
   now resolves to these tokens instead of a new local visual override. */
:root :where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="hidden"]),textarea,.ui-field) {
    box-sizing: border-box; border-radius: var(--ui-field-radius) !important;
    background-color: var(--text-entry-bg); font-family: var(--font-body); font-size: var(--ui-field-font-size) !important;
}
:root textarea { border-radius: var(--ui-textarea-radius) !important; }
/* Pointer focus uses the control's own treatment. Keyboard focus stays visible. */
:root :is(input,textarea,select,button,a[href],[role="button"]):focus:not(:focus-visible) {
    outline: none !important;
}
/* Every native dropdown uses the same pill geometry and an inset CSS chevron. */
select {
    appearance: none !important;
    -webkit-appearance: none !important;
    padding-right: 44px !important;
    border-radius: 999px !important;
    background-color: var(--ui-control) !important;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--color-select-arrow, var(--app-color-forms-000000,#000)) 50%),
        linear-gradient(135deg, var(--color-select-arrow, var(--app-color-forms-000000,#000)) 50%, transparent 50%) !important;
    background-position:
        calc(100% - 23px) 50%,
        calc(100% - 18px) 50% !important;
    background-size: 5px 5px, 5px 5px !important;
    background-repeat: no-repeat !important;
}

/* Form dropdowns share input typography; compact canvas category selectors keep
   their own dimensions. Native option and date pickers remain available. */
:is(.capture-new-memory-form, .reel-controls, .style-profile-field, .profile-form-field,
    .collab-form, .memory-chapter-dialog, .capture-routing-move) select,
select:is(.form-select,.form-input) {
    box-sizing: border-box; min-width: 0; min-height: 44px; padding: 10px 18px; border: 0;
    font: 400 var(--ui-field-font-size)/1.4 var(--font-body); letter-spacing: 0; text-transform: none;
}
.capture-new-memory-form input { min-height: 44px; padding: 10px 18px; font-weight: 400; }


/* Shared central dialog frame. Side panels and media previews keep their layout. */
:is(.ui-dialog,.content-group-dialog,.profile-lists-dialog,.memory-reel-dialog,.rm-plans-dialog) {
    border-radius: var(--ui-dialog-radius); background: var(--bg,var(--app-color-forms-f7f5eb,#f7f5eb)); color: var(--app-color-forms-111111,#111);
    font-family: var(--font-body); box-shadow: var(--ui-dialog-shadow);
}
:is(.ui-dialog-title,.content-group-dialog h2,.pl-header h2,.memory-reel-dialog h2,.memory-team-heading h2,.rm-plans-dialog h2,.capture-new-memory-dialog h3) {
    font: 700 var(--ui-dialog-heading)/1.15 var(--font-body); letter-spacing: 0;
    text-transform: none; color: var(--app-color-forms-111111,#111);
}
:is(.content-group-dialog h2,.memory-reel-dialog h2,.rm-plans-dialog h2,.capture-new-memory-dialog h3) { margin: 0 32px 24px; text-align: center; }
.pl-header { position: relative; padding-right: 64px; }
.pl-header > div { width: 100%; text-align: center; }
:is(.ui-dialog-close,.content-group-close,.profile-lists-dialog .pl-close,.rm-plans-close,.memory-team-close,.capture-new-memory-close,
.memory-chapter-dialog header [data-close]) {
    position: absolute; top: 22px; right: 24px; display: grid; place-items: center;
    width: 24px; height: 24px; min-height: 24px; padding: 0; border: 0; border-radius: 50%;
    background: transparent; color: var(--ui-secondary); font: 400 24px/1 var(--font-body) !important; cursor: pointer;
}
:is(.ui-dialog-close,.content-group-close,.pl-close,.rm-plans-close,.memory-team-close,.capture-new-memory-close,
.memory-chapter-dialog header [data-close])::before { content:''; position:absolute; inset:-10px; }
:is(.content-group-eyebrow,.reel-eyebrow) { display:block; margin:0 32px 16px; text-align:center; color:var(--ui-accent); font:800 12px/20px var(--font-body); letter-spacing:1px; text-transform:uppercase; }
@media(max-width:600px) {
    :root { --ui-dialog-heading:26px; }
    :is(.ui-dialog,.content-group-dialog,.profile-lists-dialog,.memory-reel-dialog,.rm-plans-dialog) { border-radius:var(--ui-dialog-radius-mobile); }
    .content-group-actions [data-group-release] { flex-basis:100%; width:100%; }
    .content-group-actions :is(.btn-primary,.btn-outline) { flex-grow:1; min-width:0; }
}

/* Secondary panels use the same selected purple / neutral hover as Design tabs.
   Explicit adapters avoid changing icon grids or controls on the memory canvas. */
:is(.ui-tabs, .memory-team-tabs, .ai-sticker-mode-switch, .rm-plans-billing) > button {
    box-sizing: border-box; min-width: 0; min-height: var(--ui-dialog-action-height);
    padding: 10px var(--button-padding-x); border: 0; border-radius: var(--button-radius);
    background: var(--ui-control); color: var(--app-color-forms-111111,#111);
    font: var(--button-font-weight) var(--button-font-size)/1.25 var(--font-body);
    text-transform: none; letter-spacing: 0; white-space: normal; overflow-wrap: anywhere;
    cursor: pointer;
}
:is(.ui-tabs, .memory-team-tabs, .ai-sticker-mode-switch, .rm-plans-billing) > button:is([aria-selected="true"],[aria-pressed="true"],.active) {
    background: var(--ui-accent); color: var(--bg,var(--app-color-forms-f7f5eb,#f7f5eb));
}
:is(.ui-tabs, .memory-team-tabs, .ai-sticker-mode-switch, .rm-plans-billing) > button:not([aria-selected="true"]):not([aria-pressed="true"]):not(.active):not(:disabled):hover {
    background: var(--ui-control-hover); opacity: 1;
}
/* Keep four desktop mode labels on one line with the shared side padding. */
.auth-dialog.ai-sticker-dialog { width:min(660px,100%); }
.ai-sticker-styles button {
    min-height: var(--button-height); padding: 8px var(--button-padding-x); border: 1px solid var(--app-color-forms-111111,#111);
    border-radius: var(--button-radius); background: transparent; color: var(--app-color-forms-111111,#111);
    font: var(--button-font-weight) var(--button-font-size)/1.25 var(--font-body);
    letter-spacing: 0; text-transform: none; cursor: pointer;
}
.ai-sticker-styles button.active { background: var(--app-color-forms-111111,#111); color: var(--bg,var(--app-color-forms-f7f5eb,#f7f5eb)); }
.ai-sticker-styles button:not(.active):not(:disabled):hover { background: var(--ui-control-hover); }
.ai-sticker-modal .ai-sticker-upload-choice { font-size: var(--button-font-size); font-weight: var(--button-font-weight); }
.ai-sticker-actions button, .ai-sticker-modal .ai-sticker-generate {
    min-height: var(--ui-dialog-action-height) !important;
}
.ai-sticker-confirm-actions [data-ai-sticker-cancel] { border: 1px solid var(--app-color-forms-111111,#111) !important; background: transparent !important; }
.ai-sticker-confirm-actions [data-ai-sticker-cancel]:hover { background: var(--ui-control-hover) !important; }
.memory-team-heading { padding-right: 32px; }
.memory-team-heading h2 { margin: 0; }
.capture-new-memory-dialog { box-sizing: border-box; max-height: calc(100dvh - 48px); overflow-y: auto; }
.capture-new-memory-actions > button {
    flex: 1 1 130px; width: auto; height: auto !important;
    min-height: var(--ui-dialog-action-height) !important; padding: 10px var(--button-padding-x) !important;
    line-height: 1.25 !important; white-space: normal; overflow-wrap: anywhere;
}
.capture-new-memory-cancel { border: 1px solid var(--app-color-forms-111111,#111) !important; background: transparent !important; }
.capture-new-memory-cancel:not(:disabled):hover { background: var(--ui-control-hover) !important; }
.capture-new-memory-form label { min-width: 0; }
@media(max-width:420px) {
    .capture-new-memory-date-grid { grid-template-columns: minmax(0,1fr); }
}

/* Equal-width choices; Cancel keeps the standard fixed action size. */
.auth-dialog.app-dialog--choice-pair { width:min(640px,100%); }
.auth-dialog.app-dialog--choice-pair > .app-dialog-message { text-align:center; }
.auth-dialog.app-dialog--choice-pair > .app-dialog-actions {
    display:grid; grid-template-columns:repeat(4,1fr); gap:16px;
    width:max-content; max-width:100%; margin-left:auto; margin-right:auto;
}
.auth-dialog.app-dialog--choice-pair > .app-dialog-actions > .app-dialog-action {
    grid-column:span 2; width:auto!important; min-width:160px; white-space:nowrap;
}
.auth-dialog.app-dialog--choice-pair > .app-dialog-actions > .is-secondary {
    grid-column:2 / span 2; justify-self:center; width:160px!important;
}
@media(max-width:480px) {
    .auth-dialog.app-dialog--choice-pair > .app-dialog-actions { grid-template-columns:minmax(0,1fr); width:100%; }
    .auth-dialog.app-dialog--choice-pair > .app-dialog-actions > .app-dialog-action { grid-column:1; }
}
