/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:      #3b82f6;
  --blue-dark: #1d4ed8;
  --green:     #10b981;
  --amber:     #f59e0b;
  --red:       #ef4444;
  --bg:        #f1f5f9;
  --card:      #ffffff;
  --text:      #1e293b;
  --muted:     #64748b;
  --border:    #e2e8f0;
  --radius:    8px;
  --shadow:    0 1px 4px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.06);
}

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

/* ── Nav ──────────────────────────────────────────────────────────────────── */
nav {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  height: 56px;
  gap: 1rem;
}
nav .brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--blue);
  text-decoration: none;
}
nav .spacer { flex: 1; }
nav .nav-user { color: var(--muted); font-size: .9rem; }
nav .nav-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .3rem .8rem;
  cursor: pointer;
  font-size: .85rem;
  color: var(--text);
  text-decoration: none;
}
nav .nav-btn:hover { background: var(--bg); }

/* ── Notification bar ─────────────────────────────────────────────────────── */
#notification {
  display: none;
  padding: .75rem 1.5rem;
  font-size: .9rem;
  font-weight: 500;
}
#notification.success { background: #dcfce7; color: #166534; }
#notification.error   { background: #fee2e2; color: #991b1b; }
#notification.info    { background: #dbeafe; color: #1e40af; }

/* ── Container ────────────────────────────────────────────────────────────── */
.container { max-width: 900px; margin: 0 auto; padding: 2rem 1.5rem; }

/* ── Auth page ────────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 420px;
}
.auth-card h1 { text-align: center; color: var(--blue); margin-bottom: 1.5rem; font-size: 1.6rem; }
.tab-bar { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 1.5rem; }
.tab-bar button {
  flex: 1;
  background: none;
  border: none;
  padding: .6rem;
  font-size: .95rem;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.tab-bar button.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .3rem; color: var(--muted); }
input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .55rem .75rem;
  font-size: .95rem;
  font-family: inherit;
  transition: border-color .15s;
}
input:focus, textarea:focus { outline: none; border-color: var(--blue); }
textarea { resize: vertical; min-height: 80px; }
.role-row { display: flex; gap: 1rem; }
.role-row label { display: flex; align-items: center; gap: .4rem; font-size: .9rem; cursor: pointer; }

/* ── Password toggle ──────────────────────────────────────────────────────── */
.pwd-wrap { position: relative; }
.pwd-wrap input { padding-right: 2.5rem; }
.pwd-toggle {
  position: absolute;
  right: .65rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: var(--muted);
  display: flex;
  align-items: center;
}
.pwd-toggle:hover { color: var(--text); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.2rem;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--blue);  color: #fff; }
.btn-success  { background: var(--green); color: #fff; }
.btn-danger   { background: var(--red);   color: #fff; }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-sm       { padding: .3rem .7rem; font-size: .82rem; }
.btn-full     { width: 100%; justify-content: center; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}
.card-header { display: flex; align-items: center; gap: 1rem; margin-bottom: .5rem; }
.card-title  { font-weight: 600; font-size: 1rem; }
.card-meta   { font-size: .82rem; color: var(--muted); }
.card-actions { display: flex; gap: .5rem; margin-left: auto; }

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  margin-bottom: 1.5rem;
  gap: 1rem;
}
.page-header h2 { font-size: 1.4rem; flex: 1; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-gray   { background: #f1f5f9; color: var(--muted); }

/* ── Section ──────────────────────────────────────────────────────────────── */
.section { margin-bottom: 2.5rem; }
.section h3 { font-size: 1.1rem; margin-bottom: 1rem; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
  width: 100%;
  max-width: 460px;
}
.modal-box h3 { margin-bottom: 1.25rem; font-size: 1.1rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .75rem; margin-top: 1.25rem; }

/* ── AI Chat ──────────────────────────────────────────────────────────────── */
.chat-history {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  min-height: 200px;
  max-height: 420px;
  overflow-y: auto;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.chat-msg { display: flex; flex-direction: column; gap: .2rem; }
.chat-msg .label { font-size: .75rem; font-weight: 600; color: var(--muted); }
.chat-msg.question .bubble { background: var(--blue); color: #fff; align-self: flex-end; border-radius: 12px 12px 2px 12px; }
.chat-msg.answer   .bubble { background: var(--card); border: 1px solid var(--border); align-self: flex-start; border-radius: 12px 12px 12px 2px; }
.chat-msg.answer   .label  { align-self: flex-start; }
.chat-msg.question .label  { align-self: flex-end; }
.bubble { padding: .6rem .9rem; max-width: 80%; font-size: .92rem; line-height: 1.5; }
.chat-input-row { display: flex; gap: .75rem; }
.chat-input-row input { flex: 1; }

/* ── Search ───────────────────────────────────────────────────────────────── */
.search-row { display: flex; gap: .75rem; margin-bottom: 1.5rem; }
.search-row input { flex: 1; }

/* ── Table-like list ──────────────────────────────────────────────────────── */
.list-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .7rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.list-item:last-child { border-bottom: none; }
.list-item .name { flex: 1; }
.list-item .meta { color: var(--muted); font-size: .82rem; }

/* ── Upload form ──────────────────────────────────────────────────────────── */
.upload-row { display: flex; gap: .75rem; align-items: center; margin-bottom: 1rem; }
.upload-row input[type=file] { flex: 1; font-size: .88rem; }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); font-size: .95rem; }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid #fff; border-top-color: transparent; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
