/* Visual direction matched to legacy R9 CRM (crm-windows reference).
   No legacy CSS files are imported; styles are recreated for this static frontend. */

:root {
  --bg: #edf1f5;
  --bg-app: linear-gradient(180deg, #eff3fb 0%, #f8f9fd 100%);
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --line: #dfe5ef;
  --line-strong: rgba(214, 222, 235, 0.95);
  --text: #141827;
  --muted: #6b7285;
  --accent: #3f83f8;
  --accent-hover: #2f73e8;
  --accent-dark: #111827;
  --danger: #b24545;
  --green: #1d9e75;
  --radius: 18px;
  --radius-card: 26px;
  --radius-sm: 12px;
  --shadow: 0 24px 60px rgba(31, 56, 88, 0.12);
  --shadow-soft: 0 14px 34px rgba(37, 49, 84, 0.07);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --control-height: 42px;
  --sidebar-width: 272px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

.hidden { display: none !important; }

/* ——— Login (legacy auth-screen) ——— */

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #edf1f5;
  overflow: auto;
}

.auth-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(63, 131, 248, 0.1), transparent 42%),
    linear-gradient(300deg, rgba(85, 197, 155, 0.1), transparent 44%);
  pointer-events: none;
}

.auth-card {
  position: relative;
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 28px 26px;
  display: grid;
  gap: 14px;
}

.auth-brand {
  font-size: clamp(1.5rem, 4vw, 1.75rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  color: var(--text);
  line-height: 1.1;
}

.auth-brand span { color: var(--accent); }

.auth-card h1 {
  margin: 0;
  font-size: clamp(1.25rem, 3.5vw, 1.5rem);
  line-height: 1.15;
  font-weight: 800;
}

.auth-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.95rem;
}

.auth-card label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  margin: 0 0 6px;
}

.auth-field { display: grid; gap: 0; }

.input {
  width: 100%;
  min-height: var(--control-height);
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:hover { border-color: #c9d3e3; }

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(63, 131, 248, 0.22);
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  min-height: var(--control-height);
  cursor: pointer;
  font-weight: 700;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:hover { background: #f7f8fc; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn:focus-visible,
.icon-btn:focus-visible,
.nav-btn:focus-visible,
.input:focus-visible {
  outline: 2px solid rgba(63, 131, 248, 0.55);
  outline-offset: 2px;
}

.btn-dark {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  width: 100%;
}

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

.btn-inline { width: auto; }

.btn-edit {
  min-height: 36px;
  padding: 8px 12px;
  font-size: 0.84rem;
  white-space: nowrap;
  background: linear-gradient(180deg, #fff, #f4f7fc);
  border-color: #cfd9ea;
}

.btn-edit:hover {
  border-color: var(--accent);
  color: #1e4fad;
  background: #f3f7ff;
}

.auth-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 480px) {
  .auth-screen { padding: 16px; }
  .auth-card { padding: 22px 20px; gap: 12px; border-radius: 20px; }
}

/* ——— App shell ——— */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  background: var(--bg-app);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 40;
}

.sidebar-sticky {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand {
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.1;
  padding: 0 4px;
}

.brand span { color: var(--accent); }

.card-lite {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: var(--shadow-soft);
}

.current-user {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.current-user .label {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.user-mainline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-mainline strong {
  font-size: 0.95rem;
  letter-spacing: -0.02em;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(29, 158, 117, 0.18);
  flex-shrink: 0;
}

.user-email {
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-word;
  line-height: 1.35;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 800;
}

.chip.admin {
  background: #eef3ff;
  color: #253a7d;
}

.chip.muted-chip {
  background: #f1f5f9;
  color: #64748b;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  text-align: left;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  width: 100%;
}

.nav-btn:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(17, 24, 39, 0.05);
}

.nav-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(17, 24, 39, 0.05);
  position: relative;
}

.nav-btn.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 999px;
  background: var(--accent);
}

.nav-icon {
  width: 1.2rem;
  text-align: center;
  opacity: 0.8;
  flex-shrink: 0;
  font-size: 0.9rem;
}

.nav-label {
  flex: 1;
  min-width: 0;
  font-size: 0.92rem;
}

.nav-badge {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #7b879c;
  background: #eef2f7;
  border-radius: 999px;
  padding: 3px 7px;
  flex-shrink: 0;
}

.nav-disabled,
.nav-btn:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.nav-disabled:hover {
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.sidebar-actions {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding-top: 8px;
}

.sidebar-actions .btn { width: 100%; }

.main-shell {
  min-width: 0;
  padding: 22px 28px 56px;
  overflow-x: hidden;
}

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

.topbar-title {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.4rem, 2.4vw, 1.85rem);
  letter-spacing: -0.035em;
  font-weight: 900;
  line-height: 1.15;
}

.topbar-sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.topbar-context {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding-top: 4px;
}

.topbar-context span {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
}

.topbar-context .env-pill {
  color: #253a7d;
  background: #eef3ff;
  border-color: #d5e0ff;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 700;
  flex-shrink: 0;
}

.icon-btn:hover { background: #f7f8fc; }

.mobile-nav-toggle { display: none; }

.sidebar-backdrop { display: none; }

.view { min-width: 0; }

/* ——— Shared panels / stats ——— */

.panel {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 20px;
}

.panel-accent {
  border-color: #d6e4ff;
  background:
    linear-gradient(180deg, #ffffff, #f7faff);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.panel-head h3 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.muted { color: var(--muted); font-size: 0.84rem; }

.note {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 12px;
}

.error {
  color: var(--danger);
  font-weight: 700;
  background: #fff5f5;
  border: 1px solid #f0d4d4;
  border-radius: 12px;
  padding: 10px 12px;
}

.error:empty {
  display: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.dashboard-stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat {
  padding: 16px 18px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 249, 253, 0.96));
  border: 1px solid var(--line-strong);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.05);
}

.stat .k {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat .v {
  font-size: 1.75rem;
  font-weight: 900;
  margin-top: 8px;
  letter-spacing: -0.04em;
  line-height: 1;
}

.stat .s {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.4;
}

.muted-stat {
  opacity: 0.9;
  background: linear-gradient(180deg, #f8fafc, #f1f5f9);
}

.placeholder-v { color: #94a3b8; }

.panel-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 14px;
  margin-bottom: 14px;
}

.feature-list {
  margin: 0 0 18px;
  padding-left: 18px;
  color: var(--text);
  line-height: 1.55;
  font-size: 0.92rem;
}

.feature-list li { margin-bottom: 9px; }

.placeholder-stack {
  display: grid;
  gap: 10px;
}

.placeholder-card {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px dashed #cfd8e6;
}

.placeholder-card strong { font-size: 0.9rem; }
.placeholder-card span { font-size: 0.8rem; color: var(--muted); line-height: 1.4; }

.system-panel { margin-top: 0; }

.conn-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.conn-pill {
  display: inline-flex;
  align-items: center;
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.conn-pill.ok {
  background: rgba(29, 158, 117, 0.1);
  color: #0f766e;
  border-color: rgba(29, 158, 117, 0.22);
}

.conn-pill.warn {
  background: #fff7ed;
  color: #9a3412;
  border-color: #fed7aa;
}

.conn-pill.bad {
  background: #fff5f5;
  color: var(--danger);
  border-color: #f0d4d4;
}

.tech-details {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.tech-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  user-select: none;
}

.tech-details summary:hover { color: var(--text); }

.tech-details[open] summary { margin-bottom: 10px; }

pre.status-box {
  white-space: pre-wrap;
  word-break: break-word;
  background: #141827;
  color: #f8f4ec;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 0.78rem;
  margin: 0;
  max-height: 160px;
  overflow: auto;
}

/* ——— Team ——— */

.team-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  margin-bottom: 14px;
  border: 1px solid #dce8f6;
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(244, 249, 255, 0.92)),
    radial-gradient(circle at 100% 0%, rgba(55, 197, 155, 0.08), transparent 36%);
  box-shadow: 0 12px 28px rgba(31, 56, 88, 0.06);
}

.team-lede {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  max-width: 40rem;
  flex: 1;
  min-width: 220px;
}

.team-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  min-height: var(--control-height);
  cursor: pointer;
}

.mode-banner {
  margin: 0 0 12px;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.4;
}

.mode-banner:empty { display: none; }

.mode-banner.admin {
  background: #eef3ff;
  color: #253a7d;
  border: 1px solid #d5e0ff;
}

.mode-banner.member {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.team-table-panel {
  padding: 0;
  overflow: hidden;
  position: relative;
}

.table-scroll-hint {
  display: none;
  font-size: 0.72rem;
  font-weight: 800;
  color: #7b879c;
  padding: 8px 14px 0;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.team-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 720px;
}

.team-table th,
.team-table td {
  text-align: left;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.team-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 800;
  background: #f8fafc;
  position: sticky;
  top: 0;
}

.team-table tbody tr:last-child td { border-bottom: none; }

.team-table tbody tr:hover td { background: #fafbfd; }

.team-table tr.inactive td { color: var(--muted); }

.team-table tr.inactive {
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 8px,
    rgba(148, 163, 184, 0.05) 8px,
    rgba(148, 163, 184, 0.05) 16px
  );
}

.member-cell {
  display: grid;
  gap: 2px;
  min-width: 160px;
}

.member-cell strong {
  font-weight: 800;
  letter-spacing: -0.02em;
}

.member-cell span {
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-word;
}

.mono { font-variant-numeric: tabular-nums; font-size: 0.85rem; }

.empty { color: #94a3b8; }

.empty-row {
  text-align: center;
  color: var(--muted);
  padding: 32px 16px !important;
  font-weight: 600;
}

.role-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  white-space: nowrap;
}

.role-pill {
  background: var(--surface-2);
  color: #475569;
}

.role-pill.admin {
  background: #eef3ff;
  color: #253a7d;
}

.status-pill.on {
  background: rgba(29, 158, 117, 0.12);
  color: #0f766e;
}

.status-pill.off {
  background: rgba(148, 163, 184, 0.18);
  color: #64748b;
}

.col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right !important;
}

.readonly-tag {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #94a3b8;
}

.edit-panel { margin-top: 14px; }

.edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}

.edit-grid label {
  display: block;
  font-size: 0.8rem;
  margin: 12px 0 6px;
  color: var(--muted);
  font-weight: 700;
}

.edit-grid .input,
.edit-grid select {
  width: 100%;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  grid-column: 1 / -1;
}

.btn-row .btn { width: auto; }

/* ——— Responsive ——— */

@media (max-width: 1100px) {
  .stats-grid,
  .dashboard-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-grid { grid-template-columns: 1fr; }
}

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

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(var(--sidebar-width), 88vw);
    height: 100vh;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
  }

  .sidebar.open { transform: translateX(0); }

  .mobile-nav-toggle { display: grid; }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    z-index: 35;
  }

  .sidebar-backdrop.hidden { display: none !important; }

  .main-shell { padding: 16px 14px 44px; }

  .topbar-context { display: none; }

  .table-scroll-hint { display: block; }
}

@media (max-width: 640px) {
  .stats-grid,
  .dashboard-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat { padding: 14px; }

  .stat .v { font-size: 1.45rem; }

  .stat .s { font-size: 0.72rem; }

  .edit-grid { grid-template-columns: 1fr; }

  .team-toolbar { padding: 14px; }

  .team-hero-actions { width: 100%; }

  .team-hero-actions .btn { flex: 1; }

  .team-table { min-width: 620px; }

  .topbar { margin-bottom: 14px; }
}
