:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #16202b;
  --muted: #61707f;
  --line: #dfe5ea;
  --brand: #0b6b3a;
  --brand-ink: #ffffff;
  --danger: #b42318;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* Must beat the class rules below. A `display` declared in an author
   stylesheet overrides the user agent's [hidden] { display: none }, so
   without this both sections render stacked and toggling does nothing. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.brand { font-weight: 700; font-size: 20px; letter-spacing: -0.02em; color: var(--brand); }
.brand span { color: var(--muted); font-weight: 500; }

/* --- login --- */

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 32px; box-shadow: 0 1px 3px rgba(16, 32, 43, 0.06);
}

.login-card h1 { font-size: 20px; margin: 16px 0 4px; }
.login-card .sub { color: var(--muted); margin: 0 0 24px; }
.login-card label { display: block; font-weight: 600; margin: 16px 0 6px; }

.login-card input {
  width: 100%; padding: 10px 12px; font: inherit;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.login-card input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }

.login-card button {
  width: 100%; margin-top: 24px; padding: 11px; font: inherit; font-weight: 600;
  color: var(--brand-ink); background: var(--brand);
  border: 0; border-radius: 6px; cursor: pointer;
}
.login-card button:hover:not(:disabled) { filter: brightness(1.1); }
.login-card button:disabled { opacity: 0.6; cursor: default; }

/* --- app shell --- */

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}

.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }

.tabs button {
  padding: 7px 14px; font: inherit; color: var(--muted);
  background: transparent; border: 1px solid transparent;
  border-radius: 6px; cursor: pointer;
}
.tabs button:hover { background: var(--bg); }
.tabs button.active { color: var(--brand); background: var(--bg); border-color: var(--line); font-weight: 600; }

.who { display: flex; align-items: center; gap: 10px; color: var(--muted); }

.pill {
  padding: 3px 10px; font-size: 12px; font-weight: 600;
  color: var(--brand); background: #e8f3ed; border-radius: 999px;
}

.who button {
  padding: 6px 12px; font: inherit; color: var(--ink);
  background: transparent; border: 1px solid var(--line);
  border-radius: 6px; cursor: pointer;
}
.who button:hover { background: var(--bg); }

main { flex: 1; padding: 16px 20px 20px; display: flex; flex-direction: column; }

/* position:relative + inset:0 on the iframe, because .report takes its height
   from `flex: 1` rather than an explicit height. A percentage height cannot
   resolve against that, so the SDK's height:100% falls back to the replaced
   element default of 150px and the report canvas is clipped away. */
.report {
  position: relative;
  flex: 1; min-height: 640px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.report iframe {
  position: absolute; inset: 0;
  width: 100%; height: 100%; border: 0;
}

/* --- errors --- */

.error { color: var(--danger); margin: 12px 0 0; }

.banner {
  padding: 12px 14px; background: #fef3f2;
  border: 1px solid #fecdca; border-radius: 6px;
}

@media (max-width: 720px) {
  .topbar { gap: 12px; }
  .who span:first-child { display: none; }
}

/* --- Microsoft sign-in button --- */

.ms-button {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; margin-top: 8px; padding: 11px; font: inherit; font-weight: 600;
  color: #fff; background: #2f2f2f; border-radius: 6px; text-decoration: none;
}
.ms-button:hover { background: #1f1f1f; }

.button-link {
  padding: 6px 12px; color: var(--ink); text-decoration: none;
  border: 1px solid var(--line); border-radius: 6px;
}
.button-link:hover { background: var(--bg); }

.empty {
  flex: 1; display: grid; place-items: center; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
}

/* --- admin page --- */

.admin-body { min-height: 100vh; display: flex; flex-direction: column; }
.admin-main { flex: 1; padding: 20px; max-width: 1100px; width: 100%; margin: 0 auto; }

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 24px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.panel h2 { margin: 0; font-size: 18px; }
.hint { color: var(--muted); margin: 8px 0 16px; }
.hint code, .checklist code { font-size: 12px; background: var(--bg); padding: 1px 6px; border-radius: 4px; }
.muted { color: var(--muted); }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row input[type="text"] { flex: 1; min-width: 240px; }
.grow { flex: 1; }

button, .admin-body input, .admin-body select { font: inherit; }
.admin-body button {
  padding: 7px 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
}
.admin-body button:hover:not(:disabled) { background: var(--bg); }
.admin-body button:disabled { opacity: 0.5; cursor: default; }
.admin-body button.primary { color: var(--brand-ink); background: var(--brand); border-color: var(--brand); }
.admin-body button.primary:hover:not(:disabled) { filter: brightness(1.1); background: var(--brand); }
.admin-body button.danger { color: var(--danger); }
.admin-body button.danger:hover:not(:disabled) { background: #fef3f2; }

.admin-body input[type="text"], .admin-body input[type="email"], .admin-body select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.admin-body input:focus, .admin-body select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.grid td .pill { margin-left: 8px; }

.pill.admin { color: #7a4b00; background: #fff4db; }
.pill.danger { color: var(--danger); background: #fef3f2; }
.pill.muted { color: var(--muted); background: var(--bg); }

.checklist { list-style: none; margin: 0 0 16px; padding: 0; }
.checklist li {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 6px;
}
.checklist li.selected { background: #f6faf8; border-color: #cfe4d8; }
.checklist .drag { cursor: grab; color: var(--muted); user-select: none; }
.inline { display: flex; align-items: center; gap: 6px; cursor: pointer; }

dialog {
  width: min(520px, 92vw); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px 28px; box-shadow: 0 8px 30px rgba(16, 32, 43, 0.15);
}
dialog::backdrop { background: rgba(16, 32, 43, 0.35); }
dialog h3 { margin: 0 0 8px; font-size: 18px; }
dialog label { display: block; font-weight: 600; margin: 14px 0 6px; }
dialog label small { font-weight: 400; color: var(--muted); }
dialog label.inline { font-weight: 400; margin: 8px 0; }
dialog input[type="text"], dialog input[type="email"], dialog select { width: 100%; }
dialog fieldset { margin: 16px 0 0; padding: 10px 14px; border: 1px solid var(--line); border-radius: 6px; }
dialog legend { font-weight: 600; padding: 0 6px; }
.checks { display: grid; gap: 4px; }
dialog .row.end { margin-top: 20px; }

.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 10;
  padding: 10px 16px; border-radius: 6px; color: #fff; background: var(--brand);
  box-shadow: 0 4px 16px rgba(16, 32, 43, 0.2);
}
.toast.error { background: var(--danger); }
.toast.warn { background: #b54708; }
