/* Tisoro Assistants — Unified Console */

* { box-sizing: border-box; }

:root {
  --tisoro-red: #B11E2A;
  --tisoro-red-hover: #971823;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --red-bg: #fee2e2;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
}

/* ============= Topbar ============= */
.topbar {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand .logo {
  font-size: 24px;
  font-weight: 600;
  color: var(--gray-900);
  letter-spacing: -0.5px;
}

.brand .logo-sub {
  font-size: 11px;
  color: var(--tisoro-red);
  letter-spacing: 4px;
  margin-left: 8px;
}

.badge {
  background: var(--tisoro-red);
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge.ok { background: var(--green); }
.badge.error { background: var(--tisoro-red); }

/* ============= Layout ============= */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 60px);
}

.sidebar {
  background: white;
  border-right: 1px solid var(--gray-200);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  color: var(--gray-700);
  transition: all 0.15s;
}

.nav-item:hover { background: var(--gray-50); }

.nav-item.active {
  background: var(--gray-50);
  border-color: var(--gray-200);
  color: var(--gray-900);
}

.nav-item.active .nav-icon { background: var(--tisoro-red); color: white; }

.nav-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--gray-700);
  flex-shrink: 0;
}

.nav-title { font-weight: 600; font-size: 14px; }
.nav-sub { font-size: 12px; color: var(--gray-500); margin-top: 1px; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--gray-200);
  margin-top: 12px;
  font-size: 11px;
  color: var(--gray-500);
}

.sidebar-footer code {
  background: var(--gray-100);
  padding: 1px 6px;
  border-radius: 4px;
}

/* ============= Main + section ============= */
.main {
  padding: 24px 32px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.section-head { margin-bottom: 16px; }
.section-head h1 { margin: 0 0 4px; font-size: 22px; }
.muted { color: var(--gray-500); font-size: 14px; margin-top: 0; }

.section.hidden { display: none; }

/* ============= Cards ============= */
.card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.card h3 { margin: 0 0 12px; font-size: 15px; }

.hidden { display: none !important; }

/* ============= Form ============= */
.grid { display: grid; gap: 12px; }
.grid.g2 { grid-template-columns: 1fr 1fr; }
.grid.g3 { grid-template-columns: 1fr 1fr 1fr; }
.span-2  { grid-column: span 2; }
.mt-12   { margin-top: 12px; }
.mt-20   { margin-top: 20px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--gray-700);
}

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: white;
}

textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--tisoro-red);
  box-shadow: 0 0 0 3px rgba(177,30,42,0.1);
}

/* ============= Member rows ============= */
.section-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.section-row h3 { margin: 0; font-size: 14px; }

.member-row {
  display: grid;
  grid-template-columns: 1.4fr 1.4fr 0.6fr auto;
  gap: 8px;
  align-items: end;
  padding: 10px;
  background: var(--gray-50);
  border-radius: 8px;
  margin-bottom: 6px;
}

.member-row .attrs {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 4px;
  font-size: 12px;
}

.member-row .attrs label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-weight: 400;
  cursor: pointer;
}

.btn-remove {
  background: transparent;
  color: var(--gray-500);
  border: 1px solid var(--gray-300);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}

.btn-remove:hover { color: var(--tisoro-red); border-color: var(--tisoro-red); }

/* ============= Buttons ============= */
.btn-primary {
  background: var(--tisoro-red);
  color: white;
  border: none;
  padding: 10px 22px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: var(--tisoro-red-hover); }
.btn-primary:disabled { background: var(--gray-300); cursor: not-allowed; }

.btn-secondary {
  background: white;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--gray-50); }

.actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ============= Tabs ============= */
.tabs {
  display: flex;
  gap: 4px;
  margin: 16px 0;
  border-bottom: 1px solid var(--gray-200);
}

.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
}

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

/* ============= Doc group cards ============= */
.doc-group {
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
  background: white;
}

.doc-group-header {
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.doc-group-header:hover { background: var(--gray-50); }

.doc-group-title { font-weight: 600; font-size: 14px; }
.doc-group-progress { font-size: 11px; color: var(--gray-500); margin-top: 2px; }

.chevron { font-size: 16px; color: var(--gray-500); transition: transform 0.2s; }
.doc-group.collapsed .chevron { transform: rotate(-90deg); }
.doc-group.collapsed .doc-group-body { display: none; }

.progress-bar {
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--green);
  transition: width 0.3s;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--gray-500);
  margin-top: 4px;
}

.doc-group-body {
  border-top: 1px solid var(--gray-200);
  padding: 4px 14px;
}

/* ============= Doc rows ============= */
.doc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
}
.doc-row:last-child { border-bottom: none; }

.doc-row-left { flex: 1; min-width: 0; }
.doc-row-label { font-size: 13px; color: var(--gray-900); }
.doc-row-meta  { font-size: 11px; color: var(--gray-500); margin-top: 2px; }

.doc-row-fact {
  display: inline-block;
  background: var(--amber-bg);
  color: var(--amber);
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10px;
  margin-left: 6px;
  font-weight: 500;
}

.doc-row-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

.status-badge {
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}

.status-pending { color: var(--gray-500); }
.status-valid   { color: var(--green); }
.status-error   { color: var(--tisoro-red); }
.status-warning { color: var(--amber); }
.status-loading { color: var(--gray-700); }

.upload-btn {
  background: transparent;
  color: var(--tisoro-red);
  border: none;
  padding: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}
.upload-btn:hover { color: var(--tisoro-red-hover); }

.file-name {
  font-size: 12px;
  color: var(--gray-500);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============= Output ============= */
pre {
  background: var(--gray-900);
  color: #e5e7eb;
  padding: 14px;
  border-radius: 8px;
  font-size: 12px;
  overflow: auto;
  max-height: 500px;
  margin: 0;
}

.recommendation-card {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
}

.rec-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.rec-country { font-weight: 600; font-size: 15px; }
.rec-tag { font-size: 11px; padding: 2px 8px; background: var(--gray-100); border-radius: 10px; }
.rec-score { color: var(--green); font-weight: 600; font-size: 13px; }

.rec-pros, .rec-cons { font-size: 13px; margin: 6px 0; }
.rec-pros li::marker { color: var(--green); }
.rec-cons li::marker { color: var(--tisoro-red); }

/* ============= Modal ============= */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  background: white;
  border-radius: 12px;
  width: 90%;
  max-width: 640px;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.modal-header h3 { margin: 0; font-size: 16px; }

.close {
  background: transparent;
  border: none;
  font-size: 26px;
  line-height: 1;
  color: var(--gray-500);
  cursor: pointer;
}

.modal-body { padding: 20px; overflow-y: auto; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--tisoro-red);
  border-radius: 50%;
  margin: 24px auto;
  animation: spin 0.8s linear infinite;
}

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

.check-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
}

.check-list li {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--gray-100);
}

.check-list li:last-child { border: none; }
.check-list .pass { color: var(--green); }
.check-list .fail { color: var(--tisoro-red); }
.check-list .skip { color: var(--gray-500); }

.kvp {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 6px 12px;
  font-size: 13px;
  margin-top: 8px;
}

.kvp dt { color: var(--gray-500); }
.kvp dd { margin: 0; word-break: break-word; }

.status-pill {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-pill.valid    { background: var(--green-bg); color: var(--green); }
.status-pill.expired,
.status-pill.wrong_format,
.status-pill.wrong_country,
.status-pill.applicant_mismatch,
.status-pill.error    { background: var(--red-bg); color: var(--tisoro-red); }
.status-pill.not_certified,
.status-pill.incomplete,
.status-pill.unreadable { background: var(--amber-bg); color: var(--amber); }
