/*
 * styles.css — the look of the whole app.
 *
 * Brand colours:
 *   navy   #0A2533   headings, dark surfaces
 *   teal   #12A5A5   buttons, links, accents
 *   grey   #F4F6F7   page background
 *   white  #FFFFFF   cards
 */

:root {
  --navy: #0A2533;
  --navy-soft: #17394b;
  --teal: #12A5A5;
  --teal-dark: #0e8686;
  --teal-wash: #e7f6f6;
  --grey: #F4F6F7;
  --line: #dde3e6;
  --text: #16333f;
  --muted: #5d7480;
  --white: #ffffff;
  --danger: #b3261e;
  --danger-wash: #fdecea;
  --success: #1a7f5a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(10, 37, 51, .06), 0 8px 24px rgba(10, 37, 51, .07);
  --font: 'IBM Plex Sans', 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont,
          'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--grey);
  -webkit-font-smoothing: antialiased;
}

/* Arabic text gets its own face and a little more line height, because
   Arabic letters carry marks above and below that need the room. */
html[lang="ar"] body {
  font-family: 'IBM Plex Sans Arabic', var(--font);
  line-height: 1.7;
}
html[lang="ar"] h1,
html[lang="ar"] h2,
html[lang="ar"] h3 { line-height: 1.4; }

h1, h2, h3 { color: var(--navy); line-height: 1.25; margin: 0 0 .5em; font-weight: 600; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
p { margin: 0 0 1rem; }
a { color: var(--teal-dark); }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.centre { text-align: center; }

/* --- Layout --------------------------------------------------------------- */

.page-centred {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  width: 100%;
}

.card--narrow { max-width: 460px; }

.brand-mark {
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-size: .75rem;
  color: var(--teal);
  margin-bottom: 14px;
}

/* --- Buttons -------------------------------------------------------------- */
/* Large touch targets: at least 48px tall, for phones in a dim lecture hall. */

.button,
button.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 14px 22px;
  border: 0;
  border-radius: 10px;
  background: var(--teal);
  color: var(--white);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease;
}

.button:hover { background: var(--teal-dark); }
.button:active { transform: translateY(1px); }
.button:disabled { background: #9db6bd; cursor: not-allowed; transform: none; }
.button--block { width: 100%; }
.button--ghost { background: transparent; color: var(--navy); border: 1px solid var(--line); }
.button--ghost:hover { background: var(--grey); }
.button--danger { background: var(--danger); }
.button--danger:hover { background: #8f1e17; }

/* Anything focused by keyboard gets a clear ring. */
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

/* --- Forms ---------------------------------------------------------------- */

label { display: block; font-weight: 500; margin-bottom: 6px; color: var(--navy); }

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="datetime-local"], input[type="search"], select {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  font: inherit;
  color: var(--text);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
}

input:focus, select:focus { border-color: var(--teal); outline: none; box-shadow: 0 0 0 3px var(--teal-wash); }

.field { margin-bottom: 18px; }
.field .hint { font-size: .8125rem; color: var(--muted); margin-top: 6px; }

/* --- Messages ------------------------------------------------------------- */

.notice { border-radius: 10px; padding: 14px 16px; margin-bottom: 18px; font-size: .9375rem; }
.notice--error { background: var(--danger-wash); color: var(--danger); }
.notice--info { background: var(--teal-wash); color: var(--navy); }

/* ===========================================================================
   THE ATTENDEE PAGE
   The page someone sees after scanning the QR code. Designed for a phone
   held in a dim lecture hall: large text, large targets, high contrast.
   =========================================================================== */

.page-attendee { padding: 0; }

.shell {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  /* Keep clear of the notch and the home indicator on modern phones. */
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(48px, env(safe-area-inset-bottom));
}

/* --- Event details at the top --------------------------------------------- */

.event-head {
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
  margin-bottom: 22px;
}

.event-titles { display: flex; flex-direction: column; gap: 2px; }

.event-title { font-size: 1.375rem; margin-bottom: 2px; }

.event-title-ar {
  font-family: 'IBM Plex Sans Arabic', var(--font);
  font-size: 1.125rem;
  color: var(--navy-soft);
  margin: 0 0 4px;
}

/* Reading in Arabic? Then the Arabic title is the title, and the English one
   becomes the smaller line underneath. Nothing moves in the HTML — only the
   order they are drawn in. */
html[lang="ar"] .event-title-ar {
  order: -1;
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 2px;
}
html[lang="ar"] .event-titles--bilingual .event-title {
  font-size: 1rem;
  font-weight: 500;
  color: var(--navy-soft);
}

.event-meta { margin: 14px 0 0; display: grid; gap: 8px; }
.event-meta > div { display: flex; gap: 10px; align-items: baseline; }

.event-meta dt {
  flex: 0 0 auto;
  min-width: 84px;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.event-meta dd { margin: 0; font-weight: 500; color: var(--navy); }

/* Arabic labels are longer words, and are not written in capitals. */
html[lang="ar"] .event-meta dt {
  min-width: 104px;
  text-transform: none;
  letter-spacing: 0;
  font-size: .875rem;
}

/* --- The signature box ---------------------------------------------------- */

.sig-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sig-label-row label { margin-bottom: 6px; }

/* "Clear" — a text button, but still a comfortable tap target. */
.link-button {
  background: none;
  border: 0;
  padding: 6px 4px;
  margin-bottom: 6px;
  font: inherit;
  font-weight: 600;
  font-size: .9375rem;
  color: var(--teal-dark);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-button:hover { color: var(--navy); }

.sig-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  overflow: hidden;
  /* A faint baseline to sign on, like a paper form. */
  background-image: linear-gradient(to right, var(--line) 0 100%);
  background-size: calc(100% - 48px) 1px;
  background-position: 24px 76%;
  background-repeat: no-repeat;
}

#signature-pad {
  display: block;
  width: 100%;
  /* Stop the page scrolling or zooming while a finger is drawing on it. */
  touch-action: none;
  cursor: crosshair;
}

.sig-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #93a8b1;
  font-size: .9375rem;
  pointer-events: none;
}

[hidden] { display: none !important; }

/* --- Confirmation --------------------------------------------------------- */

.tick { margin: 8px 0 18px; }
#done-view h1 { font-size: 1.375rem; }
#done-view, #already-view { padding-top: 36px; padding-bottom: 36px; }

.notice strong { display: block; margin-bottom: 4px; }
.notice p { margin: 0; }

/* ===========================================================================
   THE ORGANISER DASHBOARD
   Desktop-first: this is used on a laptop before and during an event.
   =========================================================================== */

.page-admin { background: var(--grey); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- Top bar -------------------------------------------------------------- */

.topbar { background: var(--navy); color: var(--white); }

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-brand {
  color: var(--white);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-size: .8125rem;
}

.topbar-actions { margin: 0; }
.link-button--light { color: #b9d4d8; }
.link-button--light:hover { color: var(--white); }

.admin-main { max-width: 1100px; margin: 0 auto; padding: 28px 20px 64px; }

.back-link {
  display: inline-block;
  margin-bottom: 16px;
  font-size: .9375rem;
  font-weight: 500;
  text-decoration: none;
}
.back-link:hover { text-decoration: underline; }

/* --- Page heading --------------------------------------------------------- */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.page-head h1 { margin-bottom: 4px; font-size: 1.625rem; }
.page-sub { margin: 2px 0 0; font-size: .9375rem; }

/* The buttons that sit opposite the page title. */
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.head-actions .button { min-height: 46px; padding: 11px 18px; font-size: .9375rem; }

/* A note under a table, explaining something rather than shouting it. */
.page-foot { margin: 16px 2px 0; max-width: 620px; }

/* --- Tables --------------------------------------------------------------- */

.table-wrap {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  /* Wide tables scroll inside their own box rather than pushing the page
     sideways on a narrow screen. */
  overflow-x: auto;
}

.table { width: 100%; border-collapse: collapse; font-size: .9375rem; }

.table th {
  text-align: start;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table td { padding: 14px 16px; border-bottom: 1px solid #eef2f3; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafcfc; }

.cell-title a { font-weight: 600; text-decoration: none; color: var(--navy); }
.cell-title a:hover { color: var(--teal-dark); text-decoration: underline; }
.cell-sub { display: block; font-size: .8125rem; color: var(--muted); margin-top: 2px; }

.cell-index { width: 48px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cell-count { width: 110px; text-align: center; }
.cell-name { font-weight: 500; }
.cell-email { color: var(--muted); }
.cell-time { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.cell-actions { width: 1%; white-space: nowrap; text-align: end; }
.cell-remove { width: 1%; text-align: end; }

/* Signature thumbnails sit on a faint tint so a pale stroke is still visible. */
.cell-signature { width: 140px; }
.cell-signature img {
  display: block;
  width: 120px;
  height: 40px;
  background: #fbfdfd;
  border: 1px solid #eef2f3;
  border-radius: 4px;
}

.count-pill {
  display: inline-block;
  min-width: 34px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--teal-wash);
  color: var(--navy);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* --- Status and small buttons --------------------------------------------- */

.status {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: .8125rem;
  font-weight: 600;
  white-space: nowrap;
}
.status--open { background: #e4f5ee; color: var(--success); }
.status--closed { background: #eef1f2; color: var(--muted); }

.chip {
  display: inline-block;
  padding: 7px 13px;
  margin-inline-start: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  font: inherit;
  font-size: .875rem;
  font-weight: 500;
  color: var(--navy);
  text-decoration: none;
  cursor: pointer;
}
.chip:hover { background: var(--grey); border-color: #c6d0d4; }
.chip--action { color: var(--teal-dark); }

.inline-form { display: inline; margin: 0; }
.link-button--danger { color: var(--danger); }
.link-button--danger:hover { color: #8f1e17; }

/* --- Toolbar and stats ---------------------------------------------------- */

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 22px; }
.toolbar .button { min-height: 44px; padding: 10px 16px; font-size: .9375rem; }

.stat-row {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 22px;
  margin-bottom: 20px;
}

.stat { display: flex; align-items: baseline; gap: 8px; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-weight: 500; }
.stat-note { margin: 0; flex: 1 1 260px; }

/* --- Search and sort ------------------------------------------------------ */

.list-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.list-controls input[type="search"] { flex: 1 1 260px; min-height: 46px; }
.list-controls select { flex: 0 1 260px; min-height: 46px; }
.sort-label { margin: 0; font-size: .875rem; color: var(--muted); font-weight: 500; }

/* --- Forms ---------------------------------------------------------------- */

.card--form { max-width: 620px; }
.req { font-weight: 400; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 26px; }
.error-list { margin: 6px 0 0; padding-inline-start: 20px; }
.error-list li { margin-bottom: 2px; }

/* --- Empty states --------------------------------------------------------- */

.empty {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 48px 28px;
  text-align: center;
}
.empty h2 { font-size: 1.125rem; }
.empty p { max-width: 380px; margin: 0 auto 18px; }
.empty .button { margin-top: 4px; }

/* --- The QR page ---------------------------------------------------------- */

.qr-page { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 24px; align-items: start; }

.qr-panel {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 28px 40px;
  text-align: center;
}

.qr-title { font-size: 1.75rem; margin-bottom: 6px; }
.qr-instruction { font-size: 1.125rem; font-weight: 600; color: var(--navy); margin-bottom: 26px; }

/* Big enough to be read from the back of a lecture hall when projected. */
.qr-holder { width: min(420px, 80%); margin: 0 auto 26px; }
.qr-holder svg { width: 100%; height: auto; display: block; }

.qr-url {
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--navy);
  word-break: break-all;
  margin-bottom: 6px;
}

.qr-actions {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.qr-actions .hint { margin: 4px 0 0; font-size: .8125rem; color: var(--muted); }

@media (max-width: 820px) {
  .qr-page { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .875em;
  background: var(--grey);
  padding: 2px 5px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------------------
   Arabic text inside an English page
   ---------------------------------------------------------------------------
   dir="rtl" does two things: it lays the letters out right-to-left (which we
   want, always) and it pushes the line to the right-hand edge (which we do
   NOT want when the line sits underneath a left-aligned English title — it
   drifts away from the text it belongs to).
   So while the page itself is left-to-right, these lines keep their correct
   right-to-left letters but stay tucked under their English heading. When the
   attendee page is switched to Arabic the whole page becomes right-to-left
   and this rule stops applying, which is exactly right.
--------------------------------------------------------------------------- */

html[dir="ltr"] .cell-sub[dir="rtl"],
html[dir="ltr"] .page-sub[dir="rtl"],
html[dir="ltr"] .event-title-ar {
  text-align: left;
}

/* --- The export page ------------------------------------------------------ */

.export-block { border-top: 1px solid var(--line); margin-top: 26px; padding-top: 22px; }
.export-block:first-of-type { border-top: 0; margin-top: 20px; }
.export-block h2 { font-size: 1rem; margin-bottom: 6px; }
.export-block p { margin-bottom: 14px; }
.export-buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.export-buttons .button { min-height: 46px; padding: 11px 18px; font-size: .9375rem; }

/* ===========================================================================
   THE LANGUAGE SWITCH  (attendee pages only)
   English / العربية, sitting above the card so it is the first thing a
   reader finds. Both options are always visible — a toggle that only shows
   the "other" language is a coin flip for anyone unsure.
   =========================================================================== */

.page-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

/* The brand mark sits in this strip now, not inside the card. */
.page-top .brand-mark { margin-bottom: 0; }

.lang-switch {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: #e6ebed;
  /* The switch reads the same way round in both languages: English on the
     left, Arabic on the right, always. */
  direction: ltr;
}

.lang-option {
  min-height: 38px;
  padding: 7px 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font: inherit;
  font-size: .875rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  /* Stop the grey flash some phones paint over a tapped button. */
  -webkit-tap-highlight-color: transparent;
  transition: background .15s ease, color .15s ease;
}

.lang-option[lang="ar"] { font-family: 'IBM Plex Sans Arabic', var(--font); }

.lang-option:hover { color: var(--navy); }

/* The language currently in use. */
.lang-option.is-active {
  background: var(--white);
  color: var(--navy);
  box-shadow: 0 1px 3px rgba(10, 37, 51, .14);
}

/* On the centred pages (event not found) the switch sits above the heading. */
.card--narrow .lang-switch { margin-bottom: 18px; }

/* ===========================================================================
   RIGHT-TO-LEFT
   Nearly everything mirrors by itself, because the layout is built from flex,
   grid and logical properties. These are the few places that need saying.
   =========================================================================== */

/* Email addresses and web addresses are always read left-to-right, even in an
   Arabic sentence, or the dot and the @ end up in the wrong place. */
[dir="rtl"] input[type="email"],
[dir="rtl"] .qr-url { direction: ltr; text-align: start; }

/* The confirmation and "already registered" cards stay centred either way. */
[dir="rtl"] .centre { text-align: center; }

/* ===========================================================================
   SMALL TOUCHES
   =========================================================================== */

/* While the form is being sent, the button shows a turning ring so a slow
   connection does not look like a page that has frozen. */
.button.is-sending::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: var(--white);
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* The teal tick used on the "already registered" card. */
.tick--info { margin-bottom: 12px; }

/* Somebody who registers is done — give them room to breathe. */
#done-view h1, #already-view h1 { margin-bottom: 10px; }
#done-view p:last-child, #already-view p:last-child { margin-bottom: 0; }

/* Buttons and inputs on a phone: no grey flash on tap, and never zoom in on
   focus (a font size under 16px makes iOS zoom the whole page). */
button, .button, .chip, .link-button { -webkit-tap-highlight-color: transparent; }
input, select, textarea { font-size: max(16px, 1rem); }

/* Some people find movement uncomfortable, and their phone says so. Respect it. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===========================================================================
   PRINTING
   Printing the QR page from the browser (Ctrl+P / Cmd+P) should give the same
   clean sign as the PDF button, not the dashboard around it.
   =========================================================================== */

@media print {
  body { background: var(--white); }
  .topbar, .back-link, .qr-actions, .toolbar, .list-controls,
  .lang-switch, .cell-remove { display: none !important; }
  .qr-page { display: block; }
  .qr-panel, .card, .table-wrap { box-shadow: none; border: 0; }
  .qr-holder { width: 70%; }
  a[href]::after { content: ""; }
}
