:root {
  --ink: #071c18;
  --muted: #6f7d78;
  --brand: #ff4d55;
  --soft: #eef4f1;
  --line: #dce5e1;
  --white: #fff;
  --danger: #a5262d;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  background: #f5f7f6;
  color: var(--ink);
  font: 15px/1.5 Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.auth-mode {
  min-height: 100vh;
  background-color: #f7f1e9;
  background-image: linear-gradient(90deg, rgba(255,255,255,.72) 0%, rgba(255,255,255,.42) 44%, rgba(255,255,255,.04) 76%), url("./provider-background.png");
  background-position: center;
  background-size: cover;
  background-attachment: fixed;
}

body.auth-mode main {
  max-width: none;
  padding-inline: clamp(1rem, 5vw, 5rem);
}

button, input, select, textarea { font: inherit; }

button {
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-weight: 750;
  padding: .8rem 1rem;
  cursor: pointer;
}

button:disabled { opacity: .55; cursor: not-allowed; }
.secondary { background: var(--soft); color: var(--ink); }
.hidden { display: none !important; }

/* A stored session renders the stable portal shell before deferred JavaScript
   starts, preventing the signed-out screen from flashing during refresh. */
html.provider-session-pending #authPanel,
html.provider-session-pending #sessionRestorePanel { display: none !important; }
html.provider-session-pending #portal.hidden { display: grid !important; }
html.provider-session-pending body.auth-mode {
  background: #f5f7f6;
}
html.provider-session-pending body.auth-mode main {
  max-width: 1440px;
  padding: clamp(1rem, 3vw, 2rem);
}
body.session-restoring .workspace {
  opacity: .55;
  pointer-events: none;
  animation: session-shell-pulse 1.2s ease-in-out infinite alternate;
}
@keyframes session-shell-pulse {
  from { opacity: .45; }
  to { opacity: .72; }
}
.alert-count { display: inline-grid; min-width: 1.35rem; height: 1.35rem; padding: 0 .3rem; place-items: center; border-radius: 999px; background: var(--accent); color: #fff; font-size: .75rem; }
.alerts-dialog { width: min(680px, calc(100% - 2rem)); max-height: 80vh; border: 0; border-radius: 16px; padding: 1.25rem; box-shadow: 0 24px 80px rgba(0,0,0,.25); }
.alerts-dialog::backdrop { background: rgba(7,25,22,.52); }
.alert-rows { display: grid; gap: .65rem; overflow: auto; max-height: 58vh; }
.alert-item { border: 1px solid var(--line); border-radius: 12px; padding: .9rem; background: #fff; }
.alert-item.unread { border-color: #ffb0b0; background: #fff7f7; }
.alert-item p { margin: .3rem 0; color: var(--muted); }
.moderation-note { color: #9d2929 !important; font-weight: 700; }

.provider-header {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  background: rgba(7, 28, 24, .97);
  color: #fff;
}

.provider-header h1 { margin: 0; font-size: 1.4rem; }

.eyebrow {
  display: block;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: .72rem;
  font-weight: 800;
  color: #8ca59d;
}

.header-actions { display: flex; align-items: center; gap: .75rem; }

main {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem);
}

.card {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: clamp(1rem, 2vw, 1.5rem);
  box-shadow: 0 10px 35px rgba(7, 28, 24, .05);
}

.auth-card {
  max-width: 920px;
  margin: 8vh auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  align-items: center;
}

body.auth-mode .auth-card {
  grid-template-columns: 1fr;
  max-width: 570px;
  margin: clamp(2rem, 8vh, 6rem) auto clamp(2rem, 8vh, 6rem) 0;
  gap: 1.25rem;
  background: rgba(255,255,255,.94);
  border-color: rgba(255,255,255,.82);
  box-shadow: 0 24px 70px rgba(7,28,24,.18);
  backdrop-filter: blur(12px);
}

.auth-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  padding: .35rem;
  border-radius: 13px;
  background: var(--soft);
}

.auth-switch button {
  background: transparent;
  color: var(--ink);
}

.auth-switch button.active {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 6px 14px rgba(255,77,85,.24);
}

.auth-card h2, .section-heading h2 { margin: .15rem 0; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.dashboard-grid > *,
.workspace > *,
.card > *,
.form-grid > *,
.section-heading > * { min-width: 0; }

.side-card { position: static; align-self: start; }
.side-card nav { display: grid; gap: .45rem; margin-top: 1rem; }
.side-card nav button { background: transparent; color: var(--ink); text-align: left; }
.side-card nav button.active { background: var(--soft); }

.badge {
  display: inline-block;
  padding: .35rem .65rem;
  border-radius: 999px;
  background: #fff1d9;
  color: #7c4c00;
  font-weight: 750;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  gap: 1rem;
}

.section-heading,
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-heading > div { flex: 1 1 auto; }
.section-heading > button { flex: 0 0 auto; }
.toolbar { justify-content: flex-start; flex-wrap: wrap; }
.toolbar input { min-width: min(100%, 320px); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 100%;
  max-width: 100%;
  gap: 1rem;
  margin: 1rem 0;
}

.form-grid.compact { grid-template-columns: 1fr; }
.form-grid label { display: grid; gap: .35rem; font-weight: 700; min-width: 0; }
.form-grid .wide { grid-column: 1 / -1; }

.provider-type-fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.provider-type-fieldset legend {
  margin-bottom: .75rem;
  font-weight: 800;
}

.provider-type-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
}

.provider-type-card {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: flex-start;
  gap: .75rem !important;
  min-height: 112px;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.provider-type-card:hover {
  transform: translateY(-1px);
  border-color: #ff9b9f;
  box-shadow: 0 8px 22px rgba(7,28,24,.08);
}

.provider-type-card:has(input:checked) {
  border-color: var(--brand);
  background: #fff7f7;
  box-shadow: 0 0 0 3px rgba(255,77,85,.12);
}

.provider-type-card input {
  width: 18px;
  height: 18px;
  margin: .15rem 0 0;
  accent-color: var(--brand);
  flex: 0 0 auto;
}

.provider-type-card span {
  display: grid;
  gap: .3rem;
}

.provider-type-card strong {
  line-height: 1.3;
}

.location-card {
  display: grid;
  gap: .65rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft);
}

.location-card h3 { margin: 0 0 .25rem; }
.location-card p { margin: 0; }
.location-status { color: var(--muted); font-weight: 700; }
.location-status.ready { color: #18794e; }
.location-status.error { color: var(--danger); }
.manual-location { border-top: 1px solid var(--line); padding-top: .75rem; }
.manual-location summary { cursor: pointer; font-weight: 700; }
.manual-location .field-pair { margin: .75rem 0 .5rem; }
.location-preview { display: grid; gap: .65rem; }
.location-map { width: 100%; height: 360px; border: 1px solid var(--line); border-radius: 10px; background: #e7ece9; z-index: 0; }
.location-preview a { color: var(--ink); font-weight: 800; }
.location-search { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: .5rem; align-items: end; }
.location-search input { min-width: 0; }
.location-search-results { display: grid; gap: .4rem; padding: .6rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.location-search-result { width: 100%; text-align: left; background: #fff; color: var(--ink); border: 1px solid var(--line); }
.location-search-result:hover { background: var(--soft); }

@media (max-width: 720px) {
  .location-search { grid-template-columns: 1fr; }
  .location-map { height: 320px; }
}

.field-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .5rem;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .65rem;
}

input, select, textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .78rem;
  background: #fff;
  color: var(--ink);
}

textarea { resize: vertical; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .8rem;
}

.metrics article, .plan, .list-row { border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }
.metrics span { display: block; color: var(--muted); }
.metrics strong { font-size: 1.25rem; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .75rem; margin-top: 1.2rem; }
.plan h3, .list-row h3 { margin: 0; }
.stack-list { display: grid; gap: .7rem; min-width: 0; }

.list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
  min-width: 0;
}

.list-row p { margin: .25rem 0; color: var(--muted); overflow-wrap: anywhere; }
.list-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; }
.message { color: var(--danger); font-weight: 700; overflow-wrap: anywhere; }
.message.success { color: #18794e; }
.portal-message:empty { display: none; }
.portal-message {
  position: sticky;
  top: 5.5rem;
  z-index: 30;
  margin: 0 0 1rem;
  padding: .85rem 1rem;
  border: 1px solid #f3b7bc;
  border-left: .35rem solid var(--danger);
  border-radius: .75rem;
  background: #fff7f7;
  box-shadow: 0 .65rem 1.5rem rgba(34, 21, 21, .14);
}
.portal-message.success {
  border-color: #a9d9c0;
  border-left-color: #18794e;
  background: #f1fbf5;
}
small { font-weight: 400; color: var(--muted); }

@media (max-width: 850px) {
  .auth-card, .dashboard-grid { grid-template-columns: 1fr; }
  .side-card { position: static; }
  .side-card nav { display: flex; overflow-x: auto; }
  .side-card nav button { white-space: nowrap; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  .provider-header { align-items: flex-start; }
  .header-actions span { display: none; }
  .auth-card { margin: 2vh auto; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .field-pair { grid-template-columns: 1fr; }
  .section-heading, .toolbar, .list-row { align-items: stretch; flex-direction: column; }
  .list-row { display: flex; }
  .list-actions { justify-content: flex-start; }
  .metrics { grid-template-columns: 1fr 1fr; }
  body.auth-mode {
    background-position: 63% center;
    background-image: linear-gradient(rgba(255,255,255,.66), rgba(255,255,255,.76)), url("./provider-background.png");
  }
  body.auth-mode main { padding-inline: 1rem; }
  body.auth-mode .auth-card { margin: 2vh auto; }
  .provider-type-grid { grid-template-columns: 1fr; }
}
