:root {
  --am-bg: #12241d;
  --am-bg-2: #1b3329;
  --am-ink: #f3f7f4;
  --am-muted: #b7c9bf;
  --am-line: rgba(243, 247, 244, 0.14);
  --am-accent: #3d9b6e;
  --am-warn: #c4a35a;
  --am-danger: #c45c4a;
  --am-radius: 18px;
  --am-tap: 52px;
  --am-pad: max(1rem, env(safe-area-inset-left));
}

html[data-studio-theme="light"] {
  color-scheme: light;
  --am-bg: #f4f7fb;
  --am-bg-2: #ffffff;
  --am-ink: #111827;
  --am-muted: #374151;
  --am-line: #94a3b8;
  --am-accent: #087443;
  --am-warn: #7c4a03;
  --am-danger: #b42318;
  --studio-surface: #ffffff;
  --studio-surface-alt: #e8eef6;
  --studio-link: #004f9e;
  --studio-focus: #005fcc;
  --studio-control-bg: #ffffff;
  --studio-selected-bg: #0b6b42;
  --studio-selected-ink: #ffffff;
}

html[data-studio-theme="dark"] {
  color-scheme: dark;
  --am-bg: #0b1220;
  --am-bg-2: #111c2e;
  --am-ink: #f8fafc;
  --am-muted: #cbd5e1;
  --am-line: #64748b;
  --am-accent: #55c58a;
  --am-warn: #f4c56a;
  --am-danger: #ff8a78;
  --studio-surface: #172235;
  --studio-surface-alt: #223149;
  --studio-link: #8bc8ff;
  --studio-focus: #facc15;
  --studio-control-bg: #0f1a2b;
  --studio-selected-bg: #8bc8ff;
  --studio-selected-ink: #08111f;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { overflow-x: hidden; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--am-ink);
  font-family: "Source Sans 3", "Segoe UI", "Helvetica Neue", sans-serif;
  background:
    radial-gradient(900px 420px at 10% -10%, rgba(61, 155, 110, 0.28), transparent 55%),
    linear-gradient(165deg, var(--am-bg), var(--am-bg-2));
  font-size: 18px;
  line-height: 1.35;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.am-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: calc(0.9rem + env(safe-area-inset-top)) var(--am-pad) 0.4rem;
}
.am-brand {
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--am-muted);
}
.am-top h1 {
  margin: 0.15rem 0 0;
  font-size: 1.55rem;
  line-height: 1.15;
}
.am-status {
  margin: 0;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: rgba(61, 155, 110, 0.2);
  border: 1px solid var(--am-line);
  font-size: 0.92rem;
  white-space: nowrap;
}

.am-net {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.9rem;
  margin: 0.35rem var(--am-pad) 0;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--am-line);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.18);
}
.am-net-state {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.am-net-dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--am-muted);
  box-shadow: 0 0 0 3px rgba(183, 201, 191, 0.18);
}
.am-net-dot.is-online {
  background: var(--am-accent);
  box-shadow: 0 0 0 3px rgba(61, 155, 110, 0.28);
}
.am-net-dot.is-offline {
  background: transparent;
  border: 2px solid var(--am-warn);
  box-shadow: none;
}
.am-net-dot.is-degraded {
  background: var(--am-warn);
  box-shadow: 0 0 0 3px rgba(196, 163, 90, 0.28);
}
.am-sync-state {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
}
.am-sync-stamp {
  margin: 0;
  color: var(--am-muted);
  font-size: 0.92rem;
  flex: 1 1 auto;
}
.am-dash-list {
  margin: 0.45rem 0 0;
  padding-left: 1.15rem;
}
.am-dash-list li {
  margin: 0.35rem 0;
  overflow-wrap: anywhere;
}
.am-dash-meta {
  display: block;
  color: var(--am-muted);
  font-size: 0.88rem;
}
.am-dash-count {
  margin: 0.25rem 0 0;
  font-weight: 650;
}
.am-refresh {
  min-height: var(--am-tap);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--am-line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--am-ink);
  font: inherit;
  font-weight: 650;
}

.am-shell {
  padding: 0.6rem var(--am-pad) calc(1.4rem + env(safe-area-inset-bottom));
  max-width: 42rem;
  margin: 0 auto;
  display: grid;
  gap: 0.8rem;
}

.am-ask label {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.7rem;
}
.am-composer {
  display: flex;
  gap: 0.55rem;
  align-items: stretch;
}
#amIntent {
  flex: 1;
  min-height: 7.2rem;
  resize: vertical;
  border: 1px solid var(--am-line);
  border-radius: var(--am-radius);
  background: rgba(0, 0, 0, 0.22);
  color: var(--am-ink);
  font: inherit;
  font-size: 1.15rem;
  padding: 0.9rem 1rem;
}
.am-mic {
  width: var(--am-tap);
  min-width: var(--am-tap);
  border: 2px solid var(--am-warn);
  border-radius: var(--am-radius);
  background: rgba(196, 163, 90, 0.12);
  color: var(--am-warn);
  opacity: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.am-mic-svg { display: block; }
.am-voice {
  margin: 0.45rem 0 0.8rem;
  color: var(--am-warn);
  font-size: 0.95rem;
}
.am-primary, .am-secondary, .am-ghost, .am-quick button {
  min-height: var(--am-tap);
  border-radius: 14px;
  font: inherit;
  font-weight: 650;
}
.am-primary {
  width: 100%;
  border: 0;
  background: var(--am-accent);
  color: #08140f;
}
.am-secondary, .am-ghost {
  width: 100%;
  border: 1px solid var(--am-line);
  background: transparent;
  color: var(--am-ink);
}
.am-ghost { font-weight: 500; color: var(--am-muted); }

.am-quick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin: 1.1rem 0 0.8rem;
}
.am-quick button {
  border: 1px solid var(--am-line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--am-ink);
}

.am-secondary-nav { margin: 0 0 0.4rem; }
.am-link {
  border: 0;
  background: none;
  color: var(--am-muted);
  font: inherit;
  text-decoration: underline;
  min-height: 44px;
  padding: 0;
}
.am-demo-flag {
  margin: 0 0 0.7rem;
  color: var(--am-warn);
  font-size: 0.92rem;
}
.am-source-badge {
  margin: 0 0 0.7rem;
  color: var(--am-muted);
  font-size: 0.85rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}
.am-card h3 { margin: 0.8rem 0 0.3rem; font-size: 1rem; color: var(--am-muted); }
.am-job-actions { grid-template-columns: 1fr 1fr; }
.am-hint { min-height: 1.4em; color: var(--am-muted); }
.am-conflict {
  margin: 0 0 0.6rem;
  padding: 0.7rem 0.8rem;
  border-radius: 12px;
  border: 1px solid rgba(196, 163, 90, 0.45);
  background: rgba(196, 163, 90, 0.12);
  color: var(--am-warn);
  font-weight: 650;
}
.am-card {
  margin-top: 0;
  padding: 1rem;
  border: 1px solid var(--am-line);
  border-radius: var(--am-radius);
  background: rgba(0, 0, 0, 0.18);
}
.am-card h2 { margin: 0 0 0.7rem; font-size: 1.15rem; }
.am-card dl {
  display: grid;
  gap: 0.45rem 0.7rem;
  margin: 0 0 1rem;
}
.am-card dt { color: var(--am-muted); font-size: 0.92rem; }
.am-card dd { margin: 0; font-weight: 650; overflow-wrap: anywhere; }
.am-actions { display: grid; gap: 0.5rem; }
.am-prepare-fields {
  display: grid;
  gap: 0.65rem;
  margin: 0;
}
.am-prepare-fields label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.95rem;
}
.am-prepare-fields input,
.am-prepare-fields textarea {
  width: 100%;
  border: 1px solid var(--am-line);
  border-radius: var(--am-radius);
  background: rgba(0, 0, 0, 0.22);
  color: var(--am-ink);
  font: inherit;
  padding: 0.7rem 0.8rem;
}
.am-prepare-fields fieldset {
  border: 1px solid var(--am-line);
  border-radius: var(--am-radius);
  margin: 0;
  padding: 0.7rem;
  display: grid;
  gap: 0.45rem;
}
.am-prepare-line {
  display: grid;
  gap: 0.45rem;
}
.am-card ul { list-style: none; margin: 0; padding: 0; }
.am-card li {
  padding: 0.7rem 0;
  border-top: 1px solid var(--am-line);
}
.am-card li:first-child { border-top: 0; }
.am-waiting {
  display: inline-block;
  margin-top: 0.25rem;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--am-warn);
}
.am-mail-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  padding: 0;
  cursor: pointer;
}
.am-mail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  color: var(--am-muted);
  font-size: 0.88rem;
}
.am-unread { color: var(--am-accent); font-weight: 700; }
.am-emails-scroll {
  max-height: 14rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.hidden { display: none !important; }

.am-product-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.55rem 0 0;
}
.am-product-nav-item {
  min-height: 40px;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--am-line);
  color: var(--am-ink);
  text-decoration: none;
  font-size: 0.92rem;
}
.am-product-nav-item.is-disabled {
  opacity: 0.55;
}
.am-product-layout {
  display: grid;
  gap: 0.8rem;
}
.am-home-section {
  display: grid;
  gap: 0.55rem;
}
.am-home-section > h2 {
  margin: 0.2rem 0 0;
  font-size: 1.15rem;
}
.am-empty {
  margin: 0.35rem 0 0;
  color: var(--am-muted);
  font-size: 0.95rem;
}
.am-product-card.is-disabled {
  opacity: 0.62;
}
.am-product-reason {
  margin: 0.35rem 0 0;
  color: var(--am-warn);
  font-size: 0.92rem;
}
body[data-surface="phone"] .am-product-nav {
  overflow-x: hidden;
  flex-wrap: wrap;
}
body[data-surface="tablet"] .am-product-layout,
body[data-surface="desktop"] .am-product-layout {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* 430 px — iPhone plus */
@media (max-width: 430px) {
  body { font-size: 17px; }
  .am-top h1 { font-size: 1.4rem; }
  #amIntent { min-height: 7.6rem; font-size: 1.12rem; }
  .am-net { flex-direction: column; align-items: stretch; }
  .am-refresh { width: 100%; }
}

/* 390 px — iPhone compact */
@media (max-width: 390px) {
  :root { --am-tap: 50px; }
  .am-ask label { font-size: 1.25rem; }
  .am-quick { gap: 0.45rem; }
  .am-top h1 { font-size: 1.32rem; }
}

/* 768 px — tablette */
@media (min-width: 768px) {
  .am-shell { max-width: 48rem; }
  .am-quick { grid-template-columns: repeat(3, 1fr); }
  .am-emails-scroll { max-height: 16rem; }
  .am-net { flex-direction: row; }
  .am-refresh { width: auto; }
}

/* 1280 px — desktop */
@media (min-width: 1280px) {
  .am-top { max-width: 72rem; margin: 0 auto; }
  .am-net { max-width: 72rem; margin-left: auto; margin-right: auto; }
  .am-shell {
    max-width: 72rem;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
    align-items: start;
  }
  .am-col-home { display: grid; gap: 0.8rem; }
  #amMail, #amJob, #amContacts, #amHistory {
    grid-column: 1 / -1;
  }
}

/* desktop large */
.am-top-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
}
.am-user {
  margin: 0.35rem 0 0;
  font-size: 0.92rem;
  color: var(--am-muted);
}
.am-logout {
  margin: 0;
}
.am-logout button {
  min-height: 40px;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--am-line);
  background: transparent;
  color: var(--am-ink);
  font: inherit;
  cursor: pointer;
}
.am-login {
  max-width: 26rem;
  margin: 0 auto;
  padding: calc(2rem + env(safe-area-inset-top)) var(--am-pad) 2rem;
}
.am-login h1 {
  margin: 0.4rem 0 1rem;
  font-size: 1.7rem;
}
.am-login-form {
  display: grid;
  gap: 0.55rem;
}
.am-login-form input {
  min-height: var(--am-tap);
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--am-line);
  background: rgba(0, 0, 0, 0.22);
  color: var(--am-ink);
  font: inherit;
}
.am-login-error:empty { display: none; }
.am-login-error {
  color: var(--am-warn);
  min-height: 1.2em;
}
.am-login-info:empty { display: none; }
.am-login-info {
  color: var(--am-ok, #b7e0c2);
  min-height: 1.2em;
}
.am-login-links {
  margin: 0.85rem 0 0;
}
.am-login-links a {
  color: inherit;
  text-underline-offset: 0.18em;
}
.am-iam-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.am-iam-table th, .am-iam-table td {
  text-align: left;
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid var(--am-line);
}

/* Secrets adopte les thèmes Studio réutilisables sans modifier les autres surfaces. */
.studio-secrets {
  background: linear-gradient(165deg, var(--am-bg), var(--am-bg-2));
  color: var(--am-ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}
.studio-secrets .am-login {
  width: 100%;
  max-width: 64rem;
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  padding-left: max(1rem, env(safe-area-inset-left));
}
.studio-secrets .studio-secrets-main--narrow {
  max-width: 40rem;
}
.studio-secrets .studio-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}
.studio-secrets .studio-page-header h1 {
  font-size: 1.75rem;
  line-height: 1.2;
}
.studio-secrets a {
  color: var(--studio-link);
  font-weight: 650;
  text-decoration-thickness: 0.11em;
  text-underline-offset: 0.18em;
}
.studio-theme-switcher {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 0.25rem;
  padding: 0.25rem;
  border: 1px solid var(--am-line);
  border-radius: 0.75rem;
  background: var(--studio-surface-alt);
}
.studio-theme-switcher button,
.studio-secrets button,
.studio-secrets .am-btn {
  min-height: 44px;
  border: 1px solid var(--am-line);
  border-radius: 0.55rem;
  background: var(--studio-control-bg);
  color: var(--am-ink);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  padding: 0.65rem 0.8rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.studio-theme-switcher button[aria-pressed="true"] {
  border-color: var(--studio-selected-bg);
  background: var(--studio-selected-bg);
  color: var(--studio-selected-ink);
}
.studio-secrets button:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}
.studio-secrets :focus-visible {
  outline: 3px solid var(--studio-focus);
  outline-offset: 3px;
}
.studio-secrets h2 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.3rem;
}
.studio-table-scroll {
  overflow-x: auto;
  border: 1px solid var(--am-line);
  border-radius: 0.7rem;
  background: var(--studio-surface);
  -webkit-overflow-scrolling: touch;
}
.studio-secrets .am-iam-table {
  font-size: 14px;
}
.studio-secrets .am-iam-table th,
.studio-secrets .am-iam-table td {
  padding: 0.7rem 0.65rem;
  border-color: var(--am-line);
  font-size: 14px;
  vertical-align: top;
}
.studio-secrets .am-iam-table th {
  background: var(--studio-surface-alt);
  color: var(--am-ink);
  font-weight: 750;
}
.studio-secrets .am-iam-table code,
.studio-secrets .studio-primary-label {
  display: block;
}
.studio-secrets .am-iam-table code {
  margin-top: 0.15rem;
  color: var(--am-muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.studio-secrets .studio-primary-label {
  color: var(--am-ink);
  font-weight: 700;
}
.studio-status-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem 0.8rem;
  margin: 1.25rem 0;
  padding: 0.8rem;
  border: 1px solid var(--am-line);
  border-radius: 0.7rem;
  background: var(--studio-surface);
}
.studio-status-legend ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.studio-status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0.25rem 0.6rem;
  border: 2px solid currentColor;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.2;
  white-space: nowrap;
}
html[data-studio-theme="light"] .studio-status-badge--validated {
  color: #075a35;
  background: #d5f5e3;
}
html[data-studio-theme="light"] .studio-status-badge--validate {
  color: #8a3500;
  background: #ffead6;
}
html[data-studio-theme="light"] .studio-status-badge--revalidate {
  color: #704200;
  background: #fff2bd;
  border-style: dashed;
}
html[data-studio-theme="light"] .studio-status-badge--configure {
  color: #374151;
  background: #e5e7eb;
}
html[data-studio-theme="dark"] .studio-status-badge--validated {
  color: #c7f9dc;
  background: #123e2a;
}
html[data-studio-theme="dark"] .studio-status-badge--validate {
  color: #ffe4ca;
  background: #542408;
}
html[data-studio-theme="dark"] .studio-status-badge--revalidate {
  color: #fff0b3;
  background: #493106;
  border-style: dashed;
}
html[data-studio-theme="dark"] .studio-status-badge--configure {
  color: #e2e8f0;
  background: #334155;
}
.studio-technical-details {
  margin-top: 0.65rem;
  border-top: 1px solid var(--am-line);
}
.studio-technical-details summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  color: var(--studio-link);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
.studio-technical-details dl {
  display: grid;
  gap: 0.4rem;
  margin: 0 0 0.65rem;
}
.studio-technical-details dl > div {
  display: grid;
  grid-template-columns: minmax(8rem, 45%) minmax(0, 1fr);
  gap: 0.5rem;
}
.studio-technical-details dt {
  color: var(--am-muted);
  font-size: 12px;
}
.studio-technical-details dd {
  margin: 0;
}
.studio-secrets input[type="password"],
.studio-secrets input[type="text"] {
  min-height: 44px;
  border: 2px solid var(--am-line);
  border-radius: 0.45rem;
  background: var(--studio-control-bg);
  color: var(--am-ink);
  font: inherit;
  font-size: 16px;
  padding: 0.55rem 0.65rem;
}
.studio-secrets input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--am-accent);
  vertical-align: middle;
}
.studio-secrets form {
  display: grid;
  gap: 0.55rem;
}
.studio-secrets .am-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

@media (max-width: 900px) {
  .studio-secrets .studio-page-header {
    display: grid;
  }
  .studio-theme-switcher {
    width: 100%;
  }
  .studio-theme-switcher button {
    flex: 1 1 50%;
  }
  .studio-table-scroll {
    overflow: visible;
    border: 0;
    background: transparent;
  }
  .studio-secrets .am-iam-table,
  .studio-secrets .am-iam-table tbody,
  .studio-secrets .am-iam-table tr,
  .studio-secrets .am-iam-table td {
    display: block;
    width: 100%;
  }
  .studio-secrets .am-iam-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .studio-secrets .am-iam-table tr {
    margin-bottom: 0.9rem;
    border: 1px solid var(--am-line);
    border-radius: 0.7rem;
    background: var(--studio-surface);
    overflow: hidden;
  }
  .studio-secrets .am-iam-table td {
    display: grid;
    grid-template-columns: minmax(7.5rem, 40%) minmax(0, 1fr);
    gap: 0.65rem;
    border-bottom: 1px solid var(--am-line);
  }
  .studio-secrets .am-iam-table td:last-child {
    border-bottom: 0;
  }
  .studio-secrets .am-iam-table td::before {
    content: attr(data-label);
    color: var(--am-muted);
    font-size: 13px;
    font-weight: 750;
  }
}

@media (max-width: 390px) {
  .studio-secrets .am-iam-table td {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
}

@media (min-width: 1600px) {
  .am-top, .am-net, .am-shell { max-width: 86rem; }
  body { font-size: 19px; }
}

@media (min-width: 880px) and (max-width: 1279px) {
  .am-actions { grid-template-columns: 1.4fr 1fr 1fr; }
}
