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

:root {
  --color-primary:   #2563eb;
  --color-primary-h: #1d4ed8;
  --color-danger:    #dc2626;
  --color-success:   #16a34a;
  --color-warning:   #d97706;
  --color-bg:        #f8fafc;
  --color-surface:   #ffffff;
  --color-border:    #e2e8f0;
  --color-text:      #1e293b;
  --color-muted:     #64748b;
  --radius:          6px;
  --shadow:          0 1px 3px rgba(0,0,0,.08);
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* Header */
.header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: .75rem 2rem;
  box-shadow: var(--shadow);
}
.brand-link { font-weight: 700; font-size: 1.2rem; color: var(--color-primary); }
.header-nav { display: flex; gap: 1rem; flex: 1; }
.nav-link { color: var(--color-muted); font-size: .9rem; font-weight: 500; }
.nav-link:hover { color: var(--color-primary); text-decoration: none; }
.header-user { display: flex; align-items: center; gap: .75rem; }

.user-menu { position: relative; }
.user-menu-toggle {
  list-style: none;
  cursor: pointer;
  font-size: .85rem;
  color: var(--color-primary-h);
  padding: .3rem .75rem;
  background: #dbeafe;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
}
.user-menu-toggle::-webkit-details-marker { display: none; }
.user-menu-toggle:hover { background: #bfdbfe; }
.user-menu-dropdown {
  position: absolute;
  top: calc(100% + .4rem);
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 140px;
  overflow: hidden;
  z-index: 10;
}
.user-menu-item {
  display: block;
  width: 100%;
  padding: .55rem .9rem;
  font-size: .85rem;
  color: var(--color-text);
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
}
.user-menu-item:hover { background: var(--color-bg); text-decoration: none; }
.user-menu-item-btn { font: inherit; }

/* Main */
.main-content { flex: 1; max-width: 1000px; width: 100%; margin: 0 auto; padding: 2rem 1.5rem; }

/* Footer */
.footer { text-align: center; padding: 1rem; font-size: .8rem; color: var(--color-muted); border-top: 1px solid var(--color-border); }

/* Hero */
.hero { text-align: center; padding: 5rem 1rem; }
.hero h1 { font-size: 2.5rem; margin-bottom: .5rem; }
.hero p { color: var(--color-muted); margin-bottom: 1.5rem; }

/* Auth */
.auth-container { max-width: 400px; margin: 3rem auto; }
.auth-title { font-size: 1.5rem; margin-bottom: 1.5rem; text-align: center; }

/* Page header */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.6rem; }
.header-actions { display: flex; gap: .5rem; }

/* Search bar */
.search-bar { display: flex; justify-content: center; gap: .5rem; margin-bottom: 1.25rem; }
.search-input { flex: 1; max-width: 420px; border-radius: 999px; text-align: center; }

/* Buttons */
.btn {
  display: inline-block;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none !important;
  transition: background .15s;
}
.btn-primary  { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-h); }
.btn-secondary { background: #fff; color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); }
.btn-danger   { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-warning  { background: var(--color-warning); color: #fff; border-color: var(--color-warning); }
.btn-warning:hover { background: #b45309; }
.btn-success  { background: var(--color-success); color: #fff; border-color: var(--color-success); }
.btn-success:hover { background: #15803d; }
.btn-sm       { padding: .3rem .6rem; font-size: .8rem; }
.btn-full     { width: 100%; text-align: center; }
.btn-icon     { display: inline-flex; align-items: center; justify-content: center; width: 1.9rem; height: 1.9rem; padding: 0; }
.btn-icon svg { width: 1rem; height: 1rem; }
.btn-logout   { background: none; border: 1px solid var(--color-border); border-radius: var(--radius); padding: .3rem .75rem; font-size: .85rem; cursor: pointer; color: var(--color-muted); }
.btn-logout:hover { background: var(--color-bg); }
button:disabled { opacity: .5; cursor: not-allowed; }

/* Flash */
.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.flash-warning ul { margin: .5rem 0; padding-left: 1.25rem; }
.flash-warning .btn { margin-top: .5rem; }

/* Forms */
.form-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.5rem; max-width: 640px; box-shadow: var(--shadow); }
/* Same width as .page-header (full width of .main-content) — used by the acts form. */
.form-card-wide { max-width: none; width: 100%; }
.form-group { margin-bottom: 1.1rem; }
.form-group > label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .3rem; }
.checkbox-group { display: flex; flex-direction: column; gap: .35rem; margin-top: .25rem; }
.checkbox-label { display: flex; align-items: center; gap: .5rem; font-size: .9rem; font-weight: normal; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: auto; margin: 0; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: inherit;
  background: #fff;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}
.input-disabled { background: var(--color-bg) !important; color: var(--color-muted); }
.password-field { position: relative; }
.password-field input { padding-right: 2.4rem !important; }
.password-toggle {
  position: absolute;
  top: 50%;
  right: .5rem;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: .2rem;
  cursor: pointer;
  color: var(--color-muted);
}
.password-toggle:hover { color: var(--color-primary); }
.form-hint { font-size: .8rem; color: var(--color-muted); margin-top: .25rem; display: block; }
.field-error { font-size: .8rem; color: var(--color-danger); margin-top: .3rem; display: none; }
.field-error:not([hidden]) { display: block; }
.form-hint kbd { font-family: inherit; background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 3px; padding: 0 .3rem; font-size: .75rem; }
.line-counter { font-size: .75rem; font-weight: 400; color: var(--color-primary); margin-left: .5rem; }
.mismatch-warn { display: block; font-size: .82rem; color: #92400e; background: #fef3c7; border: 1px solid #fcd34d; border-radius: var(--radius); padding: .3rem .7rem; margin-bottom: .75rem; }
.merge-bar { align-items: center; gap: 1rem; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: var(--radius); padding: .6rem 1rem; margin-bottom: .75rem; font-size: .875rem; font-weight: 500; color: #1e40af; }
.form-actions { display: flex; gap: .75rem; margin-top: 1.25rem; }
.fieldset { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.1rem; }
.fieldset legend { font-size: .875rem; font-weight: 600; padding: 0 .5rem; }

/* Table */
.table { width: 100%; border-collapse: collapse; background: var(--color-surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { padding: .65rem 1rem; text-align: left; border-bottom: 1px solid var(--color-border); font-size: .875rem; }
.table th { background: var(--color-bg); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--color-muted); }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f8fafc; }
.row-cancelled td { opacity: .55; }
.actions { display: flex; gap: .4rem; flex-wrap: nowrap; }

/* Acts list: keep icons/badges on one line, scroll the table horizontally
   instead of letting cell content wrap onto a second line. */
.table-scroll { width: 100%; overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
.table-scroll .table { box-shadow: none; }
.table-scroll .table th, .table-scroll .table td { white-space: nowrap; }
.title-cell a {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* Detail card */
.detail-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.5rem; box-shadow: var(--shadow); }
.detail-row { display: flex; gap: 1rem; padding: .5rem 0; border-bottom: 1px solid var(--color-border); }
.detail-row:last-child { border-bottom: none; }
.detail-label { min-width: 160px; font-size: .8rem; font-weight: 600; color: var(--color-muted); text-transform: uppercase; letter-spacing: .04em; padding-top: .1rem; }
.pre-wrap { white-space: pre-wrap; }

/* Badges */
.badge { display: inline-block; padding: .2rem .6rem; border-radius: 9999px; font-size: .75rem; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-neutral { background: #e5e7eb; color: #374151; }
.badge-review  { background: #ffedd5; color: #9a3412; display: inline-flex; align-items: center; gap: .25rem; margin-left: .3rem; }
.badge-review svg { width: .85rem; height: .85rem; }

/* Topics */
.section { margin-top: 1.5rem; }
.section h2 { font-size: 1.1rem; margin-bottom: .75rem; }
.topics-list { padding-left: 1.25rem; }
.topics-list li { margin-bottom: .75rem; }
.comment-text { color: var(--color-muted); font-size: .875rem; margin-top: .2rem; }

/* Action bar */
.action-bar { display: flex; gap: .75rem; margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--color-border); }

/* Acta show: user comments chat panel, rendered outside <main> (see layout.ejs
   "sidePanel" content block) and floated in the margin to its right on wide screens. */
.act-comments-panel {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 1000px;
  width: calc(100% - 3rem);
  margin: 0 auto 1.5rem;
}

@media (min-width: 1700px) {
  .act-comments-panel {
    position: fixed;
    top: 6rem;
    left: calc(50% + 500px + 1.5rem);
    width: 320px;
    max-width: 320px;
    max-height: calc(100vh - 8rem);
    margin: 0;
    padding: 0;
  }
}
.act-comments-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--color-border);
}
.act-comments-panel-header h2 {
  font-size: 1rem;
}
.act-comments-panel-header form {
  margin: 0;
}
.act-comments-panel-header .btn svg {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  min-height: 3rem;
}
.chat-message {
  background: var(--color-bg);
  border-radius: 12px;
  border-top-left-radius: 3px;
  padding: .5rem .7rem;
}
.chat-message-meta { font-size: .72rem; margin-bottom: .2rem; }
.chat-message-meta strong { color: var(--color-text); margin-right: .4rem; }
.chat-message-text { font-size: .875rem; }
.chat-composer {
  display: flex;
  gap: .5rem;
  align-items: flex-end;
  padding: .75rem;
  border-bottom: 1px solid var(--color-border);
}
.chat-composer textarea {
  flex: 1;
  resize: none;
  font-family: inherit;
  font-size: .875rem;
  padding: .45rem .6rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}
.chat-composer textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}
.chat-no-permission { padding: .75rem; font-size: .8rem; border-bottom: 1px solid var(--color-border); }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--color-border); }
.pagination-links { display: flex; gap: .5rem; }
.pagination-links span[aria-disabled="true"] { opacity: .5; pointer-events: none; }

/* Folio grid */
.folio-grid { display: flex; flex-wrap: wrap; gap: .35rem; padding: .5rem 0; }
.folio-badge { display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 2rem; border-radius: var(--radius); font-size: .8rem; font-weight: 600; }
.folio-available { background: #dcfce7; color: #166534; }
.folio-used { background: #fee2e2; color: #991b1b; text-decoration: none; }
.folio-used:hover { background: #fca5a5; color: #7f1d1d; }
.folio-printed { background: #cffafe; color: #155e75; text-decoration: none; }
.folio-printed:hover { background: #a5f3fc; color: #0e3a4a; }
.folio-review { background: #ffedd5; color: #9a3412; text-decoration: none; }
.folio-review:hover { background: #fed7aa; color: #7c2d12; }
.folio-legend { display: inline-flex; align-items: center; gap: .3rem; font-size: .8rem; margin-right: .75rem; }
.folio-dot { display: inline-block; width: .75rem; height: .75rem; border-radius: .2rem; }

/* Merge modal */
.merge-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.merge-modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  width: 100%;
  max-width: 860px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.merge-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}
.merge-modal-header h2 { font-size: 1.1rem; margin: 0; }
.merge-modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-muted);
  padding: 0 .25rem;
}
.merge-modal-close:hover { color: var(--color-text); }
.merge-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
}
.merge-modal-footer {
  border-top: 1px solid var(--color-border);
  padding: .85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.merge-destination-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.merge-destination-label { font-size: .85rem; font-weight: 600; color: var(--color-muted); white-space: nowrap; }
.merge-destination-options { display: flex; gap: 1rem; flex-wrap: wrap; }
.merge-dest-option {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .875rem;
  cursor: pointer;
}
.merge-modal-actions { display: flex; gap: .5rem; margin-left: auto; }
.merge-cols {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}
.merge-col {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}
.merge-col-header {
  background: var(--color-bg);
  padding: .5rem .75rem;
  font-size: .8rem;
  font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--color-border);
}
.merge-col-body { padding: .25rem 0; }
.merge-topic-row {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  padding: .45rem .75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
}
.merge-topic-row:last-child { border-bottom: none; }
.merge-topic-row:hover { background: var(--color-bg); }
.merge-topic-row input[type="checkbox"] { margin-top: .2rem; flex-shrink: 0; }
.merge-topic-content { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.merge-topic-text { font-size: .875rem; line-height: 1.4; word-break: break-word; white-space: pre-wrap; }
.merge-topic-comment { font-size: .78rem; color: var(--color-muted); word-break: break-word; white-space: pre-wrap; }
.merge-empty { padding: .5rem .75rem; font-size: .85rem; }
.split-hint  { font-size: .85rem; color: var(--color-muted); margin-bottom: .75rem; }
.merge-topic-row--default { opacity: .55; cursor: not-allowed; background: var(--color-bg); }
.merge-topic-row--default:hover { background: var(--color-bg); }
.merge-topic-row--default input[type="checkbox"] { cursor: not-allowed; }
.merge-topic-default-tag { font-size: .72rem; color: var(--color-muted); font-style: italic; }

/* Utilities */
.text-muted  { color: var(--color-muted); font-size: .875rem; }
.text-danger { color: var(--color-danger); font-size: .875rem; }
.capitalize  { text-transform: capitalize; }
