/* FMM.Systems Admin — shared shell, tokens, components (DESIGN-PROTOCOL v1.0) */

:root {
  /* Backgrounds */
  --bg-primary:   #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary:  #f1f5f9;
  --bg-input:     #e2e8f0;

  /* Text */
  --text-primary:   #1e293b;
  --text-secondary: #475569;
  --text-muted:     #64748b;

  /* Borders */
  --border:       #cbd5e1;
  --border-light: #94a3b8;

  /* Accent */
  --accent:       #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft:  rgba(59, 130, 246, 0.15);

  /* Semantic */
  --success:      #10b981;   --success-soft: rgba(16, 185, 129, 0.15);
  --warning:      #f59e0b;   --warning-soft: rgba(245, 158, 11, 0.15);
  --danger:       #ef4444;   --danger-soft:  rgba(239, 68, 68, 0.15);

  /* Geometry */
  --radius:    8px;
  --radius-lg: 12px;

  /* Shadows */
  --shadow:    0 1px 4px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

body.dark {
  --bg-primary:   #0f1419;
  --bg-secondary: #1a2028;
  --bg-tertiary:  #242d38;
  --bg-input:     #2a3441;
  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;
  --border:       #334155;
  --border-light: #475569;
  --shadow:    0 1px 4px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
}

/* Dark-flash prevention */
html.pre-dark, html.pre-dark body { background: #0f1419 !important; }

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

html { overflow-x: hidden; }

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

.screen { display: none; }
.screen.active { display: flex; flex-direction: column; flex: 1; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 40px;
  height: 60px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  flex-shrink: 0;
  width: 100%;
}
.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.topbar-separator { color: var(--text-primary); margin: 0 8px; }
.module-name { font-size: 0.9rem; font-weight: 400; letter-spacing: -0.01em; }
.user-name { font-size: 0.8rem; font-weight: 500; color: var(--text-secondary); }
.unsaved-indicator { color: var(--warning); font-size: 1rem; display: none; }

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; transition: color 0.15s; }
.brand:hover span { color: var(--accent); }
.brand-icon {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 8px;
  flex-shrink: 0;
}
.brand-icon svg { width: 18px; height: 18px; }
.brand span { font-size: 1rem; font-weight: 700; letter-spacing: -0.02em; }

.btn-icon-bordered {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: 1px solid var(--border); border-radius: 7px;
  color: var(--text-secondary); cursor: pointer; transition: all 0.15s;
}
.btn-icon-bordered:hover { border-color: var(--accent); color: var(--accent); }
.btn-icon-bordered svg { width: 16px; height: 16px; }

/* ---------- Breadcrumb ---------- */
.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 40px;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.breadcrumb-nav { display: flex; align-items: center; gap: 6px; }
.breadcrumb a { color: var(--accent); text-decoration: none; transition: color 0.15s; }
.breadcrumb a:hover { color: var(--accent-hover); }
.breadcrumb-separator { color: var(--text-muted); }
.breadcrumb-current { color: var(--text-primary); }
.breadcrumb-toolbar { display: flex; align-items: center; gap: 6px; margin-left: auto; }

/* ---------- Page body ---------- */
.page-body { flex: 1; padding: 32px 40px; max-width: 1100px; width: 100%; margin: 0 auto; }

/* ---------- Dashboard ---------- */
.dash-body { flex: 1; padding: 48px 40px; max-width: 960px; width: 100%; margin: 0 auto; }

.dash-greeting { margin-bottom: 32px; }
.dash-greeting h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.dash-greeting p  { font-size: 0.88rem; color: var(--text-muted); }

.section-label {
  font-size: 0.7rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 16px;
}

.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }

.app-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: flex; flex-direction: column; align-items: flex-start; gap: 14px;
  position: relative;
  color: var(--text-primary);
  box-shadow: var(--shadow);
}
.app-card:hover {
  border-color: var(--accent);
  background: var(--bg-tertiary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.app-card.disabled { opacity: 0.45; cursor: default; pointer-events: none; }

.app-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.app-icon svg { width: 22px; height: 22px; }
.icon-blue   { background: rgba(59,130,246,0.12);  color: #3b82f6; }
.icon-green  { background: rgba(16,185,129,0.12);  color: #10b981; }
.icon-orange { background: rgba(245,158,11,0.12);  color: #f59e0b; }
.icon-purple { background: rgba(139,92,246,0.12);  color: #8b5cf6; }
.icon-teal   { background: rgba(20,184,166,0.12);  color: #14b8a6; }

.app-name { font-size: 0.92rem; font-weight: 700; }
.app-desc { font-size: 0.76rem; color: var(--text-muted); line-height: 1.4; }

.card-badge {
  position: absolute; top: 12px; right: 12px;
  font-size: 0.62rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 2px 7px; border-radius: 4px;
}
.badge-live    { background: rgba(16,185,129,0.12);  color: #10b981; }
.badge-soon    { background: rgba(100,116,139,0.12); color: #64748b; }
.badge-upgrade { background: rgba(245,158,11,0.12);  color: #d97706; }

.card-arrow { position: absolute; bottom: 16px; right: 16px; color: var(--text-muted); opacity: 0; transition: opacity 0.2s; }
.app-card:hover .card-arrow { opacity: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  font-size: 0.83rem; font-weight: 600; font-family: inherit;
  border: none; border-radius: var(--radius);
  cursor: pointer; transition: all 0.15s;
  white-space: nowrap; line-height: 1;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-input); }

.btn.btn-sm { padding: 5px 10px; font-size: 0.75rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-danger  { background: rgba(239,68,68,0.1);  color: var(--danger);  border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover:not(:disabled)  { background: rgba(239,68,68,0.18); }
.btn-success { background: rgba(16,185,129,0.12); color: var(--success); border: 1px solid rgba(16,185,129,0.3); }

.btn-ghost {
  padding: 5px 12px; background: none;
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-secondary); font-family: inherit;
  font-size: 0.78rem; font-weight: 500;
  cursor: pointer; transition: all 0.2s;
  text-decoration: none; display: inline-flex; align-items: center; gap: 5px;
}
.btn-ghost:hover { background: var(--bg-tertiary); border-color: var(--accent); color: var(--accent); }
.btn-ghost.danger { color: var(--danger); }
.btn-ghost.danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.btn-icon { background: none; border: none; color: var(--text-muted); padding: 4px 6px;
  border-radius: var(--radius); font-size: 0.78rem; cursor: pointer; transition: all 0.15s; }
.btn-icon:hover { color: var(--text-primary); }

/* ---------- Forms ---------- */
.form-group { display: flex; flex-direction: column; gap: 5px; }

.form-label {
  font-size: 0.72rem; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.05em;
}

.form-input, .form-select, .form-textarea {
  width: 100%; padding: 9px 12px;
  font-family: inherit; font-size: 0.88rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-input:disabled, .form-select:disabled, .form-textarea:disabled { opacity: 0.6; cursor: not-allowed; }
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-muted); }

.modal-err { font-size: 0.78rem; color: var(--danger); display: none; }

.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.46);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }

.modal {
  width: 100%; max-width: 560px;
  max-height: 90vh; overflow: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.modal-head h2 { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }

.modal-close {
  width: 30px; height: 30px;
  border-radius: var(--radius); border: none;
  background: var(--bg-input); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); font-size: 1rem; line-height: 1;
  transition: all 0.15s;
}
.modal-close:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }

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

/* ---------- Tables ---------- */
.table-wrapper { overflow-x: auto; margin-bottom: 4px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table thead th {
  font-size: 0.68rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--border);
  text-align: left; white-space: nowrap;
}
.data-table tbody td {
  padding: 10px 12px 10px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg-tertiary); }

.info-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.info-table th {
  width: 160px; text-align: left;
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted);
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.info-table td { font-weight: 500; padding: 9px 0; border-bottom: 1px solid var(--border); }
.info-table tr:last-child th, .info-table tr:last-child td { border-bottom: none; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state-icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.4; }
.empty-state h3 { font-size: 1rem; font-weight: 700; color: var(--text-secondary); }
.empty-state p { font-size: 0.85rem; }
.table-empty { text-align: center; color: var(--text-muted); padding: 16px 10px !important; font-size: 0.82rem; }

/* ---------- Feedback ---------- */
.toast {
  position: fixed; bottom: 28px; right: 28px;
  background: var(--success); color: #fff;
  padding: 10px 18px; border-radius: var(--radius);
  font-size: 0.85rem; font-weight: 600;
  box-shadow: var(--shadow);
  transform: translateY(80px); opacity: 0;
  transition: all 0.3s ease;
  z-index: 9999; pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.err { background: var(--danger); }

.status-bar { padding: 10px 40px; font-size: 0.85rem; font-weight: 500; flex-shrink: 0; }
.status-error   { background: var(--danger-soft);  color: var(--danger); }
.status-success { background: var(--success-soft); color: var(--success); }
.status-info    { background: var(--accent-soft);  color: var(--accent); }

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-msg { font-size: 0.85rem; color: var(--text-muted); }

.badge {
  display: inline-flex; padding: 2px 8px; border-radius: 4px;
  font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.badge-success { background: rgba(16,185,129,0.12);  color: #10b981; }
.badge-warning { background: rgba(245,158,11,0.12);  color: #d97706; }
.badge-danger  { background: rgba(239,68,68,0.12);   color: #ef4444; }
.badge-info    { background: rgba(59,130,246,0.12);  color: #3b82f6; }
.badge-neutral { background: rgba(100,116,139,0.12); color: #64748b; }
body.dark .badge-warning { color: #fcd34d; }

.pill {
  padding: 5px 11px; font-size: 0.78rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-secondary); cursor: pointer; transition: all 0.15s;
  font-family: inherit;
}
.pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Content cards ---------- */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 0.7rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding-bottom: 10px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

/* ---------- Auth ---------- */
#auth-screen { min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}

.tab-bar { display: flex; background: var(--bg-tertiary); border-radius: 8px; padding: 3px; margin-bottom: 24px; gap: 3px; }
.tab-btn {
  flex: 1; padding: 7px 0; background: none; border: none; border-radius: 6px;
  font-family: inherit; font-size: 0.8rem; font-weight: 600;
  color: var(--text-muted); cursor: pointer; transition: all 0.15s;
}
.tab-btn.active { background: var(--bg-secondary); color: var(--text-primary); box-shadow: 0 1px 4px rgba(0,0,0,0.15); }

/* ---------- Loading overlay (hub) ---------- */
.loading-overlay {
  position: fixed; inset: 0; z-index: 99999;
  background: var(--bg-primary);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar     { padding: 0 16px; }
  .breadcrumb { padding: 6px 16px; }
  .status-bar { padding: 8px 16px; }
  .topbar-right .user-name { display: none; }
  .page-body  { padding: 24px 16px; }
  .dash-body  { padding: 32px 16px; }
}

@media (max-width: 600px) {
  .app-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
}
