:root {
  --bg: #f4f6fb;
  --bg-card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --muted-strong: #475569;
  --border: #dbe3f0;
  --border-strong: #c5d0e3;
  --accent: #0f766e;
  --accent-weak: #ecfdf5;
  --accent-strong: #0d5e58;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --success: #059669;
  --success-bg: #d1fae5;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --card-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --text: #f8fafc;
  --muted: #94a3b8;
  --muted-strong: #cbd5f5;
  --border: #273349;
  --border-strong: #36435c;
  --accent: #14b8a6;
  --accent-weak: #064e48;
  --accent-strong: #0f766e;
  --danger: #f87171;
  --danger-bg: #7f1d1d;
  --success: #34d399;
  --success-bg: #064e3b;
  --warning: #facc15;
  --warning-bg: #7c5c0a;
  --card-shadow: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.4;
}

.app-shell {
  padding-bottom: 80px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
}

.brand-link:hover,
.brand-link:focus {
  text-decoration: none;
  color: var(--text);
}

.brand-logo {
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  letter-spacing: 1px;
}

.brand strong {
  display: block;
  font-size: 1rem;
}

.brand small {
  color: var(--muted);
  font-size: 0.8rem;
}

.nav-links {
  display: flex;
  gap: 18px;
}

.nav-links a {
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  padding: 6px 0;
  position: relative;
}

.nav-links a.active {
  color: var(--accent);
}

.nav-links a.active::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -6px;
  width: 100%;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

.nav-links a.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.nav-links .nav-disabled {
  display: inline-block;
  padding: 6px 0;
  color: var(--muted);
  opacity: 0.35;
  cursor: not-allowed;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  border-color: var(--accent);
}

.stepper {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  padding: 16px 28px 10px;
}

.step {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
}

.step span {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}

.step.active {
  border-style: solid;
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-weak);
}

.content {
  padding: 32px 28px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.page-header h1 {
  margin: 0;
  font-size: 2rem;
}

.muted {
  color: var(--muted);
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  box-shadow: var(--card-shadow);
  margin-bottom: 24px;
}

.card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.form-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.form-grid .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
}

.form-grid .search-field {
  flex: 1 1 300px;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  border-radius: 999px;
  padding: 8px 14px;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.06);
}

.search-input {
  border: none;
  outline: none;
  background: transparent;
  flex: 1;
  font-size: 1rem;
  color: var(--text);
}

.search-input::placeholder {
  color: var(--muted);
}

.search-icon {
  font-size: 0.9rem;
  color: var(--muted-strong);
}

label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
}

input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

textarea {
  min-height: 80px;
  resize: vertical;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}

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

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

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

.table thead th {
  text-align: left;
  padding: 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(148, 163, 184, 0.1);
  font-size: 0.85rem;
  color: var(--muted-strong);
}

.table tbody td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table tbody tr:hover {
  background: rgba(15, 118, 110, 0.05);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.78rem;
  color: var(--muted-strong);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.status-pill.success {
  background: var(--success-bg);
  color: var(--success);
}

.status-pill.fail {
  background: var(--danger-bg);
  color: var(--danger);
}

.status-pill.neutral {
  background: rgba(148, 163, 184, 0.2);
  color: var(--muted-strong);
}

.selection-hint {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin: 16px 0;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 100;
}

.loading-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 12px;
}

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

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 80;
}

.modal.open {
  visibility: visible;
  opacity: 1;
}

.modal-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
  max-width: 460px;
  width: 100%;
  box-shadow: var(--card-shadow);
}

.modal-card h3 {
  margin-top: 0;
}

.flex {
  display: flex;
  gap: 12px;
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
  gap: 20px;
}

@media (max-width: 900px) {
  .split {
    grid-template-columns: 1fr;
  }
}

.chat-layout {
  min-height: 70vh;
}

.chat-history {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 65vh;
  overflow-y: auto;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 90%;
}

.message .meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.bubble {
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.message.you {
  align-self: flex-end;
  text-align: right;
}

.message.you .bubble {
  background: var(--accent-weak);
  color: var(--text);
}

.chat-compose {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--bg-card);
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-compose form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.input-stack {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.input-stack textarea {
  flex: 1;
  min-height: 110px;
}

.input-stack .send-btn {
  height: 44px;
  white-space: nowrap;
}

.chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.grid-two {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.table textarea {
  width: 100%;
}

.count-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-weight: 600;
}

.link {
  color: var(--accent);
  text-decoration: none;
}

.link:hover {
  text-decoration: underline;
}
