/* ── Reset & base ───────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}
a { color: inherit; text-decoration: none; }
img { display: block; }

/* ── Shell layout ───────────────────────────────── */
.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────── */
.shell-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 60px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  position: sticky;
  top: 0;
  z-index: 10;
}
.shell-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.shell-logo { width: 26px; height: 26px; }
.shell-brand-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.shell-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.shell-user-name {
  font-size: 0.875rem;
  color: var(--text-dim);
}
.shell-signout {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--border-input);
  border-radius: 7px;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
  font-family: inherit;
  transition: color 120ms, border-color 120ms;
}
.shell-signout:hover {
  color: var(--text-primary);
  border-color: var(--border-input);
}

.shell-user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: 7px;
  padding: 0.25rem 0.5rem;
  transition: background 120ms;
}
.shell-user-chip:hover { background: var(--bg-hover); }

.shell-user-avatar {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 800;
  color: #fff;
  overflow: hidden;
}
.shell-user-avatar--image { background: none; }
.shell-user-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ── Profile page ────────────────────────────────── */
.profile-page {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-width: 520px;
}

.profile-header {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.profile-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.profile-avatar-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
}

.profile-email {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-faint);
}

.shell-user-link {
  transition: color 120ms;
}
.shell-user-link:hover { color: var(--text-primary); }

/* ── Main area ──────────────────────────────────── */
.shell-main {
  flex: 1;
  padding: 2.5rem 1.5rem;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

/* ── Terminal notice ─────────────────────────────── */
@keyframes terminal-cursor-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}
@keyframes terminal-notice-fade {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.terminal-notice {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.875rem;
  color: var(--terminal-color);
  text-shadow: 0 0 6px var(--terminal-glow), 0 0 2px var(--terminal-glow);
  background: rgba(0,0,0,0.55);
  border: 0px solid transparent;
  border-radius: 6px;
  padding: 0.65rem 1rem;
  margin-bottom: 1.25rem;
  letter-spacing: 0.04em;
  position: relative;
}

.terminal-notice::after {
  content: "▋";
  display: inline-block;
  margin-left: 1px;
  animation: terminal-cursor-blink 0.8s step-start infinite;
  color: var(--terminal-color);
  text-shadow: 0 0 6px var(--terminal-glow);
}

.terminal-notice--fade {
  animation: terminal-notice-fade 0.6s ease forwards;
}

/* keep .app-notice as alias */
.app-notice {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.875rem;
  color: var(--terminal-color);
  text-shadow: 0 0 6px var(--terminal-glow), 0 0 2px var(--terminal-glow);
  background: rgba(0,0,0,0.55);
  border: 0px solid transparent;
  border-radius: 6px;
  padding: 0.65rem 1rem;
  margin-bottom: 1.25rem;
  letter-spacing: 0.04em;
}

/* ── Workspaces page ────────────────────────────── */
.workspaces-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 2rem;
  gap: 1rem;
}
.workspaces-title {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--text-primary);
}
.workspaces-sub {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* ── Workspace list ─────────────────────────────── */
.workspace-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.workspace-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 140ms, background 140ms;
}
.workspace-card:hover {
  border-color: var(--accent-border);
  background: var(--bg-active);
}
.workspace-card-icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
  overflow: hidden;
}
.workspace-card-icon--image {
  background: none;
}
.workspace-card-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.workspace-card-body {
  flex: 1;
  min-width: 0;
}
.workspace-card-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.workspace-card-desc {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.workspace-card-role {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  background: var(--bg-hover);
  border: 1px solid var(--border-card);
  border-radius: 6px;
  padding: 0.2rem 0.55rem;
}

/* ── Empty state ────────────────────────────────── */
.workspaces-empty {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-faint);
  font-size: 0.95rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

/* ── New workspace page ─────────────────────────── */
.new-workspace-page {
  display: flex;
  justify-content: center;
  padding-top: 1rem;
}
.new-workspace-page .auth-card { max-width: 480px; width: 100%; }
.new-workspace-page .auth-card__title { font-size: 1.5rem; }

/* ── Shared auth bits (reused) ───────────────────── */
.auth-card__header { text-align: center; margin-bottom: 2rem; }
.auth-card__title {
  margin: 0 0 0.4rem;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--text-primary);
}
.auth-card__sub { margin: 0; font-size: 0.95rem; color: var(--text-dim); }

.auth-alert {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
  color: var(--error-text);
}
.auth-alert p { margin: 0; }
.auth-alert p + p { margin-top: 0.25rem; }

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 16px;
  padding: 2rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-label { font-size: 0.83rem; font-weight: 600; color: var(--text-muted); letter-spacing: 0.01em; }
.form-input {
  width: 100%;
  padding: 0.7rem 0.9rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 9px;
  outline: none;
  transition: border-color 140ms, box-shadow 140ms;
  -webkit-appearance: none;
}
.form-input::placeholder { color: var(--text-ghost); }
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.form-input--error { border-color: var(--error-border); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-textarea--tall { min-height: 180px; }

.btn-submit {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.8rem 1rem;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  color: #ffffff;
  background: var(--accent);
  border: none;
  border-radius: 9px;
  cursor: pointer;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: background 140ms, transform 120ms, box-shadow 140ms;
}
.btn-submit:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-glow);
}
.btn-submit:active { transform: translateY(0); }

/* ── Danger button ───────────────────────────────── */
.btn-danger {
  padding: 0.6rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--error-text);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 7px;
  cursor: pointer;
  transition: background 140ms, color 140ms;
}
.btn-danger:hover {
  background: rgba(239,68,68,0.22);
  color: #f87171;
}

/* ── Primary button (link style) ─────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  padding: 0.65rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border-radius: 9px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: background 140ms, transform 120ms;
  white-space: nowrap;
}
.btn-primary:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

/* ── Collection icon in sidebar ─────────────────── */
.ws-collection-icon {
  font-size: 0.8rem;
  color: var(--text-faint);
  line-height: 1;
  flex-shrink: 0;
}

/* ── Form hint text ─────────────────────────────── */
.form-hint {
  margin: 0.3rem 0 0;
  font-size: 0.78rem;
  color: var(--text-faint);
  line-height: 1.5;
}
.form-hint code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.75rem;
  color: var(--text-dim);
  background: var(--bg-hover);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}

/* ── Monospace textarea ─────────────────────────── */
.form-textarea--mono {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.82rem;
}

/* ── Workspace interior shell ────────────────────── */
.ws-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-primary);
}

/* ── Main content area ───────────────────────────── */
turbo-frame#workspace-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

@keyframes ws-spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

turbo-frame#workspace-content[aria-busy="true"]::after,
turbo-frame#settings-content[aria-busy="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 20, 0.6);
  z-index: 10;
  display: block;
}

turbo-frame#workspace-content[aria-busy="true"]::before,
turbo-frame#settings-content[aria-busy="true"]::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  border: 2.5px solid var(--accent-bg);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ws-spin 0.7s linear infinite;
  z-index: 11;
  transform: translate(-50%, -50%);
}

.ws-main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.ws-notice {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.875rem;
  color: var(--terminal-color);
  text-shadow: 0 0 6px var(--terminal-glow), 0 0 2px var(--terminal-glow);
  background: rgba(0,0,0,0.55);
  border-bottom: 0px solid transparent;
  padding: 0.65rem 1.5rem;
  letter-spacing: 0.04em;
}

.ws-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.ws-placeholder-inner {
  text-align: center;
  max-width: 360px;
}

.ws-placeholder-title {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-ghost);
}

.ws-placeholder-sub {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-ghost);
}

.ws-inline-link {
  color: var(--accent);
  transition: color 120ms;
}
.ws-inline-link:hover { color: var(--accent-light); }

/* ── Channel form extras ─────────────────────────── */
.auth-card__workspace-label {
  margin: 0 0 0.25rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.form-input-prefix-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.form-input-prefix {
  position: absolute;
  left: 0.9rem;
  z-index: 1;
  color: var(--text-dim);
  font-size: 1rem;
  pointer-events: none;
  user-select: none;
}

.form-input.form-input--prefixed {
  padding-left: 1.9rem;
}

.form-hint {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  color: var(--text-faint);
}

/* ── Secondary button ───────────────────────────── */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  padding: 0.65rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-hover);
  border-radius: 9px;
  border: 1px solid var(--border-input);
  cursor: pointer;
  text-decoration: none;
  transition: background 140ms, color 140ms, border-color 140ms;
  white-space: nowrap;
}
.btn-secondary:hover {
  background: var(--bg-active);
  color: var(--text-primary);
  border-color: var(--border-input);
}

/* ── Alert banner ───────────────────────────────── */
.app-alert {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
  color: var(--error-text);
}

/* ── User limit banner ─────────────────────────── */
.ws-limit-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: rgba(234, 179, 8, 0.1);
  border: 1px solid rgba(234, 179, 8, 0.3);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin: 1rem 1.5rem 0;
  font-size: 0.85rem;
  color: #fde68a;
}

.ws-limit-banner-text {
  flex: 1;
}

.ws-limit-banner-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.ws-limit-banner-upgrade {
  background: rgba(234, 179, 8, 0.2);
  border: 1px solid rgba(234, 179, 8, 0.4);
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  color: #fde68a;
  cursor: pointer;
  transition: background 0.15s;
}

.ws-limit-banner-upgrade:hover {
  background: rgba(234, 179, 8, 0.35);
}

.ws-limit-banner-dismiss {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-family: inherit;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.ws-limit-banner-dismiss:hover {
  color: rgba(255, 255, 255, 0.8);
  border-color: rgba(255, 255, 255, 0.3);
}

/* ── Join button ────────────────────────────────── */
.btn-join {
  flex-shrink: 0;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  transition: background 140ms;
}
.btn-join:hover { background: var(--accent-dark); }
.workspace-card--discover { cursor: default; }
.workspace-card--discover:hover { border-color: var(--border-card); background: var(--bg-card); }

/* ── Visibility toggle (new workspace form) ─────── */
.visibility-toggle {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.visibility-option {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 9px;
  cursor: pointer;
  transition: border-color 140ms;
}
.visibility-option:has(.visibility-radio:checked) {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.visibility-radio { margin-top: 0.2rem; accent-color: var(--accent); }
.visibility-option-content { display: flex; flex-direction: column; gap: 0.1rem; }
.visibility-option-title { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.visibility-option-desc { font-size: 0.78rem; color: var(--text-dim); }

/* ── Workspace visibility settings (sidebar) ────── */
.ws-settings {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-subtle);
}
.ws-settings-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  margin-bottom: 0.5rem;
}
.ws-visibility-form { margin: 0; }
.ws-visibility-options {
  display: flex;
  gap: 0.4rem;
}
.ws-vis-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.3rem 0.5rem;
  background: var(--bg-hover);
  border: 1px solid var(--border-card);
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 120ms, color 120ms, background 120ms;
}
.ws-vis-option input[type="radio"] { display: none; }
.ws-vis-option--active {
  border-color: var(--accent);
  color: var(--accent-lighter);
  background: var(--accent-bg);
}

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 640px) {
  .shell-main { padding: 1.5rem 1rem; }
  .workspaces-header { flex-direction: column; }
  .workspace-card-role { display: none; }

  /* Mobile: one panel fills the full screen at a time */
  .ws-sidebar {
    width: 100%;
    border-right: none;
  }

  /* Workspace page (no channel) — hide the empty main area */
  .ws-shell .ws-main:not(.ws-main--chat):not(.ws-main--settings) { display: none; }

  /* Channel page — hide sidebar, chat fills the screen */
  .ws-shell:has(.ws-main--chat) .ws-sidebar { display: none; }
  .ws-main--chat { width: 100%; }

  /* Settings page — hide sidebar, settings fills the screen */
  .ws-shell:has(.ws-main--settings) .ws-sidebar { display: none; }
  .ws-main--settings { width: 100%; }
}

/* ── Admin panel ───────────────────────────────── */
.admin-page {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}
.admin-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 1rem;
  color: var(--text-primary);
}
.admin-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.admin-tab {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 120ms, border-color 120ms;
}
.admin-tab:hover { color: var(--text-primary); }
.admin-tab--active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}
.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.admin-table th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-secondary, var(--bg-primary));
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: var(--bg-hover, rgba(128,128,128,0.06)); }
.admin-mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.admin-link {
  color: var(--accent);
  font-weight: 600;
}
.admin-link:hover { text-decoration: underline; }
.admin-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  background: var(--bg-hover, rgba(128,128,128,0.1));
  color: var(--text-dim);
  text-transform: capitalize;
}
