/* =====================================================================
   apps.erdmanautomation.com — the hub: sign-in, and the list of apps.

   ITS OWN STYLESHEET, like every app's. The tokens and the card rules are
   lifted from public/pretrip/static/css/form.css so the sign-in pages look
   exactly as they did when they were the pre-trip site's — they are the
   same pages, moved. Deliberately NOT kept in sync with it afterwards:
   two files that must match is the trap.

   What is new here is the app list on the home page, at the bottom.
 * ===================================================================== */

/* ---------------------------------------------------------------- *
   Tokens
 * ---------------------------------------------------------------- */
:root {
  --bg:            #f4f5f7;
  --surface:       #ffffff;
  --surface-2:     #fafbfc;
  --surface-sunk:  #eef0f3;
  --border:        #dfe3e8;
  --border-strong: #c6ccd4;

  --text:          #1a1f26;
  --text-muted:    #626c7a;
  --text-faint:    #8a94a2;

  --accent:        #1a5fb4;
  --accent-hover:  #164e94;
  --accent-soft:   #e8f0fb;
  --accent-text:   #ffffff;

  --danger:        #b3261e;
  --danger-soft:   #fdeceb;
  --success:       #1a7f4b;
  --success-soft:  #e6f4ec;
  --warning:       #9a6400;
  --warning-soft:  #fdf3e0;

  --radius:    8px;
  --radius-sm: 5px;

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

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #14171c;
    --surface:       #1c2027;
    --surface-2:     #21262e;
    --surface-sunk:  #171b21;
    --border:        #2e3540;
    --border-strong: #3d4653;

    --text:          #e6e9ee;
    --text-muted:    #9aa4b2;
    --text-faint:    #6f7987;

    --accent:        #5c9dfa;
    --accent-hover:  #7bb0fb;
    --accent-soft:   #1b2b42;
    --accent-text:   #0e1116;

    --danger:        #f28b82;
    --danger-soft:   #3a1f1d;
    --success:       #6fce9a;
    --success-soft:  #16301f;
    --warning:       #e3b341;
    --warning-soft:  #332612;

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

/* ---------------------------------------------------------------- *
   Base
 * ---------------------------------------------------------------- */
[hidden] { display: none !important; }

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.3; }

p { margin: 0 0 .75em; }

p:last-child { margin-bottom: 0; }

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

a:hover { text-decoration: underline; }

.subtle { color: var(--text-muted); font-size: 13px; }

.mono { font-family: var(--mono); }

.text-center { text-align: center; }

.mt-1 { margin-top: .5rem; }

/* ---------------------------------------------------------------- *
   Forms and buttons
 * ---------------------------------------------------------------- */
.form-row { display: flex; flex-direction: column; gap: .3rem; }

label { font-size: 13px; font-weight: 600; }

input[type="email"], input[type="text"], input[type="tel"], select {
  width: 100%;
  padding: .45rem .6rem;
  font: inherit; font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

input::placeholder { color: var(--text-faint); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .45rem .85rem;
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-sunk); text-decoration: none; }

.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-danger { color: var(--danger); border-color: var(--border-strong); }

.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}

.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { background: transparent; border-color: var(--border); }

.btn-sm { padding: .25rem .55rem; font-size: 12px; }

/* ---------------------------------------------------------------- *
   Flash messages
 * ---------------------------------------------------------------- */
.flashes { margin-bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; }

.flash {
  padding: .6rem .85rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 500;
}

.flash-success { background: var(--success-soft); color: var(--success); border-color: currentColor; }

.flash-error { background: var(--danger-soft);  color: var(--danger);  border-color: currentColor; }

.flash-warning { background: var(--warning-soft); color: var(--warning); border-color: currentColor; }

/* ---------------------------------------------------------------- *
   The sign-in cards
 * ---------------------------------------------------------------- */
.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 2rem 1rem;
  background: var(--bg);
}

.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.75rem;
}

.auth-head { text-align: center; margin-bottom: 1.25rem; }

.auth-head h1 { font-size: 19px; margin-bottom: .25rem; }

.auth-head p { color: var(--text-muted); font-size: 13px; overflow-wrap: anywhere; }

.auth-card .form-row + .form-row { margin-top: .85rem; }

.auth-card .btn-primary { width: 100%; margin-top: 1.15rem; padding: .55rem; }

/* The number to pick on another device (login_sent), and the three to
   pick from (login_approve). Big: it is read across a desk, off a PC. */
.auth-number {
  margin: 1rem auto;
  padding: .5rem 0;
  width: 7rem;
  text-align: center;
  font-size: 40px; font-weight: 700; letter-spacing: .08em;
  font-variant-numeric: tabular-nums;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}

.auth-choices { display: flex; gap: .5rem; margin-top: 1rem; }

.auth-choices .btn {
  flex: 1;
  padding: .7rem 0;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- *
   Top bar — the home page
 * ---------------------------------------------------------------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
  padding: .55rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-brand {
  font-weight: 650; font-size: 15px; letter-spacing: -.01em;
  color: var(--text);
}

.topbar-brand:hover { text-decoration: none; }

.topbar-user { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .6rem; margin-left: auto; }

.topbar-user form { margin: 0; }

/* A long address must not push "Sign out" off a phone screen. */
.topbar-email {
  max-width: 16rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* The address is a link to "Your details" (/profile on the hub): name and
   phone for forms. Muted like the text it replaced, until hovered. */
a.topbar-email { color: var(--text-muted); font-size: 13px; }
a.topbar-email:hover { color: var(--accent); }

/* A card page under the top bar: full height minus the bar. */
.auth-wrap.with-topbar { min-height: calc(100vh - 52px); }

/* ---------------------------------------------------------------- *
   The list of apps
 * ---------------------------------------------------------------- */
.page { padding: 1.5rem 1rem; max-width: 760px; margin: 0 auto; }

.page-title { font-size: 20px; margin-bottom: 1rem; }

.app-list {
  list-style: none; margin: 0; padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: .9rem;
}

.app-tile {
  display: flex; flex-direction: column; gap: .3rem;
  height: 100%;
  padding: 1.1rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  color: var(--text);
}

.app-tile:hover {
  text-decoration: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.app-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app-tile-name { font-size: 16px; font-weight: 650; color: var(--accent); }

.app-tile-desc { font-size: 13px; color: var(--text-muted); }

/* ---------------------------------------------------------------- *
   Home: the apps, and the Links column down the side
 * ---------------------------------------------------------------- */
.page-wide { max-width: 1040px; }

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

/* On a phone the column has nowhere to go but underneath. */
@media (max-width: 720px) {
  .home-grid { grid-template-columns: minmax(0, 1fr); }
}

.links-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem;
}

.links-head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  margin-bottom: .6rem;
}

.links-head h2 {
  font-size: 12px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-faint);
}

.link-list { list-style: none; margin: 0; padding: 0; }

.link-list li + li { border-top: 1px solid var(--border); }

.link-list a {
  display: block;
  padding: .5rem 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------- *
   /links — the admin page
 * ---------------------------------------------------------------- */
.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-bottom: .75rem;
}

.page-head .page-title { margin-bottom: 0; }

.panel {
  margin-top: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-head { padding: .75rem 1rem; border-bottom: 1px solid var(--border); }

.panel-head h2 { font-size: 14px; }

.panel-body { padding: 1rem; }

.table-wrap { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }

table.data th, table.data td {
  padding: .5rem .75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.data th {
  font-size: 11px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text-faint);
  background: var(--surface-2);
}

table.data input[type="text"] { min-width: 10rem; }

table.data select { width: auto; min-width: 6.5rem; }

td.actions { text-align: right; white-space: nowrap; }

td.actions form { display: inline; margin: 0; }

.add-link { display: flex; flex-direction: column; gap: .75rem; max-width: 34rem; }

/* ---------------------------------------------------------------- *
   /access — Users & permissions
 * ---------------------------------------------------------------- */
.tabs {
  display: flex; flex-wrap: wrap; gap: .25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.tab {
  padding: .5rem .9rem;
  font-size: 13px; font-weight: 600;
  color: var(--text-muted);
  border: 1px solid transparent; border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  text-decoration: none;
}

.tab:hover { background: var(--surface-sunk); text-decoration: none; }

.tab.is-active {
  color: var(--accent);
  background: var(--surface);
  border-color: var(--border);
  margin-bottom: -1px;
  padding-bottom: calc(.5rem + 1px);
}

.nowrap { white-space: nowrap; }

.chip {
  display: inline-block;
  margin: .1rem .15rem .1rem 0;
  padding: .1rem .5rem;
  font-size: 11px; font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
}

a.chip:hover { background: var(--border); text-decoration: none; }

.chip-accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }

.check-list { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem 1rem; }

.check { display: inline-flex; align-items: center; gap: .35rem; font-size: 13px; }

.inline-edit { margin-top: .25rem; }

.inline-edit summary { cursor: pointer; font-size: 12px; color: var(--accent); }

.inline-edit .check-list { margin-top: .5rem; padding: .5rem; border: 1px solid var(--border); border-radius: var(--radius); }

.group-form { display: flex; flex-direction: column; gap: .75rem; max-width: 44rem; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .75rem; }

.perm-app {
  display: flex; flex-direction: column; gap: .35rem;
  margin: 0; padding: .5rem .75rem .75rem;
  border: 1px solid var(--border); border-radius: var(--radius);
}

.perm-app legend { padding: 0 .35rem; font-size: 12px; font-weight: 700; color: var(--text-muted); }

.sub-head { margin: 1.25rem 0 .5rem; font-size: 13px; }

.member-list { list-style: none; margin: 0 0 .75rem; padding: 0; display: flex; flex-direction: column; gap: .35rem; }

.member-list li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; font-size: 13px; }

.member-list form { margin: 0; }

.inline-add { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }

.inline-add input[type="email"] { flex: 1 1 14rem; max-width: 22rem; }

.delete-group { margin-top: .5rem; }

.row-action { margin: .25rem 0 0; }
