* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #0e0f13;
    color: #f5f5f7;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

.app {
    width: min(950px, 100%);
    margin: 0 auto;
    padding: 28px 18px 80px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 36px;
}

h1 {
    margin: 0;
    font-size: 28px;
}

h2 {
    margin: 0 0 8px;
    font-size: 23px;
}

h3 {
    margin: 0 0 16px;
    font-size: 17px;
}

h4 {
    margin: 0 0 12px;
    font-size: 16px;
}

header p,
.hint,
.chat-id {
    color: #9295a0;
    font-size: 13px;
}

header p {
    margin: 5px 0 0;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.section-heading .hint {
    margin: 0;
}

.card {
    margin-bottom: 16px;
    padding: 20px;
    background: #17181e;
    border: 1px solid #292b33;
    border-radius: 14px;
}

.card h3 {
    margin-top: 0;
}

label {
    display: block;
    margin-bottom: 16px;
    color: #b7bac3;
    font-size: 13px;
}

input,
textarea,
select {
    display: block;
    width: 100%;
    margin-top: 7px;
    padding: 12px;
    background: #101116;
    color: #f5f5f7;
    border: 1px solid #30323b;
    border-radius: 9px;
    font: inherit;
}

input:focus,
textarea:focus,
select:focus {
    outline: 2px solid #6478a8;
    outline-offset: 1px;
}

textarea {
    resize: vertical;
}

button {
    font: inherit;
    cursor: pointer;
}

button:focus-visible {
    outline: 2px solid #a6b9ec;
    outline-offset: 3px;
}

.primary,
.secondary,
.danger {
    padding: 11px 15px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 650;
}

.primary {
    border: 1px solid #f1f1f3;
    background: #f1f1f3;
    color: #101116;
}

.primary:hover {
    background: #d8d9df;
}

.secondary {
    border: 1px solid #373a44;
    background: #24262e;
    color: #e5e6eb;
}

.secondary:hover {
    background: #30333d;
}

.danger {
    border: 1px solid #693c42;
    background: #342025;
    color: #f1b2bb;
}

.danger:hover {
    background: #492b31;
}

.wide {
    width: 100%;
}

.conversation {
    display: block;
    width: 100%;
    margin-bottom: 12px;
    padding: 18px;
    border: 1px solid #292b33;
    border-radius: 14px;
    background: #17181e;
    color: inherit;
    text-align: left;
}

.conversation:hover {
    background: #1d1f26;
}

.conversation-name {
    font-size: 17px;
    font-weight: 650;
}

.conversation-id {
    margin-top: 5px;
    color: #777b86;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.link-button,
.add {
    padding: 0;
    border: 0;
    background: transparent;
    color: #adb7d5;
}

.link-button:hover,
.add:hover {
    text-decoration: underline;
}

.editor-heading {
    margin: 25px 0;
}

.chat-id {
    margin: 0;
    overflow-wrap: anywhere;
}

.tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 22px;
    padding: 5px;
    border: 1px solid #292b33;
    border-radius: 12px;
    background: #17181e;
}

.tab {
    flex: 1;
    padding: 12px 8px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: #a1a4ae;
    font-size: 13px;
    font-weight: 650;
}

.tab.active {
    background: #30333d;
    color: #fff;
}

.tab:hover:not(.active) {
    background: #22242c;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.list-row {
    display: flex;
    gap: 8px;
    margin-bottom: 9px;
}

.list-row input {
    margin: 0;
}

.remove {
    width: 42px;
    flex-shrink: 0;
    border: 0;
    border-radius: 9px;
    background: #292b33;
    color: #aaaeb8;
    font-size: 20px;
}

.add {
    margin-top: 7px;
}

.search {
    margin: 0 0 20px;
}

.record-card {
    margin-bottom: 12px;
}

.record-meta {
    margin: 0 0 8px;
    color: #a1b0d2;
    font-size: 12px;
}

.record-content {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    margin: 0 0 14px;
    color: #d4d5dd;
    font-size: 14px;
}

.record-actions,
.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    margin-top: 18px;
}

.status {
    min-height: 20px;
    color: #b5c8b5;
    font-size: 13px;
    text-align: center;
}

.error {
    color: #e5a0a0;
    font-size: 13px;
}

.hidden {
    display: none !important;
}

.login-card {
    max-width: 430px;
    margin: 60px auto 0;
}

@media (max-width: 600px) {
    .app {
        padding: 20px 14px 60px;
    }

    .header {
        align-items: flex-start;
    }

    .section-heading {
        align-items: flex-start;
    }

    .card {
        padding: 16px;
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .tab {
        padding: 11px 5px;
        font-size: 12px;
    }

    .primary,
    .secondary,
    .danger {
        padding: 10px 12px;
    }
}


/* Tags des souvenirs */

.event-tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin: 12px 0;
}

.event-tag-badge {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.4;
    overflow-wrap: anywhere;
    color: #FFFFFF;
    background: #555F73;
    border: 1px solid transparent;
}

.event-tag-person {
    background: #508CDC;
}

.event-tag-topic {
    background: #3CAA7D;
}

.event-tag-episode {
    background: #D62839;
}

.event-tag-sex {
    background: #FF69B4;
    color: #301024;
}

.event-tags-fieldset {
    min-width: 0;
    margin: 14px 0;
    padding: 14px;
    border: 1px solid rgba(130, 140, 160, 0.3);
    border-radius: 12px;
}

#event-tags-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.event-tag-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: auto;
    padding: 8px 12px;
    border: 1px solid rgba(130, 140, 160, 0.3);
    border-radius: 10px;
    cursor: pointer;
}

.event-tag-option input[type="checkbox"] {
    width: auto;
    margin: 0;
    accent-color: #6599dc;
}

.event-tag-option:has(input:checked) {
    border-color: #6599dc;
}

.event-tag-option:has(input:disabled) {
    opacity: 0.55;
    cursor: not-allowed;
}

#tag-management-list {
    display: grid;
    gap: 8px;
    margin-top: 15px;
}

#tag-management-list .record-actions {
    align-items: center;
    flex-wrap: wrap;
}

@media (max-width: 600px) {
    .event-tag-option {
        max-width: 100%;
    }

    .event-tag-badge {
        font-size: 0.75rem;
    }
}

/* V4.8: compact category-based selectable tag pills */
.event-date-filter{display:flex;align-items:end;gap:10px;flex-wrap:wrap;margin:12px 0}
.event-date-filter label{flex:0 1 210px}
#event-tag-search{width:100%;margin:6px 0 12px}
#event-tags-options{display:block}
.event-tag-group{margin:0 0 12px}
.event-tag-group-title{display:block;font-size:.8rem;opacity:.8;margin-bottom:6px}
.event-tag-pills{display:flex;flex-wrap:wrap;gap:5px}
.event-tag-pills .event-tag-option{display:inline-flex;width:auto;min-height:0;padding:5px 10px;border-radius:999px;cursor:pointer;margin:0;border:2px solid transparent;font-size:.84rem;line-height:1.3;gap:0}
.event-tag-pills .event-tag-option input{position:absolute;opacity:0;width:1px;height:1px;pointer-events:none}
.event-tag-pills .event-tag-option:has(input:checked){border-color:currentColor;outline:1px solid currentColor;outline-offset:1px;font-weight:700}
.event-tag-pills .event-tag-option:focus-within{outline:2px solid currentColor;outline-offset:2px}
.event-tag-pills .event-tag-option:has(input:disabled){opacity:.5}

/* V4.8: tag creation and inline editing */
.event-tag-create{display:flex;flex-wrap:wrap;align-items:end;gap:10px;padding:10px 0}
.event-tag-create label{min-width:145px;flex:0 1 180px}
.event-tag-create #event-tag-create-label{font-weight:600;align-self:center}
.tag-edit-form{margin-top:14px;padding:14px;border:1px solid rgba(130,140,160,.35);border-radius:12px}
.tag-edit-form h4{margin:0 0 10px}
.tag-edit-form label{display:block;margin:8px 0}
.event-tag-pills .event-tag-option:has(input:checked){border-color:#fff;outline:2px solid #6599dc;outline-offset:1px}
.event-tag-pills .event-tag-option.event-tag-sex:has(input:checked){border-color:#301024;outline-color:#FF69B4}

.event-tag-create.hidden{display:none}

/* V4.8 correction: no visible checkbox, only selectable colored pills.
   Override the generic input checkbox selector and old label styles. */
.event-tag-pills .event-tag-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: auto;
  gap: 0;
  padding: 6px 12px;
  margin: 0;
  border: 2px solid transparent;
  border-radius: 999px;
  font-weight: 500;
}
.event-tag-pills .event-tag-option input[type="checkbox"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: 0;
  border: 0;
  opacity: 0;
  clip-path: inset(50%);
  overflow: hidden;
  pointer-events: none;
}
.event-tag-pills .event-tag-option:has(input:checked) {
  border-color: #fff;
  outline: 2px solid #6599dc;
  outline-offset: 1px;
  font-weight: 700;
}
.event-tag-pills .event-tag-option.event-tag-sex:has(input:checked) {
  border-color: #301024;
  outline-color: #fff;
}

/* V4.8.3 — understated selected tag pills */
.event-tag-pills .event-tag-option:has(input:checked),
.event-tag-pills .event-tag-option.event-tag-sex:has(input:checked) {
    border: 2px solid rgba(255, 255, 255, .72);
    outline: none;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
    font-weight: 700;
}
.event-tag-pills .event-tag-option:has(input:checked)::after {
    content: "✓";
    display: inline-block;
    margin-left: 7px;
    font-size: .8em;
    line-height: 1;
}
.event-tag-pills .event-tag-option:focus-within {
    outline: 2px solid rgba(255, 255, 255, .8);
    outline-offset: 2px;
}

/* V4.8.4 — quick tag creation: aligned, compact responsive layout */
.event-tag-create:not(.hidden) {
    display: flex;
    align-items: end;
    flex-wrap: wrap;
    column-gap: 12px;
    row-gap: 10px;
    padding: 8px 0 4px;
    margin: 0;
}
.event-tag-create #event-tag-create-label {
    flex: 0 1 auto;
    align-self: center;
    margin: 0;
    font-size: .94rem;
    white-space: normal;
}
.event-tag-create label {
    display: flex;
    flex-direction: column;
    flex: 0 1 185px;
    min-width: 155px;
    width: auto;
    margin: 0;
    gap: 5px;
    font-size: .85rem;
}
.event-tag-create label select {
    width: 100%;
    margin: 0;
}
.event-tag-create #event-tag-create-button {
    align-self: end;
    width: auto;
    margin: 0;
    white-space: nowrap;
}
#event-tags-options:empty { margin: 0; }
#event-tags-hint { margin-top: 8px; }
#event-tag-create-status:empty { display: none; }
@media (max-width: 580px) {
    .event-tag-create:not(.hidden) { align-items: stretch; }
    .event-tag-create #event-tag-create-label { flex-basis: 100%; }
    .event-tag-create label { flex: 1 1 150px; }
    .event-tag-create #event-tag-create-button { flex: 1 1 auto; }
}

/* V4.8.5 — center quick-create controls vertically */
.event-tag-create:not(.hidden) {
    align-items: center;
}
.event-tag-create #event-tag-create-label {
    align-self: center;
}
.event-tag-create #event-tag-create-button {
    align-self: center;
}
@media (max-width: 580px) {
    .event-tag-create:not(.hidden) {
        align-items: center;
    }
    .event-tag-create #event-tag-create-button {
        align-self: center;
    }
}

/* V4.8.6: true vertical centering — category label visually hidden */
.event-tag-create:not(.hidden) {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}
.event-tag-create .event-tag-kind-label {
    display: block;
    flex: 0 1 220px;
    min-width: 155px;
    margin: 0;
    align-self: center;
}
.event-tag-create .event-tag-kind-label select {
    display: block;
    width: 100%;
    margin: 0;
}
.event-tag-create #event-tag-create-label,
.event-tag-create #event-tag-create-button {
    align-self: center;
    margin: 0;
}
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
@media (max-width: 580px) {
    .event-tag-create .event-tag-kind-label { flex: 1 1 150px; }
}

/* V4.8.7 — preserve the complete quick-create label */
.event-tag-create #event-tag-create-label {
    flex: 0 0 auto;
    min-width: max-content;
    max-width: 100%;
    overflow-wrap: anywhere;
    white-space: normal;
}
@media (max-width: 580px) {
    .event-tag-create #event-tag-create-label {
        flex: 0 0 100%;
        min-width: 0;
    }
}

/* V4.8.8 — RP date filter: align control with button, brighten native calendar icon */
.event-date-filter {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 12px;
}
.event-date-filter > label {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    flex: 0 1 250px;
    min-width: 200px;
    margin: 0;
}
.event-date-filter #event-date-filter {
    margin: 7px 0 0;
    min-height: 48px;
    color-scheme: dark;
}
.event-date-filter #event-date-filter::-webkit-calendar-picker-indicator {
    filter: invert(1);
    opacity: .9;
    cursor: pointer;
}
.event-date-filter #event-date-clear {
    align-self: flex-end;
    min-height: 48px;
    margin: 0;
}
@media (max-width: 440px) {
    .event-date-filter > label { flex: 1 1 100%; }
    .event-date-filter #event-date-clear { width: 100%; }
}

/* V4.8.9 — draw a white calendar glyph independently of browser native icon */
.event-date-filter > label { position: relative; }
.event-date-filter > label::after {
    content: "";
    position: absolute;
    right: 15px;
    bottom: 14px;
    width: 20px;
    height: 20px;
    pointer-events: none;
    background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='16' rx='2'/%3E%3Cpath d='M16 3v4M8 3v4M3 10h18'/%3E%3C/svg%3E");
}
.event-date-filter #event-date-filter::-webkit-calendar-picker-indicator {
    opacity: 0;
    filter: none;
    cursor: pointer;
}

/* V4.8.10 — floating back-to-top button */
.back-to-top {
    position: fixed;
    right: max(18px, env(safe-area-inset-right));
    bottom: max(20px, env(safe-area-inset-bottom));
    z-index: 100;
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    padding: 0;
    color: #f5f5f7;
    background: #303541;
    border: 1px solid #697386;
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
    cursor: pointer;
}
.back-to-top[hidden] { display: none; }
.back-to-top:hover { background: #44516a; }
.back-to-top:focus-visible { outline: 2px solid #a6b9ec; outline-offset: 3px; }
.back-to-top svg { width: 24px; height: 24px; }

/* V4.8.11 — readable captured context */
.injected-context-text {
    max-height: 480px;
    overflow: auto;
    padding: 14px;
    border: 1px solid #424957;
    border-radius: 8px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font: 12px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace;
    color: #e5e9f1;
    background: #10141d;
}

/* V4.8.12 — simulator */
.simulator-result { padding: 12px 0; border-bottom: 1px solid #353a45; }
.simulator-result details { margin-top: 6px; }
.simulator-result summary { cursor: pointer; }
.simulator-result pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }


/* V4.9.5 — Characters: structured, colorful and restrained */
.character-page { --cp-purple:#aa91ff; --cp-blue:#78b9ff; --cp-amber:#f2c574; --cp-teal:#69d3bf; }
.character-hero {
    display:flex; align-items:center; justify-content:space-between; gap:22px;
    margin:8px 0 22px; padding:25px 27px; border-radius:16px;
    border:1px solid #444064;
    background:linear-gradient(112deg,rgba(91,67,151,.27),rgba(37,43,72,.36) 65%,rgba(36,71,92,.23));
}
.character-eyebrow {font-size:10px;letter-spacing:2px;font-weight:800;color:#c4b3ff;}
.character-hero h3 {font-size:25px;margin:7px 0 5px;}
.character-hero p {color:#b9bfd0;margin:0;line-height:1.5;max-width:620px;}
.character-create-trigger {flex-shrink:0;background:#7258bc;border-color:#9073db;color:white;}
.character-create-trigger:hover {background:#8669d2;}
.character-panel {
    margin:0 0 19px; padding:23px 25px; border-radius:14px;
    border:1px solid #333b4d; background:#191c25;
    box-shadow:0 8px 24px rgba(0,0,0,.10);
}
.character-panel-create {border-color:#68518f;background:linear-gradient(130deg,#231d33,#1a1c26);}
.character-panel-roster {border-top:3px solid #638fc9;}
.character-panel-suggestions {border-top:3px solid #c49953;}
.character-panel-manual {border-top:3px solid #4eab9e;}
.character-panel-heading {display:flex;align-items:center;gap:13px;margin-bottom:18px;}
.character-panel-heading h4 {font-size:16px;margin:0 0 5px;color:#f2f3fa;}
.character-panel-heading p {margin:0;color:#aeb6c8;font-size:12px;line-height:1.55;}
.character-panel-icon {display:grid;place-items:center;flex:none;width:39px;height:39px;border-radius:12px;font-size:21px;font-weight:700;}
.character-icon-purple {background:rgba(162,126,247,.15);color:var(--cp-purple);}
.character-icon-blue {background:rgba(95,166,242,.15);color:var(--cp-blue);}
.character-icon-amber {background:rgba(239,188,97,.13);color:var(--cp-amber);}
.character-icon-teal {background:rgba(89,209,184,.13);color:var(--cp-teal);}
.character-form-grid {display:grid;grid-template-columns:1fr 1fr;gap:16px;}
.character-form-grid label {min-width:0;}
.character-actions {display:flex;gap:10px;flex-wrap:wrap;}
.character-roster {display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:12px;margin:12px 0 23px;}
.character-roster-item {display:flex;align-items:center;gap:12px;min-width:0;padding:14px;border-radius:12px;border:1px solid #384257;background:#202636;}
.character-avatar {display:grid;place-items:center;flex:none;width:43px;height:43px;border-radius:12px;background:linear-gradient(135deg,#7055ad,#456fa3);color:#fff;font-size:19px;font-weight:750;}
.character-roster-info {min-width:0;}
.character-roster-info strong {color:#f2f4fb;font-size:15px;}
.character-roster-info p {margin:5px 0 0;overflow-wrap:anywhere;}
#character-associations-browser {border-top:1px solid #343e50;padding-top:16px;}
#character-associations-browser > h4 {margin:0 0 12px;font-size:14px;color:#c7d9ff;}
#character-associations-browser details {margin-bottom:10px;background:#202633;border-color:#39465d;}
#character-associations-browser summary {cursor:pointer;font-weight:600;color:#e6edff;}
#character-associations-browser .record-card {margin:10px 0;background:#1a2030;}
#character-suggest-list label,.character-link-choices label {display:flex;align-items:flex-start;gap:10px;padding:10px 4px;border-bottom:1px solid #303747;}
#character-suggest-list input[type=checkbox],.character-link-choices input[type=checkbox] {width:auto;flex:none;margin-top:3px;}
#character-suggest-approve {margin-top:12px;}
.character-page button:focus-visible,.character-page summary:focus-visible {outline:2px solid #b6a2fa;outline-offset:3px;}
@media(max-width:700px) {
    .character-hero {flex-direction:column;align-items:stretch;padding:20px;}
    .character-create-trigger {align-self:flex-start;}
    .character-panel {padding:18px 16px;}
    .character-form-grid {grid-template-columns:1fr;gap:0;}
}
