@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=IBM+Plex+Mono:wght@400;500;600&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg: #e9edf2;
  --surface: #ffffff;
  --ink: #182233;
  --ink-soft: #5b6472;
  --line: #d7dce3;
  --primary: #2f5d8a;
  --primary-dark: #1f3f60;
  --pending: #8a8f98;
  --processing: #b5852f;
  --done: #2e7d5b;
  --failed: #b23a34;
  --radius: 10px;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background-color: var(--bg);
  background-image: radial-gradient(circle, rgba(24, 34, 51, 0.07) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--font-body);
  min-height: 100vh;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  gap: 12px;
}

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

.brand-mark {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.08em;
  border: 2px solid var(--primary);
  color: var(--primary);
  padding: 6px 10px;
  border-radius: 6px;
  transform: rotate(-4deg);
}

.brand h1 {
  font-family: var(--font-display);
  font-size: 22px;
  margin: 0;
  line-height: 1.1;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.legend {
  display: flex;
  gap: 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  flex-wrap: wrap;
}

.legend span { display: flex; align-items: center; gap: 6px; }
.legend .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---- Layout ---- */
.layout {
  max-width: 1900px;
  width: 94%;
  margin: 28px auto 28px 20px;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 260px 300px 1fr; /* user + upload + documents, side by side */
  gap: 24px;
  align-items: start;
}

/* Panels ka column FIXED rakha hai (DOM order/auto-placement par nahi
   chhoda) -- warna jab non-admin user ke liye .user-panel chhup jaata hai
   (display:none), to grid auto-placement baaki panels ko ek slot bayin
   taraf khisak deta hai aur Documents panel galti se 320px wale column
   mein chala jaata hai, poore-width wale 1fr column mein nahi. */
.user-panel { grid-column: 1; }
.upload-panel { grid-column: 2; }
.jobs-panel { grid-column: 3; }

/* Non-admin: Users panel poori tarah chhupa hota hai (index.html JS
   .layout par "no-users" class laga deta hai) -- iske bina, uska 260px
   fixed track khaali jagah ki tarah reh jaata hai (grid track content na
   hone par bhi apni width leta hai). Is class ke saath sirf 2 columns
   (New document + Documents) reh jaate hain, khaali jagah ke bina. */
.layout.no-users {
  grid-template-columns: 320px 1fr;
}
.layout.no-users .upload-panel { grid-column: 1; }
.layout.no-users .jobs-panel { grid-column: 2; }

/* Tablet: Users + New document side by side, Documents full width below */
@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr 1fr;
    margin: 20px auto;
  }
  .layout.no-users {
    grid-template-columns: 1fr;
  }
  .user-panel, .upload-panel,
  .layout.no-users .upload-panel {
    grid-column: auto;
  }
  .jobs-panel {
    grid-column: 1 / -1;
  }
}

/* Mobile: everything stacks in a single column */
@media (max-width: 640px) {
  .topbar {
    padding: 16px 18px;
  }
  .topbar > div:last-child {
    flex-wrap: wrap;
    gap: 10px !important;
  }
  .layout {
    grid-template-columns: 1fr;
    padding: 0 16px;
    gap: 16px;
    margin: 16px auto;
  }
  .jobs-panel {
    grid-column: auto;
  }
  .panel {
    padding: 16px;
  }
  .panel-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .panel-head > div {
    width: 100%;
    flex-wrap: wrap;
  }
  #docSearchInput {
    width: 100% !important;
  }
}

/* ---- Panels ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.panel h2 {
  font-family: var(--font-display);
  font-size: 16px;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-icon {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  color: var(--primary);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.panel-head h2 { margin: 0; }

/* ---- User panel ---- */
.user-panel h2 {
  margin-bottom: 8px;
}

.user-panel .hint {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--ink-soft);
}

.user-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.user-btn {
  display: block;
  text-align: center;
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.user-btn.primary {
  background: var(--primary);
  border: 1px solid var(--primary);
  color: #fff;
}

.user-btn.secondary {
  background: #fff;
  border: 1px solid var(--primary);
  color: var(--primary);
}

.user-btn.primary:hover,
.user-btn.secondary:hover {
  opacity: 0.9;
}

/* ---- Dashboard stat list (narrow sidebar) ---- */
.stat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.stat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f3f6fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.stat-item .stat-num {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  color: var(--primary);
}

.stat-item .stat-label {
  font-size: 10.5px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: right;
}

/* ---- Wide stat row (report page) ---- */
.stat-row {
  display: flex;
  gap: 14px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.stat-box {
  flex: 1;
  min-width: 140px;
  text-align: center;
  background: #f3f6fa;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 10px;
}

.stat-box .stat-num {
  display: block;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
}

.stat-box .stat-label {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

.user-summary {
  font-size: 12px;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.user-summary p {
  margin: 4px 0;
}

/* ---- Upload panel ---- */
.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-soft);
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--primary); background: #eef3f9; color: var(--primary); }
.dropzone input { display: none; }

#uploadForm button[type="submit"] {
  width: 100%;
  margin-top: 14px;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
}
#uploadForm button[type="submit"]:hover { background: var(--primary-dark); }
#uploadForm button[disabled] { background: var(--ink-soft); cursor: default; }

.hint { font-size: 12px; color: var(--ink-soft); margin: 12px 0 0; min-height: 16px; }

/* ---- Buttons ---- */
.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.ghost-btn:hover { border-color: var(--primary); color: var(--primary); }
.ghost-btn.small { padding: 3px 9px; font-size: 11px; }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

tbody tr {
  cursor: pointer;
  transition: background .1s;
}
tbody tr:hover { background: #f3f6fa; }
tbody td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }

.empty-row {
  text-align: center;
  color: var(--ink-soft);
  cursor: default;
  padding: 24px 0 !important;
}
.empty-row:hover { background: none !important; }

.filename { font-weight: 600; }
.file-id { display: block; font-family: var(--font-mono); font-size: 11px; color: var(--ink-soft); }

/* ---- Badges ---- */
.badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge.PENDING { background: var(--pending); }
.badge.PROCESSING { background: var(--processing); }
.badge.DONE { background: var(--done); }
.badge.FAILED { background: var(--failed); }

/* ---- Stage track ---- */
.stage-track { display: flex; gap: 3px; }
.stage-dot {
  width: 16px;
  height: 6px;
  border-radius: 3px;
  background: #e3e7ec;
  display: inline-block;
}
.stage-dot.filled { background: var(--processing); }
.stage-dot.filled.done { background: var(--done); }
.stage-dot.filled.failed { background: var(--failed); }

/* ---- Document detail modal ---- */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 33, 0.5);
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}
.modal-backdrop.open { display: flex; }

.modal {
  position: relative;
  background: var(--surface);
  width: 640px;
  max-width: 100%;
  max-height: 86vh;
  border-radius: 12px;
  padding: 28px 30px;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.modal-close:hover { background: #f1f4f7; color: var(--ink); }

#modalTitle {
  font-family: var(--font-display);
  font-size: 19px;
  margin: 0 28px 18px 0;
  word-break: break-word;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 20px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.modal-grid > div { display: flex; flex-direction: column; gap: 2px; }
.modal-grid .label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.modal-grid .value { font-size: 13px; font-weight: 600; word-break: break-word; }

.ocr-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-display);
  font-size: 15px;
  margin: 0 0 10px;
}

.ocr-text {
  background: #f6f8fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
  margin: 0;
}

/* ---- Document pipeline strip ---- */
.pipeline-strip {
  max-width: 1440px;
  width: 94%;
  margin: 4px auto 44px;
  padding: 0 24px;
}

.pipeline-head h2 {
  font-family: var(--font-display);
  font-size: 16px;
  margin: 0 0 4px;
}

.pipeline-head .hint {
  margin: 0 0 18px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.pipeline-track {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 30px;
}

.pipeline-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  text-align: center;
}

.pipeline-num {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  border: 1.5px solid var(--primary);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eef3f9;
}

.pipeline-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
}

.pipeline-label small {
  display: block;
  font-weight: 400;
  color: var(--ink-soft);
  font-size: 10.5px;
  margin-top: 1px;
}

.pipeline-connector {
  flex: 0 0 44px;
  height: 1.5px;
  background: var(--line);
  margin: 0 2px 24px;
}

@media (max-width: 860px) {
  .pipeline-track { flex-direction: column; align-items: stretch; padding: 20px; }
  .pipeline-node { flex-direction: row; justify-content: flex-start; text-align: left; }
  .pipeline-connector { width: 1.5px; height: 20px; flex-basis: 20px; margin: 0 0 0 13px; }
}

/* ---- Footer ---- */
.app-footer {
  max-width: 1440px;
  width: 94%;
  margin: 0 auto 32px;
  padding: 18px 24px 0;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
}

