/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:       #367DA2;
  --brand-dark:  #295f7a;
  --brand-light: #e8f4fa;
  --text:        #1a2332;
  --text-muted:  #6b7a8d;
  --border:      #dde3ea;
  --bg:          #f4f6f9;
  --card-bg:     #ffffff;
  --sidebar-w:   230px;
  --topbar-h:    56px;
  --success:     #28a745;
  --warning:     #f59e0b;
  --danger:      #dc3545;
  --radius:      8px;
  --shadow:      0 1px 4px rgba(0,0,0,.08), 0 2px 12px rgba(0,0,0,.05);
}

html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; font-size: 14px; }

/* ===== LOGIN PAGE ===== */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #1a3a52 0%, #367DA2 100%); }

.login-wrapper { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; max-width: 400px; padding: 20px; }

.login-card { background: var(--card-bg); border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,.2); padding: 40px 36px; width: 100%; }

.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo-img { width: 200px; height: auto; display: block; margin: 0 auto 10px; }
.login-logo p { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-footer { font-size: 11px; color: rgba(255,255,255,.5); text-align: center; }

/* ===== APP LAYOUT ===== */
.app-page { display: flex; height: 100vh; overflow: hidden; }

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  background: #1a2332;
  color: #c8d3e0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width .2s;
  overflow: hidden;
  z-index: 100;
}
.sidebar-logo {
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-logo-wrap {
  background: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  display: flex; align-items: center; justify-content: center;
}
.sidebar-logo-img {
  height: 30px; width: auto; display: block;
}
.sidebar-nav { flex: 1; padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 6px;
  color: #a0aec0; font-size: 13.5px; font-weight: 500;
  transition: background .15s, color .15s; white-space: nowrap;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--brand); color: #fff; }

.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 12px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.user-info { flex: 1; overflow: hidden; }
.user-name { display: block; font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; font-size: 11px; color: #718096; }
.logout-btn {
  background: none; border: none; color: #718096; padding: 4px;
  border-radius: 4px; transition: color .15s;
}
.logout-btn:hover { color: #fc8181; }

/* MAIN CONTENT */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.topbar {
  height: var(--topbar-h); background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px; flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.topbar-title { font-size: 16px; font-weight: 600; color: var(--text); }
.sidebar-toggle {
  background: none; border: none; color: var(--text-muted);
  padding: 4px; border-radius: 4px;
  display: none;
}

/* PANELS */
.panel { display: none; flex: 1; overflow-y: auto; }
.panel.active { display: flex; flex-direction: column; }
.panel-inner { padding: 20px; display: flex; flex-direction: column; gap: 20px; max-width: 1400px; }

/* ===== CARDS ===== */
.card { background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); }
.card-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--border); }
.card-header h3 { font-size: 15px; font-weight: 700; }
.card-subtitle { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }
.card-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

/* ===== FORM ===== */
.eval-form { padding: 20px 24px; }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.span-2 { grid-column: span 2; }

.field-group { display: flex; flex-direction: column; gap: 5px; }
.field-group label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field-group input, .field-group select, .field-group textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.field-group input:focus, .field-group select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(54,125,162,.15);
}
.required { color: #e53e3e; }

/* ===== TYPE TABS ===== */
.type-tabs {
  display: flex; gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.type-tab {
  display: flex; align-items: center; gap: 7px;
  padding: 10px 22px;
  background: none; border: none;
  font-size: 13.5px; font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
  cursor: pointer;
}
.type-tab:hover { color: var(--brand); }
.type-tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.form-section { margin-bottom: 4px; }

.form-actions { margin-top: 20px; display: flex; gap: 10px; }

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--brand); color: #fff; border: none;
  padding: 9px 18px; border-radius: 6px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 7px;
  transition: background .15s;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { background: #a0c4d8; cursor: not-allowed; }

.btn-secondary {
  background: #fff; color: var(--brand); border: 1.5px solid var(--brand);
  padding: 8px 16px; border-radius: 6px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 7px;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--brand-light); }

.btn-full { width: 100%; justify-content: center; padding: 11px; }

/* ===== AGENT STATUS ===== */
.agent-status {
  background: var(--brand-light);
  border: 1.5px solid var(--brand);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.status-spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid rgba(54,125,162,.25);
  border-top-color: var(--brand);
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-text strong { display: block; font-size: 14px; color: var(--brand-dark); }
.status-text span { font-size: 12.5px; color: var(--text-muted); }

/* ===== CRITERIA BAR ===== */
.criteria-bar {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 0 4px;
}
.criteria-bar:empty { display: none; }
.criterion-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
  border: 1.5px solid transparent;
}
.criterion-chip .chip-rank {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 50%;
  font-size: 10px; font-weight: 700; flex-shrink: 0;
}
.criterion-chip.rank-0 { background: #fff0f0; border-color: #dc3545; color: #842029; }
.criterion-chip.rank-0 .chip-rank { background: #dc3545; color: #fff; }
.criterion-chip.rank-1 { background: #e8f4fa; border-color: #367DA2; color: #1d5570; }
.criterion-chip.rank-1 .chip-rank { background: #367DA2; color: #fff; }
.criterion-chip.rank-2 { background: #e8f5ee; border-color: #28a745; color: #1a6630; }
.criterion-chip.rank-2 .chip-rank { background: #28a745; color: #fff; }
.criterion-chip.rank-3 { background: #fff8e8; border-color: #f59e0b; color: #7d5200; }
.criterion-chip.rank-3 .chip-rank { background: #f59e0b; color: #fff; }
.criterion-chip.rank-4 { background: #f3f4f6; border-color: #9ca3af; color: #4b5563; }
.criterion-chip.rank-4 .chip-rank { background: #9ca3af; color: #fff; }
.chip-value { font-weight: 400; opacity: .85; }

/* ===== SURSE DE DATE ===== */
.sources-section {
  margin: 16px 0 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.sources-toggle {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 11px 16px;
  background: #f8fafc; border: none;
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  cursor: pointer; text-align: left;
  transition: background .15s;
}
.sources-toggle:hover { background: var(--brand-light); color: var(--brand); }
.sources-count {
  margin-left: auto;
  font-size: 11.5px; font-weight: 500;
  background: var(--brand-light); color: var(--brand);
  padding: 2px 9px; border-radius: 10px;
}
.sources-chevron { transition: transform .2s; flex-shrink: 0; }
.sources-chevron.open { transform: rotate(180deg); }

.sources-body { padding: 12px 16px 14px; border-top: 1px solid var(--border); background: #fff; }
.sources-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }

.source-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  background: #fafbfc;
}
.source-row input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--brand); flex-shrink: 0; cursor: pointer; }
.source-label { font-size: 13px; font-weight: 600; color: var(--text); min-width: 110px; }
.source-url { flex: 1; font-size: 12.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-default-badge { font-size: 10.5px; background: #e0f0f8; color: var(--brand); padding: 1px 7px; border-radius: 8px; font-weight: 600; flex-shrink: 0; }
.source-delete {
  background: none; border: none; color: #cbd5e0; font-size: 16px; line-height: 1;
  cursor: pointer; padding: 0 2px; flex-shrink: 0;
  transition: color .15s;
}
.source-delete:hover { color: var(--danger); }

.source-add-row { display: flex; gap: 8px; align-items: center; }
.source-input-label {
  width: 130px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; font-size: 13px; color: var(--text);
}
.source-input-label:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(54,125,162,.12); }
.source-input-url {
  flex: 1;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; font-size: 13px; color: var(--text);
}
.source-input-url:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(54,125,162,.12); }
.btn-add-source {
  display: flex; align-items: center; gap: 5px;
  background: var(--brand); color: #fff; border: none;
  padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 600;
  white-space: nowrap; transition: background .15s;
}
.btn-add-source:hover { background: var(--brand-dark); }

/* ===== RESULTS ===== */
.results-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.results-header h3 { font-size: 15px; font-weight: 700; }

/* ===== TABLES ===== */
.table-wrapper { overflow-x: auto; }
.comparables-table, .history-table, .admin-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.comparables-table th, .history-table th, .admin-table th {
  background: var(--brand); color: #fff;
  padding: 10px 12px; text-align: center;
  font-weight: 600; font-size: 12.5px; white-space: nowrap;
}
.comparables-table td, .history-table td, .admin-table td {
  padding: 9px 12px; text-align: center;
  border-bottom: 1px solid var(--border); vertical-align: middle;
}
.comparables-table tbody tr:nth-child(even) td,
.history-table tbody tr:nth-child(even) td,
.admin-table tbody tr:nth-child(even) td { background: #f9fbfd; }
.comparables-table tbody tr:hover td,
.history-table tbody tr:hover td,
.admin-table tbody tr:hover td { background: var(--brand-light); }

.comparables-table td.link-cell a { color: var(--brand); font-size: 12px; word-break: break-all; }
.empty-row { color: var(--text-muted); padding: 24px !important; font-style: italic; }

/* STATUS BADGES */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  font-size: 11.5px; font-weight: 600;
}
.badge-running { background: #fff3cd; color: #856404; }
.badge-done    { background: #d1e7dd; color: #0a6640; }
.badge-error   { background: #f8d7da; color: #842029; }
.badge-pending { background: #e2e8f0; color: #4a5568; }
.badge-active  { background: #d1e7dd; color: #0a6640; }
.badge-inactive{ background: #f8d7da; color: #842029; }
.badge-admin   { background: #e0d7ff; color: #5a3e9e; }
.badge-user    { background: #e2e8f0; color: #4a5568; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal {
  background: #fff; border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 420px; max-width: 95vw;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 22px;
  color: var(--text-muted); line-height: 1;
}
.modal-close:hover { color: var(--danger); }
.modal-form { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 4px; }

/* ===== ERROR MSG ===== */
.error-msg { background: #fff5f5; border: 1px solid #fc8181; color: #c53030; padding: 10px 14px; border-radius: 6px; font-size: 13px; }

/* ===== ACTION LINKS IN TABLE ===== */
.action-link { background: none; border: none; color: var(--brand); font-size: 12.5px; font-weight: 600; padding: 3px 6px; border-radius: 4px; }
.action-link:hover { background: var(--brand-light); }
.action-link.danger { color: var(--danger); }
.action-link.danger:hover { background: #fff5f5; }

/* ===== NR. COMPARABILE ===== */
.count-row {
  display: flex; align-items: center; gap: 12px;
  margin: 16px 0 4px;
}
.count-row label {
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  white-space: nowrap;
}
.count-row input {
  width: 80px;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; font-size: 14px; color: var(--text);
  background: #fff; text-align: center;
  transition: border-color .15s, box-shadow .15s;
}
.count-row input:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(54,125,162,.15);
}

/* ===== SETĂRI CRITERII ===== */
.limits-body { padding: 10px 16px 14px; }
.limits-grid { display: flex; flex-direction: column; gap: 6px; }
.limit-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  background: #fafbfc;
  flex-wrap: wrap;
}
.limit-rank {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  font-size: 11px; font-weight: 700; flex-shrink: 0; color: #fff;
}
.limit-rank.rank-2 { background: #28a745; }
.limit-rank.rank-3 { background: #f59e0b; }
.limit-rank.rank-4 { background: #9ca3af; }
.limit-label {
  font-size: 13px; font-weight: 600; color: var(--text);
  flex: 1; min-width: 110px;
}
.limit-op { font-size: 14px; font-weight: 700; color: var(--text-muted); }
.limit-input {
  width: 64px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; font-size: 13px; color: var(--text);
  text-align: center; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.limit-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(54,125,162,.12); }
.limit-unit { font-size: 12.5px; color: var(--text-muted); }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .span-2 { grid-column: span 2; }
}
@media (max-width: 640px) {
  .sidebar { position: absolute; left: -100%; }
  .sidebar.open { left: 0; }
  .sidebar-toggle { display: flex; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
}
