/* ============================================================
   PrimeTeam Auth — Mission Control
   Utilitarian instrument-panel aesthetic
   ============================================================ */

/* --- Fonts ------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- Tokens ------------------------------------------------ */
:root {
  /* Navy chrome */
  --hull:        #0b1120;
  --hull-light:  #131d33;
  --hull-mid:    #1a2744;
  --hull-line:   #243352;
  --hull-text:   #8b9ec2;

  /* Content surface */
  --surface:     #f4f6fa;
  --surface-alt: #ffffff;
  --surface-border: #e2e6ee;
  --text:        #1a1e2c;
  --text-mid:    #5a6178;
  --text-light:  #8b90a0;

  /* Status */
  --ok:          #12b76a;
  --ok-bg:       #ecfdf3;
  --ok-border:   #a6f4c5;
  --warn:        #f79009;
  --warn-bg:     #fffaeb;
  --warn-border: #fedf89;
  --err:         #f04438;
  --err-bg:      #fef3f2;
  --err-border:  #fecdca;
  --neutral:     #98a2b3;
  --neutral-bg:  #f2f4f7;

  /* Accent */
  --accent:      #4e7cff;
  --accent-hover:#3b65e0;
  --accent-bg:   #eef3ff;

  /* Layout */
  --sidebar-w:   240px;
  --header-h:    56px;
  --radius:      6px;
  --radius-lg:   10px;

  /* Transitions */
  --ease:        cubic-bezier(.4,0,.2,1);
}

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

html { font-size: 14px; -webkit-font-smoothing: antialiased; }

body {
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  background: var(--surface);
  line-height: 1.5;
}

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

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  border: none;
  outline: none;
}

/* --- Layout Shell ------------------------------------------ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar ----------------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--hull);
  color: var(--hull-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform .25s var(--ease);
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--hull-line);
}

.sidebar-brand h1 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.02em;
  line-height: 1.2;
}

.sidebar-brand span {
  display: block;
  font-size: .7rem;
  font-weight: 500;
  color: var(--hull-text);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-top: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.sidebar-nav .nav-section {
  padding: 8px 16px 4px;
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--hull-text);
  opacity: .6;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: var(--hull-text);
  font-size: .9rem;
  font-weight: 400;
  border-radius: 0;
  text-decoration: none;
  transition: background .15s var(--ease), color .15s var(--ease);
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
  background: var(--hull-light);
  color: #fff;
  text-decoration: none;
}

.sidebar-nav a.active {
  background: var(--hull-light);
  color: #fff;
  border-left-color: var(--accent);
  font-weight: 500;
}

.sidebar-nav a svg {
  width: 18px;
  height: 18px;
  opacity: .7;
  flex-shrink: 0;
}

.sidebar-nav a.active svg { opacity: 1; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--hull-line);
  font-size: .8rem;
}

.sidebar-footer .user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-footer .user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--hull-mid);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: .75rem;
  color: var(--accent);
  flex-shrink: 0;
}

.sidebar-footer .user-name {
  color: #fff;
  font-weight: 500;
  font-size: .85rem;
}

.sidebar-footer .user-role {
  color: var(--hull-text);
  font-size: .7rem;
  text-transform: capitalize;
}

.sidebar-footer a.logout {
  display: block;
  margin-top: 8px;
  color: var(--hull-text);
  font-size: .75rem;
}

/* --- Main Content ------------------------------------------ */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

.page-header {
  background: var(--surface-alt);
  border-bottom: 1px solid var(--surface-border);
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--text);
}

.page-header .breadcrumb {
  font-size: .8rem;
  color: var(--text-light);
  margin-top: 2px;
}

.page-header .breadcrumb a { color: var(--text-mid); }

.page-content {
  padding: 24px 32px 48px;
}

/* --- Stat Cards -------------------------------------------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}

.stat-card .stat-label {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-light);
  margin-bottom: 6px;
}

.stat-card .stat-value {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -.03em;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
}

.stat-card .stat-sub {
  font-size: .75rem;
  color: var(--text-mid);
  margin-top: 4px;
}

/* --- Table ------------------------------------------------- */
.table-wrap {
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-toolbar {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--surface-border);
}

.table-toolbar h3 {
  font-size: .95rem;
  font-weight: 600;
}

.search-box {
  position: relative;
}

.search-box input {
  width: 260px;
  padding: 7px 12px 7px 34px;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: .85rem;
  transition: border-color .15s var(--ease);
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.search-box svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-light);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-light);
  background: var(--surface);
  border-bottom: 1px solid var(--surface-border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 16px;
  font-size: .85rem;
  border-bottom: 1px solid var(--surface-border);
  vertical-align: middle;
}

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

tbody tr:hover { background: #f8f9fd; }

.client-name {
  font-weight: 600;
  color: var(--text);
}

.client-name a {
  color: var(--text);
  text-decoration: none;
}

.client-name a:hover {
  color: var(--accent);
  text-decoration: none;
}

.mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: .8rem;
}

.text-muted { color: var(--text-light); font-size: .8rem; }
.text-mid   { color: var(--text-mid); }

/* --- Status Dots ------------------------------------------- */
.status-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}

.status-dot {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.status-dot .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--neutral);
  flex-shrink: 0;
}

.status-dot .dot.connected    { background: var(--ok); }
.status-dot .dot.pending      { background: var(--warn); }
.status-dot .dot.error        { background: var(--err); }
.status-dot .dot.disconnected { background: var(--neutral); }

.status-dot .region-label {
  font-size: .65rem;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  color: var(--text-light);
  letter-spacing: .03em;
}

.status-dot .dot.connected + .region-label { color: var(--ok); }

/* tooltip on hover */
.status-dot[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--hull);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: .7rem;
  font-weight: 400;
  white-space: nowrap;
  z-index: 200;
  pointer-events: none;
}

/* Platform group labels */
.platform-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.platform-label {
  font-size: .6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-light);
  margin-bottom: 1px;
}

/* --- Badges ------------------------------------------------ */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .02em;
}

.badge-ok      { background: var(--ok-bg); color: #027a48; border: 1px solid var(--ok-border); }
.badge-warn    { background: var(--warn-bg); color: #b54708; border: 1px solid var(--warn-border); }
.badge-err     { background: var(--err-bg); color: #b42318; border: 1px solid var(--err-border); }
.badge-neutral { background: var(--neutral-bg); color: #475467; border: 1px solid #d0d5dd; }

/* --- Buttons ----------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: .85rem;
  cursor: pointer;
  transition: all .15s var(--ease);
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  text-decoration: none;
  color: #fff;
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--surface-border);
}

.btn-secondary:hover { background: var(--surface); }

.btn-ghost {
  background: transparent;
  color: var(--text-mid);
  padding: 6px 10px;
}

.btn-ghost:hover { background: var(--surface); color: var(--text); }

.btn-sm { padding: 5px 10px; font-size: .8rem; }

.btn-danger { background: var(--err); color: #fff; }
.btn-danger:hover { background: #d92d20; }

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

.form-group label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-mid);
  margin-bottom: 5px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  font-size: .9rem;
  transition: border-color .15s var(--ease);
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235a6178' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.checkbox-group {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: .85rem;
}

.checkbox-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.checkbox-item.connected {
  opacity: .6;
}

.checkbox-item.connected::after {
  content: "Connected";
  font-size: .65rem;
  font-weight: 600;
  color: var(--ok);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* --- Cards ------------------------------------------------- */
.card {
  background: var(--surface-alt);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
}

.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 {
  font-size: .95rem;
  font-weight: 600;
}

.card-body { padding: 20px; }

/* --- Modal ------------------------------------------------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 17, 32, .55);
  backdrop-filter: blur(4px);
  z-index: 500;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--surface-alt);
  border-radius: var(--radius-lg);
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px rgba(0,0,0,.2);
  animation: modal-in .2s var(--ease);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  padding: 20px 24px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--surface-border);
}

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  cursor: pointer;
  color: var(--text-light);
  padding: 4px;
  border-radius: 4px;
}

.modal-close:hover { background: var(--surface); color: var(--text); }

.modal-body { padding: 20px 24px; }

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--surface-border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* --- Link Result Box --------------------------------------- */
.link-result {
  display: none;
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--accent-bg);
  border: 1px solid #c7d7fe;
  border-radius: var(--radius);
}

.link-result.active { display: block; }

.link-result .link-url {
  font-family: 'JetBrains Mono', monospace;
  font-size: .8rem;
  word-break: break-all;
  color: var(--accent);
  margin-bottom: 10px;
  line-height: 1.6;
}

.link-result .link-meta {
  font-size: .75rem;
  color: var(--text-mid);
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s var(--ease);
}

.copy-btn:hover { background: var(--accent-hover); }
.copy-btn.copied { background: var(--ok); }

/* --- Connection Detail List -------------------------------- */
.connection-list {
  list-style: none;
}

.connection-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--surface-border);
}

.connection-item:last-child { border-bottom: none; }

.connection-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .65rem;
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  flex-shrink: 0;
}

.connection-icon.amazon  { background: #fff3e0; color: #e65100; }
.connection-icon.tiktok  { background: #f3e5f5; color: #7b1fa2; }
.connection-icon.ads     { background: #e3f2fd; color: #1565c0; }

.connection-info { flex: 1; }

.connection-info .conn-title {
  font-weight: 600;
  font-size: .85rem;
  color: var(--text);
}

.connection-info .conn-meta {
  font-size: .75rem;
  color: var(--text-light);
  margin-top: 1px;
}

/* --- Login ------------------------------------------------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--hull);
  position: relative;
  overflow: hidden;
}

/* subtle grid pattern */
.login-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--hull-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--hull-line) 1px, transparent 1px);
  background-size: 60px 60px;
  opacity: .15;
}

.login-card {
  position: relative;
  z-index: 1;
  background: var(--surface-alt);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 380px;
  max-width: 92vw;
  box-shadow: 0 32px 64px rgba(0,0,0,.35);
}

.login-card .brand {
  text-align: center;
  margin-bottom: 28px;
}

.login-card .brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}

.login-card .brand p {
  font-size: .75rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 500;
  margin-top: 4px;
}

.login-card .form-group { margin-bottom: 14px; }

.login-card .btn-primary {
  width: 100%;
  justify-content: center;
  padding: 10px;
  margin-top: 6px;
}

.login-error {
  padding: 10px 12px;
  background: var(--err-bg);
  border: 1px solid var(--err-border);
  border-radius: var(--radius);
  color: #b42318;
  font-size: .8rem;
  margin-bottom: 14px;
}

/* --- Tabs -------------------------------------------------- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--surface-border);
  margin-bottom: 20px;
  gap: 0;
}

.tab {
  padding: 10px 20px;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-mid);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all .15s var(--ease);
  background: none;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* --- Empty State ------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-light);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  opacity: .4;
}

.empty-state p {
  font-size: .9rem;
}

/* --- Timeline ---------------------------------------------- */
.timeline-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--surface-border);
}

.timeline-item:last-child { border-bottom: none; }

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}

.timeline-dot.ok   { background: var(--ok); }
.timeline-dot.warn { background: var(--warn); }
.timeline-dot.err  { background: var(--err); }

.timeline-content .tl-title {
  font-weight: 500;
  font-size: .85rem;
}

.timeline-content .tl-time {
  font-size: .75rem;
  color: var(--text-light);
  font-family: 'JetBrains Mono', monospace;
  margin-top: 2px;
}

/* --- Flash Messages ---------------------------------------- */
.flash {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: .85rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.flash-success { background: var(--ok-bg); color: #027a48; border: 1px solid var(--ok-border); }
.flash-error   { background: var(--err-bg); color: #b42318; border: 1px solid var(--err-border); }
.flash-info    { background: var(--accent-bg); color: #2d4fa0; border: 1px solid #c7d7fe; }

/* --- Responsive -------------------------------------------- */
.menu-toggle {
  display: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

  .main {
    margin-left: 0;
  }

  .menu-toggle {
    display: block;
  }

  .page-header {
    padding: 14px 16px;
  }

  .page-content {
    padding: 16px;
  }

  .search-box input {
    width: 180px;
  }

  .stat-row {
    grid-template-columns: repeat(2, 1fr);
  }

  table {
    font-size: .8rem;
  }

  thead th, tbody td {
    padding: 8px 10px;
  }
}

/* --- Utility ----------------------------------------------- */
.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8   { margin-top: 8px; }
.mt-16  { margin-top: 16px; }
.mt-24  { margin-top: 24px; }
.mb-8   { margin-bottom: 8px; }
.mb-16  { margin-bottom: 16px; }
.w-full { width: 100%; }
