/* ═══════════════════════════════════════════
   MBANC Middleware Dashboard
   ═══════════════════════════════════════════ */

/* Force the HTML `hidden` attribute to win over class-based display rules.
   Without this, .login-screen { display: flex } overrides [hidden]'s default
   display: none, so the login screen stayed visible after successful login. */
[hidden] { display: none !important; }

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-hover: #22263a;
  --bg-input: #141620;
  --border: #2a2e3e;
  --border-focus: #4f7df9;
  --text: #e4e6ee;
  --text-muted: #8b8fa3;
  --text-dim: #5e6278;
  --primary: #4f7df9;
  --primary-hover: #3d6ce6;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --info: #60a5fa;
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-w: 220px;
  --nav-h: 56px;
  --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ─── TYPOGRAPHY ─── */
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }

/* ═══════════ LOGIN SCREEN ═══════════ */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f1117 0%, #1a1d27 50%, #0f1117 100%);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 380px;
  max-width: 95vw;
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.logo-icon {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  margin-bottom: 0.75rem;
}

.logo-icon-sm {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 800;
  color: #fff;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* ─── FORMS ─── */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input, select, textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
  transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(79, 125, 249, 0.15);
}

.error-text {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 0.75rem;
  text-align: center;
}

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-success {
  background: var(--success);
  color: #000;
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-dim);
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
}

.btn-full {
  width: 100%;
  margin-top: 0.5rem;
}

/* ═══════════ LAYOUT ═══════════ */
.top-nav {
  height: var(--nav-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.nav-title {
  font-weight: 700;
  font-size: 1rem;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-user {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.layout {
  display: flex;
  height: calc(100vh - var(--nav-h));
}

/* ─── SIDEBAR ─── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex-shrink: 0;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.15s;
}

.nav-link:hover {
  color: var(--text);
  background: var(--bg-card-hover);
}

.nav-link.active {
  color: var(--primary);
  background: rgba(79, 125, 249, 0.1);
}

.nav-link.admin-only.hidden {
  display: none;
}

/* ─── MAIN CONTENT ─── */
.content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

/* ═══════════ CARDS ═══════════ */
.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: border-color 0.2s;
}

.stat-card:hover {
  border-color: var(--text-dim);
}

.stat-card .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-card .sub {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

.stat-card.green .value { color: var(--success); }
.stat-card.blue .value { color: var(--info); }
.stat-card.yellow .value { color: var(--warning); }
.stat-card.red .value { color: var(--danger); }

/* ═══════════ TABLES ═══════════ */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.table-toolbar input, .table-toolbar select {
  max-width: 200px;
}

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

th {
  text-align: left;
  padding: 0.65rem 1rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-input);
}

td {
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

tr:hover td {
  background: var(--bg-card-hover);
}

/* ─── BADGES ─── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-green { background: rgba(52, 211, 153, 0.15); color: var(--success); }
.badge-blue { background: rgba(96, 165, 250, 0.15); color: var(--info); }
.badge-yellow { background: rgba(251, 191, 36, 0.15); color: var(--warning); }
.badge-red { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.badge-gray { background: rgba(139, 143, 163, 0.15); color: var(--text-muted); }

/* ═══════════ PIPELINE VIEW ═══════════ */
.pipeline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}

.pipeline-stage {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  text-align: center;
  transition: all 0.15s;
}

.pipeline-stage:hover {
  border-color: var(--primary);
}

.pipeline-stage .stage-name {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  line-height: 1.3;
}

.pipeline-stage .stage-count {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.pipeline-stage.active-stage {
  border-color: var(--primary);
  background: rgba(79, 125, 249, 0.05);
}

.pipeline-stage.won-stage {
  border-color: var(--success);
  background: rgba(52, 211, 153, 0.05);
}

.pipeline-stage.lost-stage {
  border-color: var(--danger);
  background: rgba(248, 113, 113, 0.05);
}

/* ═══════════ SYNC VIEW ═══════════ */
.sync-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.sync-panel h3 {
  margin-bottom: 0.75rem;
}

.sync-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}
.dot.green { background: var(--success); }
.dot.yellow { background: var(--warning); animation: pulse 1.5s infinite; }
.dot.red { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.sync-result {
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--bg-input);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

/* ═══════════ MODAL ═══════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 440px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h2 {
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* ═══════════ TOAST ═══════════ */
.toast-container {
  position: fixed;
  top: calc(var(--nav-h) + 12px);
  right: 12px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 1rem;
  font-size: 0.83rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  animation: slideIn 0.25s ease;
  max-width: 360px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--info); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ═══════════ SPINNER ═══════════ */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--text-muted);
  gap: 0.75rem;
}

/* ═══════════ RESPONSIVE ═══════════ */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .content { padding: 1rem; }
  .cards-row { grid-template-columns: repeat(2, 1fr); }
  .pipeline-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ─── UTILITIES ─── */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.8rem; }
.mono { font-family: var(--mono); }
