:root {
  color-scheme: dark;
  --bg: #101418;
  --panel: #161d22;
  --panel-soft: #1d252b;
  --text: #f4f7f8;
  --muted: #9aa8ae;
  --line: #2c363d;
  --blue: #72a7ff;
  --green: #68d89b;
  --coral: #ff8f70;
  --focus: #f7d774;
  --shadow: 0 16px 60px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  border-radius: 8px;
  min-height: 42px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: var(--blue);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.shell {
  min-height: 100vh;
}

.login {
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: 100vh;
  padding: 24px;
  gap: 22px;
}

.login h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 4.2rem);
  letter-spacing: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 72px;
  aspect-ratio: 1;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--blue), var(--green));
  color: #071014;
  font-weight: 900;
  box-shadow: var(--shadow);
}

.brand-mark.small {
  width: 42px;
  border-radius: 12px;
  flex: 0 0 auto;
}

.login-form {
  width: min(100%, 440px);
  display: grid;
  gap: 12px;
}

.login-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.login input,
.composer textarea,
.media-search input {
  width: 100%;
  border: 1px solid var(--line);
  background: #0c1114;
  color: var(--text);
  border-radius: 8px;
}

.login input {
  min-height: 46px;
  padding: 0 14px;
}

.error {
  margin: 0;
  color: var(--coral);
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 18px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 20px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quick-actions button:nth-child(1) {
  border-color: rgba(114, 167, 255, 0.5);
}

.quick-actions button:nth-child(2) {
  border-color: rgba(104, 216, 155, 0.5);
}

.quick-actions button:nth-child(3) {
  border-color: rgba(247, 215, 116, 0.5);
}

.quick-actions button:nth-child(4) {
  border-color: rgba(255, 143, 112, 0.5);
}

.sidebar-actions {
  align-self: end;
  display: grid;
  gap: 8px;
}

.chat {
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  height: 100vh;
}

/* Modal panels (parametres + medias partagent le meme look) */
.modal-panel,
.admin-panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow-y: auto;
  background: rgba(12, 17, 20, 0.98);
  padding: 28px;
}

.modal-header,
.admin-header {
  max-width: 1100px;
  margin: 0 auto 18px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.modal-header h2,
.admin-header h2 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.5rem);
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.8rem;
}

.modal-grid,
.admin-grid {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  gap: 14px;
}

.modal-grid.three-cols,
.admin-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.modal-section,
.admin-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.modal-section h3,
.admin-section h3 {
  margin: 0 0 14px;
  font-size: 1rem;
  letter-spacing: 0;
}

.status-list {
  display: grid;
  gap: 10px;
  margin: 0 0 14px;
}

.status-list div {
  display: grid;
  gap: 2px;
}

.status-list dt {
  color: var(--muted);
  font-size: 0.78rem;
}

.status-list dd {
  margin: 0;
  word-break: break-word;
}

.model-list,
.preset-list {
  display: grid;
  gap: 10px;
}

.admin-option {
  border: 1px solid var(--line);
  background: #0c1114;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 6px;
  text-align: left;
}

.admin-option.active {
  border-color: var(--green);
  box-shadow: inset 0 0 0 1px rgba(104, 216, 155, 0.36);
}

.admin-option strong {
  display: block;
}

.admin-option span {
  color: var(--muted);
  font-size: 0.85rem;
}

.admin-option code {
  color: var(--blue);
  white-space: normal;
}

/* Media panel */
.media-toolbar {
  max-width: 1100px;
  margin: 0 auto 14px;
  display: grid;
  gap: 12px;
}

.media-search {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.media-search input {
  min-height: 46px;
  padding: 0 14px;
}

.media-search button {
  min-width: 120px;
  background: var(--green);
  color: #08120d;
  border-color: transparent;
  font-weight: 800;
}

.media-search button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.media-services {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.media-pill {
  display: inline-flex;
  align-items: center;
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  text-transform: lowercase;
}

.media-pill.ok {
  border-color: rgba(104, 216, 155, 0.45);
  color: var(--green);
}

.media-pill.error {
  border-color: rgba(255, 143, 112, 0.5);
  color: var(--coral);
}

.media-pill.loading {
  border-style: dashed;
}

.media-pill.muted {
  opacity: 0.7;
}

.media-feedback {
  max-width: 1100px;
  margin: 0 auto 14px;
  color: var(--muted);
  font-size: 0.92rem;
  min-height: 1.4em;
}

.media-results {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.media-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.media-poster {
  width: 92px;
  aspect-ratio: 2 / 3;
  border-radius: 6px;
  background: #0c1114;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

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

.media-poster.placeholder {
  border: 1px dashed var(--line);
}

.media-body {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 6px;
}

.media-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.25;
  word-break: break-word;
}

.media-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.media-tag {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  font-size: 0.74rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(0, 0, 0, 0.18);
}

.media-tag.ok {
  border-color: rgba(104, 216, 155, 0.45);
  color: var(--green);
}

.media-tag.info {
  border-color: rgba(114, 167, 255, 0.5);
  color: var(--blue);
}

.media-overview {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.messages {
  overflow-y: auto;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  width: min(780px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: #142033;
  border-color: rgba(114, 167, 255, 0.32);
}

.message.assistant {
  align-self: flex-start;
  background: var(--panel);
}

.message.system {
  align-self: center;
  color: var(--muted);
  background: transparent;
  border-style: dashed;
}

.composer {
  border-top: 1px solid var(--line);
  background: rgba(16, 20, 24, 0.92);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 16px;
}

.composer textarea {
  min-height: 48px;
  max-height: 180px;
  resize: vertical;
  padding: 13px 14px;
}

.composer button {
  min-width: 108px;
  background: var(--green);
  color: #08120d;
  border-color: transparent;
  font-weight: 800;
}

.composer button:disabled {
  opacity: 0.55;
  cursor: wait;
}

[hidden] {
  display: none !important;
}

@media (max-width: 780px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    grid-template-rows: auto auto auto;
  }

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

  .chat {
    height: calc(100vh - 222px);
  }

  .messages {
    padding: 16px;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .modal-panel,
  .admin-panel {
    padding: 16px;
  }

  .modal-header,
  .admin-header {
    align-items: flex-start;
  }

  .modal-grid.three-cols,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .media-search {
    grid-template-columns: 1fr;
  }

  .media-results {
    grid-template-columns: 1fr;
  }

  .media-card {
    grid-template-columns: 80px 1fr;
  }

  .media-poster {
    width: 80px;
  }
}
