/* ==========================================================================
   Tringtring - mobile-only stylesheet.

   This app is designed for a phone and nothing else. There are no desktop
   breakpoints that rearrange the layout: on a wide screen the app renders as a
   centred phone-width column rather than stretching, so the touch-first
   layout always holds. The admin panel has its own responsive stylesheet.
   ========================================================================== */

/* --- Tokens --------------------------------------------------------------- */
:root {
  --brand:          #4f46e5;
  --brand-strong:   #4338ca;
  --brand-soft:     #eef2ff;
  --brand-contrast: #ffffff;

  --bg:             #f4f5f9;
  --surface:        #ffffff;
  --surface-alt:    #f8f9fc;
  --border:         #e3e5ee;
  --border-strong:  #cdd0de;

  --text:           #151726;
  --text-muted:     #676b82;
  --text-faint:     #9195aa;

  --danger:         #d92d20;
  --danger-soft:    #fef3f2;
  --success:        #067647;
  --success-soft:   #ecfdf3;
  --warning:        #b54708;

  --bubble-in:      #ffffff;
  --bubble-out:     #4f46e5;
  --bubble-out-text:#ffffff;

  --radius-sm: 8px;
  --radius:    14px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(16, 18, 40, .06);
  --shadow:    0 4px 16px rgba(16, 18, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 18, 40, .16);

  /* Header and composer heights, referenced by the scroll area. */
  --header-h:   58px;
  --composer-h: 60px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";

  /* Widest the app is ever allowed to render. Beyond this it centres. */
  --app-max-width: 480px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand:          #7c74f5;
    --brand-strong:   #6d64f0;
    --brand-soft:     #23233c;
    --brand-contrast: #ffffff;

    --bg:             #0e0f18;
    --surface:        #171826;
    --surface-alt:    #1e1f30;
    --border:         #2a2c40;
    --border-strong:  #3b3d55;

    --text:           #eceef8;
    --text-muted:     #a0a4bd;
    --text-faint:     #757a94;

    --danger:         #f97066;
    --danger-soft:    #2a1a1c;
    --success:        #47cd89;
    --success-soft:   #16241d;
    --warning:        #f79009;

    --bubble-in:      #23253a;
    --bubble-out:     #5b52e8;
    --bubble-out-text:#ffffff;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow:    0 4px 16px rgba(0, 0, 0, .45);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .6);
  }
}

/* --- Reset ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

html {
  /* Stops iOS Safari inflating text in landscape. */
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  font-size: 16px;               /* Anything smaller makes iOS zoom on focus. */
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;   /* No pull-to-refresh mid-conversation. */
}

img { max-width: 100%; display: block; }

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

a { color: var(--brand); text-decoration: none; }

/* --- App shell ------------------------------------------------------------
   100dvh rather than 100vh: on mobile browsers vh includes the collapsing
   address bar, which leaves the composer floating off-screen.
   -------------------------------------------------------------------------- */
.app {
  position: relative;
  width: 100%;
  max-width: var(--app-max-width);
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* On anything wider than a phone, frame the column so it reads as intentional
   rather than as a broken desktop layout. */
@media (min-width: 520px) {
  body { background: #e8eaf2; }
  @media (prefers-color-scheme: dark) {
    body { background: #07080f; }
  }
  .app {
    height: min(100dvh, 900px);
    margin-top: max(0px, calc((100dvh - 900px) / 2));
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
  }
}

/* --- Screens (full-page views, swapped rather than shown side by side) ----- */
.screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;               /* Lets the inner scroll area actually scroll. */
}
.screen[hidden] { display: none; }

/* --- Top bar -------------------------------------------------------------- */
.topbar {
  flex: 0 0 auto;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar__title {
  font-size: 17px;
  font-weight: 650;
  margin: 0;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__sub {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.2;
}

.topbar__grow { flex: 1; min-width: 0; }

/* --- Icon buttons: 44px minimum, the smallest reliable touch target -------- */
.icon-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: var(--surface-alt); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn--danger { color: var(--danger); }

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--brand);
  color: var(--brand-contrast);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s ease, opacity .15s ease;
}
.btn:active { background: var(--brand-strong); }
.btn:disabled { opacity: .55; cursor: default; }
.btn--block { width: 100%; }
.btn--ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}
.btn--ghost:active { background: var(--surface-alt); }
.btn--danger { background: var(--danger); }
.btn--sm { min-height: 38px; padding: 0 14px; font-size: 14px; border-radius: var(--radius-sm); }

/* --- Forms ---------------------------------------------------------------- */
.field { margin-bottom: 16px; }

.field__label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.input {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 16px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.input[aria-invalid="true"] { border-color: var(--danger); }

.field__hint { font-size: 12px; color: var(--text-faint); margin-top: 6px; }
.field__error { font-size: 13px; color: var(--danger); margin-top: 6px; }

/* Password field with a reveal toggle sitting inside it. */
.input-group { position: relative; }
.input-group .input { padding-right: 52px; }
.input-group__action {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}

/* --- Alerts --------------------------------------------------------------- */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert--error   { background: var(--danger-soft);  color: var(--danger);  border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert--success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.alert--info    { background: var(--brand-soft);   color: var(--brand-strong); border-color: color-mix(in srgb, var(--brand) 22%, transparent); }

/* --- Auth screens --------------------------------------------------------- */
.auth {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 22px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
  background: var(--bg);
}

.auth__brand {
  text-align: center;
  margin-bottom: 28px;
}

.auth__logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 20px;
  background: var(--brand);
  color: var(--brand-contrast);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}
.auth__logo svg { width: 34px; height: 34px; }

.auth__name {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.auth__tagline {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--text-muted);
}

.auth__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  box-shadow: var(--shadow-sm);
}

.auth__heading {
  margin: 0 0 18px;
  font-size: 19px;
  font-weight: 650;
}

.auth__footer {
  margin-top: 20px;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
}
.auth__footer a { font-weight: 600; }

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

.stack-8  > * + * { margin-top: 8px; }
.stack-12 > * + * { margin-top: 12px; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
