:root {
  --green: #00a651;
  --green-dark: #008543;
  --ink: #1f2328;
  --muted: #6b7480;
  --line: #e2e6ea;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --danger: #c0392b;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--green-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  background: var(--ink);
  color: #fff;
  padding: 0 20px;
  height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 600; font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand-icon { height: 32px; width: auto; }
.topnav { display: flex; gap: 18px; flex: 1; }
.topnav a { color: #cfd4da; font-weight: 500; }
.topnav a:hover { color: #fff; text-decoration: none; }
.user-box { display: flex; align-items: center; gap: 14px; color: #cfd4da; }
.user-name { font-weight: 500; }
.btn-link { color: #cfd4da; }
.btn-link:hover { color: #fff; }

/* Layout */
.layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar {
  width: 280px;
  flex: 0 0 280px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
}
.content { flex: 1; padding: 24px 28px; min-width: 0; }

/* Sidebar flag tree */
.sidebar h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.sidebar .quick a { display: block; padding: 6px 8px; border-radius: 6px; color: var(--ink); }
.sidebar .quick a.active, .sidebar .quick a:hover { background: var(--bg); text-decoration: none; }
.flag-cat { margin-top: 16px; }
.flag-cat > summary { font-weight: 600; cursor: pointer; padding: 6px 4px; list-style: none; }
.flag-cat > summary::-webkit-details-marker { display: none; }
.flag-cat > summary::before { content: "▸"; color: var(--muted); margin-right: 6px; }
.flag-cat[open] > summary::before { content: "▾"; }
.flag-val { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 22px; border-radius: 6px; color: var(--ink); }
.flag-val:hover { background: var(--bg); text-decoration: none; }
.flag-val.active { background: #e7f6ee; }
.chip-dot { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto; border: 1px solid rgba(0,0,0,.15); }
.flag-val .count { margin-left: auto; color: var(--muted); font-size: 12px; }

/* Active filter pills */
.active-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.pill { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.pill a { color: var(--muted); font-weight: 700; }

/* Flag chips on rows */
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }

/* Tables */
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { background: #fafbfc; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.list th a { color: var(--muted); }
table.list tr:last-child td { border-bottom: none; }
table.list tr:hover td { background: #fafbfc; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Headers */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }

/* Buttons & forms */
.btn { display: inline-block; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; font-size: 14px; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-danger { color: var(--danger); border-color: #e7c3bd; }
.btn-sm { padding: 4px 9px; font-size: 12px; }

form label { display: block; margin-bottom: 12px; font-weight: 500; }
form input[type=text], form input[type=password], form input[type=date],
form input[type=file], form select, form textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 6px; font-size: 14px; background: #fff;
}
form .inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 16px; padding: 14px 16px; }
fieldset legend { font-weight: 600; padding: 0 6px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }

/* Flashes */
.flashes { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; border: 1px solid; }
.flash-error { background: #fdecea; border-color: #f5c6c0; color: #842029; }
.flash-success { background: #e7f6ee; border-color: #b6e3c9; color: #0f5132; }
.flash-info, .flash-message, .flash-warning { background: #fff8e6; border-color: #f0e0a8; color: #6b5900; }

/* Dashboard cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card .big { font-size: 28px; font-weight: 700; }
.card .label { color: var(--muted); font-size: 13px; }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--ink); }
.login-card { background: var(--panel); border-radius: 12px; padding: 28px; width: 360px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.login-banner { width: 100%; height: auto; border-radius: 6px; margin-bottom: 20px; }
.login-card .btn-primary { width: 100%; margin-top: 6px; }

/* Misc */
.empty { color: var(--muted); padding: 40px; text-align: center; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }
.dup-warning { background: #fff8e6; border: 1px solid #f0e0a8; border-radius: 6px; padding: 10px 14px; margin-bottom: 14px; }
.version-row td { font-size: 13px; }
.tag-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }

/* Nav badge (review queue count) */
.nav-badge { display: inline-block; min-width: 18px; padding: 0 5px; height: 18px; line-height: 18px; text-align: center; font-size: 11px; font-weight: 700; color: #fff; background: var(--green); border-radius: 999px; vertical-align: middle; }

/* Global drag-and-drop overlay */
.drop-overlay { position: fixed; inset: 0; z-index: 2000; background: rgba(0, 133, 67, .18); backdrop-filter: blur(1px); display: flex; align-items: center; justify-content: center; }
.drop-overlay[hidden] { display: none; }
.drop-card { background: var(--panel); border: 3px dashed var(--green); border-radius: 16px; padding: 48px 64px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.25); pointer-events: none; }
.drop-icon { font-size: 56px; }
.drop-title { font-size: 18px; font-weight: 600; margin-top: 12px; }

/* Toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 2100; display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px; padding: 12px 14px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.18); opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; }
.toast.show { opacity: 1; transform: none; }
.toast-success { border-left-color: var(--green); }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: #6b7480; }

/* Review queue banner on the document workspace */
.review-banner { display: flex; align-items: center; justify-content: space-between; gap: 16px; background: #fff8e6; border: 1px solid #f0e0a8; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; }

/* Contract status badges */
.badge { font-size: 11px; padding: 2px 9px; border-radius: 999px; margin-left: 8px; font-weight: 600; border: 1px solid; white-space: nowrap; }
.badge-expired { background: #fdecea; color: #842029; border-color: #f5c6c0; }
.badge-soon { background: #fff8e6; color: #6b5900; border-color: #f0e0a8; }
.badge-active { background: #e7f6ee; color: #0f5132; border-color: #b6e3c9; }
.badge-none { background: var(--bg); color: var(--muted); border-color: var(--line); }

/* Document workspace: edit fields beside a live preview.
   Split is 50/50 by default (small windows) and 25/75 (edit/preview) when
   wide — the preview gets the extra room. */
.workspace { display: flex; gap: 20px; align-items: flex-start; }
.workspace-edit { flex: 1 1 0; min-width: 0; }
.workspace-preview {
  flex: 1 1 0;
  min-width: 0;
  position: sticky;
  top: 24px;
  height: calc(100vh - 56px - 48px);
  background: #f0f1f3;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-frame { width: 100%; height: 100%; border: 0; background: #fff; }
.preview-image { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-empty { padding: 40px; color: var(--muted); text-align: center; }

/* Wide screens: give the preview the larger share (edit 25% / preview 75%). */
@media (min-width: 1200px) {
  .workspace-edit { flex-grow: 1; }
  .workspace-preview { flex-grow: 3; }
}

/* Phones: stack the panes. */
@media (max-width: 640px) {
  .workspace { flex-direction: column; }
  .workspace-edit, .workspace-preview { width: 100%; }
  .workspace-preview { position: static; height: 70vh; }
}

/* Document workspace details */
.back-link { display: inline-block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.page-head h1 .badge { vertical-align: middle; font-size: 12px; }
.head-actions { display: flex; gap: 8px; align-items: center; }

.notice { background: #eef4ff; border: 1px solid #cfe0fb; color: #234; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 18px; font-size: 13px; }

.workspace-edit .panel { margin-bottom: 16px; }
.edit-tools { display: flex; justify-content: flex-end; margin-bottom: 12px; }
/* Collapsible card headers (details/summary) */
.workspace-edit summary { list-style: none; display: flex; align-items: center; cursor: pointer; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.workspace-edit summary::-webkit-details-marker { display: none; }
.workspace-edit details[open] > summary { margin-bottom: 14px; }
.workspace-edit summary h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin: 0; padding: 0; border: 0; }
.workspace-edit summary::after { content: "▾"; color: var(--muted); font-size: 12px; margin-left: auto; }
.workspace-edit details:not([open]) > summary::after { content: "▸"; }
.workspace-edit summary:hover h2 { color: var(--ink); }

/* Compact label/value list (read-only facts) */
.meta { display: flex; flex-direction: column; }
.meta-row { display: flex; justify-content: space-between; gap: 16px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.meta-row:last-child { border-bottom: none; }
.meta-row > span:first-child { color: var(--muted); }
.meta-row > span:last-child { text-align: right; font-weight: 500; }

/* A single row of inputs ending in a button (title, tag, version, etc.) */
.field-row { display: flex; gap: 10px; align-items: flex-end; }
.field-row label { margin-bottom: 0; }
.field-row .grow { flex: 1; }

/* Two-up grid of fields (contract dates, etc.) */
.field-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 16px; }
.field-grid label { margin-bottom: 12px; }

.form-actions { margin-top: 4px; }
.check { font-weight: 400; }
.req { font-size: 11px; color: var(--green-dark); background: #e7f6ee; border: 1px solid #b6e3c9; border-radius: 999px; padding: 1px 7px; margin-left: 4px; }

/* Removable tag chips */
.chip-x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1; padding: 0 0 0 4px; }
.chip-x:hover { color: var(--danger); }

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

/* ---- Bulk actions on document lists ---- */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding: 8px 10px;
  background: #f4f6f8;
  border: 1px solid #e0e4e8;
  border-radius: 6px;
}
.bulk-bar .bulk-count { font-weight: 600; margin-right: auto; }
.bulk-bar input[type="text"] { width: 9em; }
.bulk-col { width: 1%; text-align: center; }
