/* ===========================================================================
   app.css — layout + components for the authed COACT shell.
   Builds on tokens.css / theme.css (CSS custom properties, dark + light).
   =========================================================================== */

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--surface-900);
  color: var(--text-primary);
  font-family: var(--font-ui, system-ui, sans-serif);
  font-size: var(--text-base, 14px);
  line-height: var(--lh-base, 20px);
}

.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

/* Sidebar */
.app-sidebar {
  background: var(--surface-800);
  border-right: var(--border);
  padding: var(--space-4);
  display: flex; flex-direction: column; gap: var(--space-2);
}
.app-brand {
  font-family: var(--font-brand, var(--font-ui));
  font-weight: 800; font-size: var(--text-xl);
  letter-spacing: 0.04em;
  background: var(--brand-gradient);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: var(--space-4);
}
.app-brand img { width: 132px; height: auto; display: block; }
.nav-section {
  font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); margin: var(--space-4) 0 var(--space-1);
}
.nav-link {
  display: block; padding: 8px 10px; border-radius: var(--radius-md);
  color: var(--text-secondary); text-decoration: none; font-size: var(--text-sm);
}
.nav-link:hover { background: var(--surface-600); color: var(--text-primary); }
.nav-link[aria-current="page"] { background: var(--accent-muted); color: var(--accent-hover); font-weight: 600; }

/* Main */
.app-main { display: flex; flex-direction: column; min-width: 0; }
.app-topbar {
  height: var(--topbar-h); min-height: var(--topbar-h);
  border-bottom: var(--border); background: var(--surface-800);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-5);
}
#app-whoami { display: flex; flex-direction: column; line-height: 1.2; }
#app-whoami .muted { color: var(--text-muted); font-size: var(--text-xs); }
.app-content { padding: var(--space-5); max-width: 1100px; width: 100%; }

h1 { font-size: var(--text-xl); margin: 0 0 var(--space-2); }
.page-sub { color: var(--text-secondary); margin: 0 0 var(--space-5); font-size: var(--text-sm); }

/* Cards */
.card {
  background: var(--surface-800); border: var(--border);
  border-radius: var(--radius-lg); padding: var(--space-5);
  margin-bottom: var(--space-5);
}
.card h2 { font-size: var(--text-lg); margin: 0 0 var(--space-4); }

/* Forms */
.field { margin-bottom: var(--space-4); }
.field label { display: block; font-size: var(--text-xs); color: var(--text-secondary); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-md);
  border: 1px solid var(--surface-500); background: var(--surface-600);
  color: var(--text-primary); font-size: var(--text-sm); font-family: inherit;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.row { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.row .field { flex: 1; min-width: 160px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-md); border: 1px solid transparent;
  font-size: var(--text-sm); font-weight: 600; cursor: pointer; font-family: inherit;
  background: var(--accent); color: #fff;
}
.btn:hover { background: var(--accent-hover); }
.btn.secondary { background: transparent; border-color: var(--surface-500); color: var(--text-primary); }
.btn.secondary:hover { background: var(--surface-600); }
.btn.ghost { background: transparent; color: var(--text-secondary); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* Tables */
table.data { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
table.data th, table.data td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--surface-500); }
table.data th { color: var(--text-muted); font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.06em; }
table.data tr:hover td { background: var(--surface-600); }

/* Status pills */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: var(--text-2xs); font-weight: 600; }
.pill.active   { background: rgba(92,203,59,0.16);  color: var(--positive); }
.pill.invited  { background: rgba(232,161,58,0.16); color: var(--warning); }
.pill.suspended,.pill.disabled { background: rgba(239,92,107,0.16); color: var(--negative); }

.muted { color: var(--text-muted); }
.mono { font-family: var(--font-data, monospace); }
.inline-link { color: var(--accent-hover); cursor: pointer; text-decoration: underline; }

/* Reveal box (one-time set-password link) */
.reveal {
  background: var(--surface-700); border: 1px dashed var(--surface-500);
  border-radius: var(--radius-md); padding: var(--space-3); margin-top: var(--space-3);
  font-family: var(--font-data, monospace); font-size: var(--text-xs); word-break: break-all;
}

/* User menu (account popup) */
.usermenu { position: relative; }
.usermenu-trigger { background: none; border: 0; cursor: pointer; padding: 0; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; font-size: var(--text-xs);
  letter-spacing: 0.5px;
}
.usermenu-pop {
  position: absolute; right: 0; top: 44px; z-index: 1000;
  width: 280px; background: var(--surface-700); border: var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-popover);
  padding: var(--space-3); display: flex; flex-direction: column; gap: 2px;
}
.um-head { padding: var(--space-2) var(--space-2) var(--space-3); }
.um-name { font-weight: 700; }
.um-email { font-size: var(--text-xs); }
.um-chips { margin-top: var(--space-2); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: var(--text-2xs);
  background: var(--surface-600); color: var(--text-secondary); }
.um-acting { margin-top: var(--space-2); font-size: var(--text-xs); color: var(--accent-hover); }
.um-item { display: block; padding: 9px 10px; border-radius: var(--radius-md); color: var(--text-primary);
  text-decoration: none; font-size: var(--text-sm); }
.um-item:hover { background: var(--surface-600); }
.um-item.danger { color: var(--negative); }
.um-row { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; font-size: var(--text-sm); }
.um-switch select { flex: 1; max-width: 150px; padding: 5px 8px; border-radius: var(--radius-md);
  border: 1px solid var(--surface-500); background: var(--surface-600); color: var(--text-primary); font-size: var(--text-xs); }
.um-sep { height: 1px; background: var(--surface-500); margin: var(--space-2) 0; }
.seg { display: inline-flex; border: 1px solid var(--surface-500); border-radius: 999px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 5px 12px; font-size: var(--text-xs);
  color: var(--text-secondary); cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }

/* Theme swatch picker (Settings page) */
.swatches { display: flex; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-2); }
.swatch { cursor: pointer; border: 2px solid transparent; border-radius: var(--radius-md); padding: 4px;
  text-align: center; font-size: var(--text-2xs); color: var(--text-secondary); }
.swatch.on { border-color: var(--accent); }
.swatch .dot { width: 44px; height: 28px; border-radius: var(--radius-sm); display: block; margin-bottom: 4px; }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar { display: none; }
}
