/* ========== RESET & BASE ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  background: #F0F2F5;
  color: #1C1E21;
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}
a { color: #1877F2; text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; background: none; }

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #BCC0C4; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #8A8D91; }

/* ========== LOGIN PAGE (full-screen) ========== */
.login-page {
  position: fixed; inset: 0; z-index: 9999;
  background: #F0F2F5;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
}
.signin-wrapper {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  width: 100%; max-width: 396px; padding: 20px;
}
.signin-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.signin-logo .logo-icon {
  width: 48px; height: 48px; background: #1877F2; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 22px;
}
.signin-logo h1,
.signin-logo .logo-text { font-size: 28px; font-weight: 700; color: #1C1E21; }
.signin-card {
  background: #fff; border-radius: 12px; padding: 24px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1), 0 8px 16px rgba(0,0,0,0.1);
  width: 100%;
}
.signin-card h2 { font-size: 18px; font-weight: 600; text-align: center; margin-bottom: 20px; color: #1C1E21; }
.signin-card .btn-signin {
  width: 100%; padding: 12px; background: #1877F2; color: #fff;
  border-radius: 8px; font-size: 16px; font-weight: 600;
  transition: background 0.2s; margin-top: 4px; border: none;
}
.signin-card .btn-signin:hover { background: #166FE5; }
.signin-card .btn-signin:active { background: #1565D8; transform: scale(0.99); }
.signin-divider {
  display: flex; align-items: center; gap: 12px; margin: 16px 0;
  color: #8A8D91; font-size: 13px;
}
.signin-divider::before, .signin-divider::after {
  content: ''; flex: 1; height: 1px; background: #DDDFE2;
}
.signin-footer { margin-top: 20px; font-size: 12px; color: #8A8D91; text-align: center; }

/* ========== APP SHELL ========== */
.app-shell { display: flex; height: 100vh; }

/* ========== SIDEBAR ========== */
.sidebar {
  width: 240px; min-width: 240px; background: #fff;
  border-right: 1px solid #E4E6EB; display: flex; flex-direction: column;
  transition: width 0.2s, min-width 0.2s; z-index: 100;
}
.sidebar.collapsed { width: 64px; min-width: 64px; }
.sidebar.collapsed .sidebar-brand span,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-footer-info { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px 0; }
.sidebar.collapsed .nav-icon { margin-right: 0; }
.sidebar.collapsed .sidebar-footer { justify-content: center; padding: 12px 0; }
.sidebar.collapsed .nav-section-title { display: none; }

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px 12px; border-bottom: 1px solid #E4E6EB;
}
.sidebar-brand .brand-icon {
  width: 36px; height: 36px; min-width: 36px; background: #1877F2; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 16px;
}
.sidebar-brand span { font-size: 16px; font-weight: 700; color: #1C1E21; white-space: nowrap; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px; }
.nav-section { margin-bottom: 4px; }
.nav-section-title {
  font-size: 11px; font-weight: 600; color: #8A8D91;
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 8px 12px 4px; white-space: nowrap;
}

.nav-item {
  display: flex; align-items: center; padding: 8px 12px;
  border-radius: 8px; cursor: pointer; transition: background 0.15s;
  position: relative; white-space: nowrap; gap: 12px;
  text-decoration: none; color: inherit;
}
.nav-item:hover { background: #F0F2F5; text-decoration: none; }
.nav-item.active { background: #E7F3FF; }
.nav-item.active .nav-icon { color: #1877F2; }
.nav-item.active .nav-icon svg { stroke: #1877F2; }
.nav-item.active .nav-label { color: #1877F2; font-weight: 600; }

.nav-icon {
  width: 20px; height: 20px; min-width: 20px;
  display: flex; align-items: center; justify-content: center;
  color: #65676B;
}
.nav-label { font-size: 14px; color: #1C1E21; flex: 1; }

.sidebar-footer {
  padding: 12px 16px; border-top: 1px solid #E4E6EB;
  display: flex; align-items: center; gap: 10px;
  transition: background 0.15s;
}
.sidebar-footer:hover { background: #F0F2F5; }
.avatar-sm {
  width: 32px; height: 32px; min-width: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; font-weight: 600;
}
.sidebar-footer-info { overflow: hidden; }
.sidebar-footer-info .name { font-size: 13px; font-weight: 600; color: #1C1E21; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer-info .role { font-size: 11px; color: #8A8D91; }
.sidebar.collapsed .sidebar-footer-info { display: none; }

/* ========== MAIN WRAPPER ========== */
.main-wrapper {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}

/* ========== TOPBAR ========== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; background: #fff; border-bottom: 1px solid #E4E6EB;
  position: sticky; top: 0; z-index: 50; flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-left h1 { font-size: 20px; font-weight: 700; color: #1C1E21; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.btn-collapse-sidebar {
  width: 36px; height: 36px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; transition: background 0.15s;
  color: #65676B;
}
.btn-collapse-sidebar:hover { background: #F0F2F5; }

.topbar-search {
  display: flex; align-items: center; gap: 8px;
  background: #F0F2F5; border-radius: 20px; padding: 8px 16px; width: 280px;
}
.topbar-search svg { color: #8A8D91; min-width: 16px; }
.topbar-search input {
  border: none; background: transparent; outline: none; width: 100%; font-size: 14px; color: #1C1E21;
}
.topbar-search input::placeholder { color: #8A8D91; }

/* ========== MAIN CONTENT ========== */
.main-content { flex: 1; overflow-y: auto; overflow-x: hidden; }
.page-container { padding: 24px; max-width: 1200px; margin: 0 auto; }

/* ========== CARDS ========== */
.card {
  background: #fff; border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  transition: box-shadow 0.2s;
}
.card-padded { padding: 20px; }
.card-header {
  padding: 16px 20px; border-bottom: 1px solid #E4E6EB;
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h2 { font-size: 16px; font-weight: 600; }
.card-body { padding: 20px; }
.card-error { border: 1px solid #FEB2B2; }
.card-success { border: 1px solid #B7EBC6; }

/* ========== PORTAL CARD (Exercises, Agent pages) ========== */
.portal-page { display: grid; gap: 1.25rem; }
.portal-card {
  background: #fff; border: 1px solid #E4E6EB;
  border-radius: 12px; padding: 20px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.portal-card-error { border-color: #FEB2B2; color: #C53030; }
.portal-card-success { border-color: #B7EBC6; color: #1E8E3E; }
.portal-card-table { padding: 0; overflow: hidden; }

/* ========== PAGE HEADER ========== */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.page-header h1 { font-size: 22px; font-weight: 700; color: #1C1E21; }

/* ========== TYPOGRAPHY ========== */
.eyebrow {
  margin: 0 0 0.35rem; font-size: 11px; font-weight: 600;
  letter-spacing: 0.5px; text-transform: uppercase; color: #8A8D91;
}
.body-copy { color: #65676B; max-width: 58ch; }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; font-size: 14px; font-weight: 600;
  transition: all 0.15s; white-space: nowrap; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: #1877F2; color: #fff; }
.btn-primary:hover { background: #166FE5; color: #fff; }
.btn-primary:active { background: #1565D8; }
.btn-secondary { background: #E4E6EB; color: #1C1E21; }
.btn-secondary:hover { background: #D8DADF; color: #1C1E21; }
.btn-danger { background: #FA383E; color: #fff; }
.btn-danger:hover { background: #E5353B; }
.btn-outline { border: 1px solid #DDDFE2; color: #1C1E21; background: #fff; }
.btn-outline:hover { background: #F5F6F7; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 6px; }

.primary-action {
  border: 0; border-radius: 8px; background: #1877F2; color: #fff;
  padding: 8px 16px; font: inherit; font-weight: 600; transition: background 0.15s;
}
.primary-action:hover { background: #166FE5; }
.primary-action:disabled { opacity: 0.45; }

.primary-action-link {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; background: #1877F2; color: #fff;
  padding: 12px 16px; font-weight: 600; text-decoration: none;
  font-size: 16px; transition: background 0.15s; width: 100%;
}
.primary-action-link:hover { background: #166FE5; color: #fff; text-decoration: none; }

.secondary-action-link {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 1px solid #DDDFE2;
  padding: 6px 12px; text-decoration: none;
  font-size: 13px; font-weight: 600; color: #1877F2; white-space: nowrap;
  background: #fff; transition: background 0.15s;
}
.secondary-action-link:hover { background: #F5F6F7; text-decoration: none; }

.secondary-action-button {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 1px solid #DDDFE2; background: #fff;
  color: inherit; padding: 6px 12px; font: inherit;
  font-size: 13px; font-weight: 600; white-space: nowrap; transition: background 0.15s;
}
.secondary-action-button:hover { background: #F5F6F7; }

.page-actions { display: flex; align-items: center; gap: 8px; }

/* ========== TABLES ========== */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 12px 16px; font-size: 12px; font-weight: 600;
  color: #8A8D91; text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 1px solid #E4E6EB; white-space: nowrap;
}
.data-table td {
  padding: 12px 16px; border-bottom: 1px solid #F0F2F5; font-size: 14px;
  vertical-align: middle;
}
.data-table tbody tr { transition: background 0.1s; }
.data-table tbody tr:hover { background: #F5F7FA; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table-actions { width: 1%; white-space: nowrap; }

/* ========== TABLE (portal style — Exercises) ========== */
.portal-table { width: 100%; border-collapse: collapse; }
.portal-table th {
  text-align: left; padding: 12px 16px; font-size: 12px; font-weight: 600;
  color: #8A8D91; text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 1px solid #E4E6EB; white-space: nowrap;
}
.portal-table td {
  padding: 12px 16px; border-bottom: 1px solid #F0F2F5; font-size: 14px;
  vertical-align: middle;
}
.portal-table tbody tr { transition: background 0.1s; }
.portal-table tbody tr:hover { background: #F5F7FA; }
.actions-cell { width: 1%; }

/* ========== BADGES ========== */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-active { background: #E6F4EA; color: #1E8E3E; }
.badge-inactive { background: #FFF3E0; color: #E65100; }
.badge-locked { background: #FDECEA; color: #D32F2F; }
.badge-pending { background: #E8F0FE; color: #1A73E8; }
.badge-info { background: #E8F0FE; color: #1877F2; }
.badge-neutral { background: #F0F2F5; color: #65676B; }

/* ========== TABLE PAGINATION ========== */
.table-pagination {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; padding: 16px 20px; border-top: 1px solid #E4E6EB;
}
.pagination-info { font-size: 13px; color: #8A8D91; }

/* ========== PAGER (portal style — Exercises) ========== */
.pager {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; padding: 16px 20px; border-top: 1px solid #E4E6EB;
}
.pager span { font-size: 13px; color: #8A8D91; }
.pager-button {
  border: 1px solid #DDDFE2; background: #fff; color: #1C1E21;
  border-radius: 8px; padding: 6px 12px; font: inherit; font-weight: 600;
  transition: background 0.15s;
}
.pager-button:hover { background: #F5F6F7; }
.pager-button:disabled { opacity: 0.45; }

/* ========== TABS ========== */
.portal-tabs {
  display: flex; gap: 4px; border-bottom: 1px solid #E4E6EB;
  padding: 0 4px; margin-bottom: 20px;
}
.tab-chip {
  padding: 12px 16px; font-size: 14px; font-weight: 600; color: #65676B;
  cursor: pointer; border-bottom: 3px solid transparent; transition: all 0.15s;
  text-decoration: none; display: inline-flex; align-items: center;
}
.tab-chip:hover { color: #1877F2; background: #F0F2F5; border-radius: 8px 8px 0 0; text-decoration: none; }
.tab-chip-link { }
.tab-chip-active { color: #1877F2; border-bottom-color: #1877F2; }
.tab-chip-active:hover { color: #1877F2; }

/* ========== STAT CARDS ========== */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: #fff; border-radius: 12px; padding: 20px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1); display: flex; align-items: flex-start; gap: 16px;
  transition: box-shadow 0.2s;
}
.stat-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px; display: flex;
  align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0;
}
.stat-icon.blue { background: #E7F3FF; color: #1877F2; }
.stat-icon.green { background: #E6F4EA; color: #42B72A; }
.stat-icon.amber { background: #FFF3E0; color: #E65100; }
.stat-icon.red { background: #FDECEA; color: #E41E3F; }
.stat-info { flex: 1; }
.stat-value { font-size: 28px; font-weight: 700; color: #1C1E21; line-height: 1.2; }
.stat-label { font-size: 13px; color: #8A8D91; margin-top: 2px; }

/* ========== OVERVIEW GRID ========== */
.overview-grid {
  display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 16px;
}
.overview-counters {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px;
}
.metric-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; color: #8A8D91;
}
.summary-list { display: grid; gap: 0.85rem; margin: 1rem 0 0; }
.summary-list div { display: grid; gap: 0.2rem; }
.summary-list dt {
  font-size: 11px; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; color: #8A8D91;
}
.summary-list dd { margin: 0; }

/* ========== AGENT CONFIG GRID ========== */
.agent-config-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem;
}

/* ========== CHAT ========== */
.chat-thread { display: grid; gap: 0.9rem; }
.chat-bubble {
  display: grid; gap: 0.65rem; max-width: min(78ch, 100%);
  padding: 1rem 1.1rem; border-radius: 12px; border: 1px solid #F0F2F5;
}
.chat-bubble p { margin: 0; white-space: pre-wrap; }
.chat-bubble-incoming { justify-self: start; background: #F5F7FA; }
.chat-bubble-outgoing { justify-self: end; background: #1877F2; color: #fff; }
.chat-meta { display: flex; flex-wrap: wrap; gap: 0.6rem; font-size: 12px; color: #8A8D91; }
.chat-bubble-outgoing .chat-meta { color: rgba(255, 255, 255, 0.75); }

/* ========== EMPTY STATE ========== */
.empty-state {
  display: grid; place-items: center; min-height: 180px;
  text-align: center; color: #65676B;
}

/* ========== FORMS ========== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: #65676B; margin-bottom: 6px; }
.form-input {
  width: 100%; padding: 10px 12px; border: 1px solid #DDDFE2; border-radius: 8px;
  font-size: 14px; transition: all 0.2s; background: #fff;
}
.form-input:focus { outline: none; border-color: #1877F2; box-shadow: 0 0 0 2px rgba(24,119,242,0.2); }

.form-field { display: grid; gap: 0.4rem; }
.form-field label { font-size: 13px; font-weight: 600; color: #65676B; }
.text-input {
  width: 100%; border: 1px solid #DDDFE2; border-radius: 8px;
  background: #fff; padding: 10px 12px; font: inherit; color: inherit;
  transition: all 0.2s;
}
.text-input:focus { border-color: #1877F2; outline: none; box-shadow: 0 0 0 2px rgba(24,119,242,0.2); }
.text-input-tall { min-height: 200px; resize: vertical; }

/* ========== MODAL (Exercises page) ========== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 40;
  animation: fadeInOverlay 0.2s ease;
}
@keyframes fadeInOverlay { from { opacity: 0; } to { opacity: 1; } }
.modal-shell {
  position: fixed; inset: 0;
  display: grid; place-items: center; padding: 1.5rem; z-index: 50;
}
.modal-card {
  width: min(520px, calc(100vw - 2rem));
  background: #fff; border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-header {
  display: flex; justify-content: space-between; gap: 1rem; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid #E4E6EB;
}
.modal-close {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #65676B; border: 0; background: transparent; font: inherit;
  transition: background 0.15s;
}
.modal-close:hover { background: #F0F2F5; }
.modal-form-grid { display: grid; gap: 1rem; padding: 20px; }
.modal-actions { display: flex; justify-content: end; gap: 0.75rem; padding: 16px 20px; border-top: 1px solid #E4E6EB; }

/* ========== VALIDATION ========== */
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid #e50000; }
.validation-message { color: #e50000; font-size: 12px; }

/* ========== BLAZOR ERROR ========== */
.blazor-error-boundary {
  background: #FDECEA; color: #C53030; padding: 1rem; border-radius: 12px;
}
.blazor-error-boundary::after { content: "An error has occurred."; }

/* ========== UTILITY ========== */
.hidden { display: none !important; }
.text-muted { color: #8A8D91; }

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: -240px; z-index: 1000; height: 100vh;
    transition: left 0.3s;
  }
  .sidebar.open { left: 0; }
  .sidebar.collapsed { left: -64px; }
  .topbar-search { width: 200px; }
  .page-container { padding: 16px; }

  .page-header { flex-direction: column; align-items: start; }
  .overview-grid, .overview-counters, .agent-config-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }

  .portal-table, .portal-table thead, .portal-table tbody,
  .portal-table tr, .portal-table th, .portal-table td { display: block; }
  .portal-table thead { display: none; }
  .portal-table tr { padding: 1rem; border-bottom: 1px solid #F0F2F5; }
  .portal-table td { padding: 0.25rem 0; border: 0; }
  .actions-cell { margin-top: 0.75rem; }

  .pager { align-items: stretch; flex-direction: column; }
  .chat-bubble { max-width: 100%; }
  .chat-meta { flex-direction: column; gap: 0.25rem; }
  .modal-header, .modal-actions { align-items: stretch; flex-direction: column; }
}
