@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --primary:      #2E7D32;
  --primary-dark: #1B5E20;
  --accent:       #66BB6A;
  --bg:           #F5F5F5;
  --surface:      #FFFFFF;
  --text:         #1A1A2E;
  --text-muted:   #6B7280;
  --border:       #E5E7EB;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow:       0 4px 16px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.05);
  --radius:       8px;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Navbar ── */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.navbar-logo {
  height: 36px;
  width: auto;
  object-fit: contain;
}

.navbar-title {
  font-size: .9375rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -.01em;
  line-height: 1.2;
}

.navbar-subtitle {
  font-size: .675rem;
  color: var(--text-muted);
  font-weight: 400;
  display: block;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.navbar-user {
  font-size: .875rem;
  color: var(--text-muted);
  font-weight: 500;
}

#logout-btn {
  padding: .45rem 1rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: .8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
#logout-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ── Auth page ── */
.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.auth-top {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.125rem 2rem;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.auth-top img {
  height: 36px;
  width: auto;
  object-fit: contain;
}

.auth-top-title {
  font-size: .9375rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.auth-top-sub {
  font-size: .675rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 400;
}

.auth-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
}

.auth-container {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.auth-container h1 {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin-bottom: .25rem;
  letter-spacing: -.02em;
}

.auth-desc {
  text-align: center;
  font-size: .8125rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

#tab-bar {
  display: flex;
  gap: 0;
  margin-bottom: 2rem;
  background: var(--bg);
  border-radius: 6px;
  padding: 3px;
  border: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: .5rem;
  border: none;
  background: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--text-muted);
  font-family: inherit;
  transition: background .15s, color .15s, box-shadow .15s;
}
.tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 0;
}
.auth-form input {
  padding: .65rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: .9375rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  font-weight: 400;
}
.auth-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(46,125,50,.12);
}
.auth-form button {
  margin-top: .5rem;
  padding: .75rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: .9375rem;
  font-weight: 600;
  font-family: inherit;
  transition: background .15s;
  letter-spacing: .01em;
}
.auth-form button:hover { background: var(--primary-dark); }

/* ── Page header ── */
.page-header {
  padding: 1.75rem 2rem .25rem;
}
.page-header h1 {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}
.page-header p {
  font-size: .8125rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

/* ── Dashboard grid ── */
.dashboard {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  padding: 1.25rem 2rem 2.5rem;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  flex: 1 1 320px;
}
.card.full-width { flex: 1 1 100%; }

.card > h2 {
  font-size: .9375rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1.25rem;
  padding-bottom: .875rem;
  border-bottom: 1px solid var(--border);
  letter-spacing: -.01em;
}

/* ── Status badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .28rem .8rem;
  border-radius: 20px;
  font-weight: 600;
  text-transform: uppercase;
  font-size: .7rem;
  letter-spacing: .05em;
}
.badge.pending   { background: #FEF3C7; color: #92400E; }
.badge.submitted { background: #DBEAFE; color: #1E40AF; }
.badge.approved  { background: #D1FAE5; color: #065F46; }
.badge.rejected  { background: #FEE2E2; color: #991B1B; }
.badge.cleared   { background: #2E7D32; color: #fff; }

#review-note {
  font-size: .8125rem;
  color: var(--text-muted);
  margin-top: .875rem;
  line-height: 1.6;
}

/* ── Forms ── */
label {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .875rem;
}

input, select, textarea {
  padding: .6rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: .875rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  font-weight: 400;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(46,125,50,.12);
}
textarea { resize: vertical; }

button[type="submit"],
#upload-form button {
  padding: .65rem 1.4rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: .875rem;
  font-weight: 600;
  transition: background .15s;
  letter-spacing: .01em;
}
button[type="submit"]:hover,
#upload-form button:hover { background: var(--primary-dark); }

/* ── Table ── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8125rem;
}
th, td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
th {
  background: #F9FAFB;
  font-weight: 600;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #FAFAFA; }

td button {
  padding: .3rem .7rem;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  font-size: .75rem;
  font-weight: 500;
  margin-right: .3rem;
  transition: opacity .15s;
}
td button:hover { opacity: .82; }

/* ── Counterparty create form (inside add-cp-modal) ── */
#cp-create-form {
  display: flex;
  flex-wrap: wrap;
  gap: .8rem;
  align-items: flex-end;
}
#cp-create-form label {
  margin: 0;
  flex: 1;
  min-width: 160px;
}
#cp-create-msg { flex-basis: 100%; margin: 0; }

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.32);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  z-index: 200;
}
.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  width: 440px;
  max-width: 95vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.14);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-content h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  padding-bottom: .875rem;
  border-bottom: 1px solid var(--border);
  letter-spacing: -.01em;
}

.modal-actions { display: flex; gap: .75rem; }
.modal-actions button {
  flex: 1;
  padding: .65rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: .875rem;
  font-weight: 600;
  transition: background .15s;
}
/* Discreet secondary button (Cancel, Resend, etc.) — opt-in so primary
   action buttons (Generate Link, Copy Link, Export CSV/PDF…) are never
   affected regardless of whether they carry an inline background. */
.modal-actions button.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-weight: 500;
}
.modal-actions button.btn-secondary:hover { background: #F3F4F6; color: var(--text); }
#modal-submit       { background: var(--primary); color: #fff; }
#modal-submit:hover { background: var(--primary-dark); }
#modal-cancel       { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
#modal-cancel:hover { background: #ebebeb; }
#share-submit       { background: var(--primary); color: #fff; }
#share-submit:hover { background: var(--primary-dark); }
#share-cancel       { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
#share-cancel:hover { background: #ebebeb; }
/* ── CP docs review modal ── */
#cp-docs-modal .cp-docs-section {
  margin-bottom: 1.1rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--border);
}
#cp-docs-modal .cp-docs-section:last-of-type { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
#cp-docs-modal .cp-docs-section-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: .55rem;
}
#cp-docs-modal summary.cp-docs-section-label { cursor: pointer; list-style: none; }
#cp-docs-modal summary.cp-docs-section-label::-webkit-details-marker { display: none; }

/* Questionnaire cards */
#cp-docs-modal .cp-q-row { display: flex; gap: .6rem; flex-wrap: wrap; }
#cp-docs-modal .cp-q-card {
  flex: 1 1 180px;
  border-radius: 6px;
  padding: .5rem .65rem;
  font-size: .78rem;
  line-height: 1.45;
  border: 1px solid;
}
#cp-docs-modal .cp-q-card-label { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .2rem; opacity: .85; }
#cp-docs-modal .cp-q-clear   { background: #D1FAE5; color: #065F46; border-color: #6EE7B7; }
#cp-docs-modal .cp-q-flag    { background: #FEF3C7; color: #92400E; border-color: #FCD34D; }
#cp-docs-modal .cp-q-neutral { background: #F3F4F6; color: #6B7280; border-color: var(--border); }

/* Documents list */
#cp-docs-list {
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 .75rem;
}
#cp-docs-list li { padding: 0; border-bottom: none; }
#cp-docs-modal .cp-doc-empty { padding: .6rem 0; color: var(--text-muted); }
#cp-docs-modal .cp-doc-row { padding: .55rem 0; border-bottom: 1px solid var(--border); }
#cp-docs-modal .cp-doc-row:last-child { border-bottom: none; }
#cp-docs-modal .cp-doc-line { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; flex-wrap: wrap; }
#cp-docs-modal .cp-doc-info { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; font-size: .8125rem; }
#cp-docs-modal .cp-doc-tag {
  font-size: .62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .12rem .4rem;
  border-radius: 4px;
  flex-shrink: 0;
}
#cp-docs-modal .cp-doc-tag-admin { background: #EDE9FE; color: #5B21B6; }
#cp-docs-modal .cp-doc-tag-cp    { background: #E0F2FE; color: #075985; }
#cp-docs-modal .cp-doc-type { color: var(--text-muted); }
#cp-docs-modal .cp-doc-note { font-size: .75rem; color: #6B7280; font-style: italic; }
#cp-docs-modal .cp-doc-actions { display: flex; gap: .35rem; align-items: center; flex-shrink: 0; }
#cp-docs-modal .cp-doc-btn-ghost {
  padding: .22rem .55rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: .72rem;
  font-weight: 500;
  transition: background .12s, color .12s;
}
#cp-docs-modal .cp-doc-btn-ghost:hover { background: #F3F4F6; color: var(--text); }
#cp-docs-modal .cp-doc-btn {
  padding: .22rem .6rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: .72rem;
  font-weight: 600;
  color: #fff;
}
#cp-docs-modal .cp-doc-btn-approve { background: #22C55E; }
#cp-docs-modal .cp-doc-btn-reject  { background: #EF4444; }
#cp-docs-modal .cp-doc-btn-link {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-muted);
  font-family: inherit;
  font-size: .72rem;
  text-decoration: underline;
  cursor: pointer;
}
#cp-docs-modal .cp-doc-btn-link:hover { color: var(--text); }
#cp-docs-modal .cp-doc-comment-wrap {
  margin-top: .5rem;
  padding: .5rem;
  background: #F9FAFB;
  border-radius: 5px;
  border: 1px solid var(--border);
}
#cp-docs-modal .cp-doc-comment-wrap textarea {
  width: 100%;
  min-height: 48px;
  padding: .35rem .55rem;
  font-size: .78rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  resize: vertical;
  box-sizing: border-box;
}
#cp-docs-modal .cp-doc-comment-actions { display: flex; gap: .5rem; align-items: center; margin-top: .4rem; }

/* Footer */
#cp-docs-modal .cp-docs-footer { display: flex; justify-content: flex-end; padding-top: .25rem; }
#cp-docs-close {
  padding: .5rem 1.2rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: .8125rem;
  font-weight: 500;
  transition: background .15s, color .15s;
}
#cp-docs-close:hover { background: #F3F4F6; color: var(--text); }

/* ── Lists ── */
ul { list-style: none; }
ul li {
  padding: .6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .8125rem;
  color: var(--text);
  line-height: 1.5;
}
ul li:last-child { border-bottom: none; }
ul li a { color: var(--primary); text-decoration: none; font-weight: 500; }
ul li a:hover { text-decoration: underline; }

/* ── Utility ── */
.msg {
  font-size: .8rem;
  margin-top: .4rem;
  min-height: 1.2em;
  color: var(--text-muted);
}
.msg.error   { color: #DC2626; }
.msg.success { color: var(--primary); }
.hidden { display: none !important; }

/* ── Assign modal buttons ── */
#assign-save        { background: var(--primary); color: #fff; }
#assign-save:hover  { background: var(--primary-dark); }
#assign-cancel      { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
#assign-cancel:hover { background: #ebebeb; }

/* ── File input reset (prevent oversized padding) ── */
input[type="file"] { padding: .35rem .5rem; font-size: .8rem; }

/* ── Document checklist rows ── */
.doc-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.25rem;
  padding: .875rem 0;
  border-bottom: 1px solid var(--border);
}
.doc-row:last-child { border-bottom: none; }

.doc-row-info {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  flex: 1;
  min-width: 0;
}
.doc-row-type {
  font-weight: 600;
  font-size: .875rem;
  color: var(--text);
}
.doc-row-file {
  font-size: .8rem;
  color: var(--text-muted);
}
.doc-row-note {
  font-size: .78rem;
  color: #DC2626;
  font-style: italic;
}

.doc-row-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .5rem;
  flex-shrink: 0;
  min-width: 160px;
}

.doc-row-upload {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .3rem;
}
.doc-row-upload input[type="file"] {
  max-width: 190px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text-muted);
}
.doc-row-upload button {
  padding: .35rem .9rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 600;
  transition: background .15s;
}
.doc-row-upload button:hover { background: var(--primary-dark); }

@media (max-width: 600px) {
  .doc-row { flex-direction: column; gap: .75rem; }
  .doc-row-right { align-items: flex-start; }
}

/* ── Site footer ── */
.site-footer {
  text-align: center;
  padding: 1.25rem 2rem;
  font-size: .75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: auto;
}
.site-footer a {
  color: var(--text-muted);
  text-decoration: underline;
}
.site-footer a:hover { color: var(--primary); }

/* ── Responsive ── */
@media (max-width: 640px) {
  .navbar          { padding: 0 1rem; }
  .navbar-title    { font-size: .8rem; }
  .navbar-subtitle { display: none; }
  .page-header     { padding: 1.25rem 1rem .25rem; }
  .dashboard       { padding: 1rem 1rem 2rem; }
  .auth-container  { padding: 1.75rem 1.25rem; }
  .card            { padding: 1.25rem; }
}
