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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: #1a1a2e;
  background: #f5f6fa;
  min-height: 100vh;
}

/* ---- Login ---- */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 16px rgba(0,0,0,.12);
  padding: 40px 48px;
  width: 340px;
}
.login-box h1 { font-size: 1.4rem; margin-bottom: 24px; color: #1a1a2e; }
.error { color: #c0392b; font-size: 13px; margin-bottom: 12px; }

/* ---- App shell ---- */
.app { display: flex; flex-direction: column; min-height: 100vh; }

.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #1a1a2e;
  color: #fff;
  padding: 12px 20px;
}
.app-header h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.05em; white-space: nowrap; }

.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  background: transparent;
  border: none;
  color: rgba(255,255,255,.65);
  cursor: pointer;
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { background: rgba(255,255,255,.1); color: #fff; }
.tab.active { background: rgba(255,255,255,.18); color: #fff; }

.logout-btn {
  color: rgba(255,255,255,.6);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 4px;
}
.logout-btn:hover { color: #fff; background: rgba(255,255,255,.1); }

.app-main { flex: 1; padding: 20px; }

/* ---- View ---- */
.view { display: flex; flex-direction: column; gap: 12px; }

.view-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.toolbar-title { font-weight: 600; font-size: 15px; }

.filter-tabs { display: flex; gap: 4px; }
.filter-tab {
  background: #fff;
  border: 1px solid #dde;
  color: #444;
  cursor: pointer;
  padding: 5px 14px;
  border-radius: 4px;
  font-size: 13px;
}
.filter-tab:hover { border-color: #aab; }
.filter-tab.active { background: #1a1a2e; color: #fff; border-color: #1a1a2e; }

/* ---- Grid ---- */
.grid-container { overflow-x: auto; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }

.grid {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}
.grid th {
  background: #f0f1f6;
  padding: 8px 10px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: #555;
  border-bottom: 1px solid #e0e2ee;
  white-space: nowrap;
}
.grid th.sortable { cursor: pointer; user-select: none; }
.grid th.sortable:hover { background: #e4e5ef; }
.sort-indicator { margin-left: 3px; font-size: 10px; }
.grid td {
  padding: 7px 10px;
  border-bottom: 1px solid #eef;
  vertical-align: top;
}
.grid-row { cursor: pointer; }
.grid-row:hover { background: #f7f8ff; }
.grid-row.snoozed { opacity: 0.5; }
.grid-row.archived { color: #999; background: #f8f8f8; text-decoration: line-through; }
.grid-row.archived:hover { background: #f0f0f2; }
.grid-row.archived .rv-chip { opacity: 0.6; }
.grid-row.archived .chip { opacity: 0.6; }

.archive-section-divider td {
  background: #eef0f7;
  color: #666;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-top: 2px solid #d8dae8;
  border-bottom: 1px solid #d8dae8;
}
.desc-cell { max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { color: #888; text-align: center; padding: 24px; }

/* ---- Archive toggle & load-more ---- */
.btn-archive-toggle { font-size: 12px; padding: 5px 12px; }
.btn-archive-toggle.active { background: #f0f1f6; border-color: #aab; }

.archive-load-more {
  display: flex;
  justify-content: center;
  padding: 10px 0 2px;
}
.archive-loading, .archive-end { font-size: 13px; color: #999; }

.archived-label { font-size: 13px; color: #888; }

/* ---- Chips & badges ---- */
.type-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  background: #e8eaf0;
  color: #444;
}
.chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: #eee;
  color: #666;
}
.chip.done { background: #d4edda; color: #155724; }

.rv-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 12px;
}
.rv-chip.large { font-size: 16px; padding: 4px 12px; }
.rv-low { background: #d4edda; color: #155724; }
.rv-mid { background: #fff3cd; color: #856404; }
.rv-high { background: #f8d7da; color: #721c24; }

/* ---- Buttons ---- */
.btn-primary {
  background: #1a1a2e;
  color: #fff;
  border: none;
  padding: 7px 16px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.btn-primary:hover { background: #2d2d4e; }
.btn-primary:disabled { opacity: .6; cursor: default; }

.btn-secondary {
  background: #fff;
  color: #1a1a2e;
  border: 1px solid #ccd;
  padding: 7px 16px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
}
.btn-secondary:hover { background: #f0f1f6; }

.btn-danger {
  background: #fff;
  color: #c0392b;
  border: 1px solid #e9b8b5;
  padding: 7px 14px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
}
.btn-danger:hover { background: #fdf0ef; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: #fff;
  border-radius: 8px;
  width: 640px;
  max-width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #eef;
}
.modal-header h2 { font-size: 1rem; font-weight: 600; }
.close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #888;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
}
.close-btn:hover { background: #f0f1f6; color: #444; }

.modal-body { padding: 20px; overflow-y: auto; flex: 1; }

.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid #eef;
}
.spacer { flex: 1; }

/* ---- Form ---- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field.wide { grid-column: 1 / -1; }
.field.checkbox { flex-direction: row; align-items: center; gap: 8px; grid-column: 1 / -1; }
.field.checkbox input { width: auto; }

.field > span, .field > label { font-size: 12px; font-weight: 500; color: #555; }

.field input[type="text"],
.field input[type="date"],
.field input[type="number"],
.field select,
.field textarea {
  border: 1px solid #ccd;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  color: #1a1a2e;
  background: #fff;
  width: 100%;
}
.field textarea { resize: vertical; }
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: #1a1a2e;
  box-shadow: 0 0 0 2px rgba(26,26,46,.1);
}

/* ---- Detail view ---- */
.detail-view { display: flex; flex-direction: column; gap: 14px; }

.detail-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-back {
  background: none;
  border: none;
  cursor: pointer;
  color: #1a1a2e;
  font-size: 13px;
  padding: 5px 10px;
  border-radius: 4px;
}
.btn-back:hover { background: #e8eaf0; }

.detail-actions { display: flex; gap: 8px; margin-left: auto; }

.detail-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  padding: 24px 28px;
}

/* ---- Risk document ---- */
.risk-doc { display: flex; flex-direction: column; gap: 16px; }

.risk-doc-meta { display: flex; align-items: center; gap: 10px; }
.risk-doc-category { font-size: 13px; color: #888; }

.risk-doc-area { font-size: 1.3rem; font-weight: 700; color: #1a1a2e; }

.risk-doc-field { display: flex; flex-direction: column; gap: 4px; }
.risk-doc-field > label { font-size: 11px; font-weight: 600; color: #888; text-transform: uppercase; letter-spacing: 0.04em; }
.risk-doc-field > p { font-size: 14px; color: #1a1a2e; margin: 0; white-space: pre-wrap; }

.risk-doc-stats { display: flex; flex-wrap: wrap; gap: 20px; }
.risk-doc-stat { display: flex; flex-direction: column; gap: 4px; }
.risk-doc-stat > label { font-size: 11px; font-weight: 600; color: #888; text-transform: uppercase; letter-spacing: 0.04em; }
.risk-doc-stat > span { font-size: 14px; }

.risk-doc-saved { font-size: 12px; color: #aab; margin-top: 4px; }

/* ---- History ---- */
.history-toggle-row { display: flex; }

.btn-history {
  background: none;
  border: 1px solid #dde;
  cursor: pointer;
  color: #555;
  font-size: 13px;
  padding: 5px 14px;
  border-radius: 4px;
}
.btn-history:hover { background: #f0f1f6; border-color: #aab; }

.history-list {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  overflow: hidden;
}

.history-entry { border-bottom: 1px solid #eef; }
.history-entry:last-child { border-bottom: none; }

.history-entry-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 13px;
}
.history-entry-row:hover { background: #f7f8ff; }

.history-entry-header {
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: #1a1a2e;
  background: #f0f1f6;
  border-bottom: 1px solid #dde;
}
.history-entry-header:hover { background: #e8eaf0; }

.history-entry-body { padding: 16px 20px; }

.history-arrow { color: #aab; font-size: 11px; flex-shrink: 0; }
.history-date { font-size: 12px; color: #888; white-space: nowrap; flex-shrink: 0; min-width: 80px; }
.history-desc { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; color: #444; }
.history-stat { font-size: 12px; color: #666; white-space: nowrap; flex-shrink: 0; }
.history-responsible { font-size: 12px; color: #666; white-space: nowrap; flex-shrink: 0; }
.history-date-col { font-size: 12px; color: #888; white-space: nowrap; flex-shrink: 0; }

/* ---- Comments ---- */
.comments-section { display: flex; flex-direction: column; gap: 0; margin-top: 4px; }

.comments-header {
  font-size: 13px;
  font-weight: 600;
  color: #555;
  padding: 8px 0 6px;
}

.comments-list {
  background: #fff;
  border-radius: 8px 8px 0 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  overflow: hidden;
}

.comment {
  padding: 10px 16px;
  border-bottom: 1px solid #eef;
}
.comment:last-child { border-bottom: none; }

.comment-header { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.comment-source { font-size: 12px; font-weight: 600; color: #1a1a2e; }
.comment-time { font-size: 12px; color: #aab; }
.comment-body { font-size: 13px; color: #333; white-space: pre-wrap; }

.comment-form {
  background: #fff;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 2px solid #eef0f7;
}

.comment-source-input,
.comment-body-input {
  border: 1px solid #ccd;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  color: #1a1a2e;
  background: #fff;
  width: 100%;
}
.comment-body-input { resize: vertical; }
.comment-source-input:focus,
.comment-body-input:focus {
  outline: none;
  border-color: #1a1a2e;
  box-shadow: 0 0 0 2px rgba(26,26,46,.1);
}

.comment-form-actions { display: flex; justify-content: flex-end; }

/* ---- Minutes ---- */
.minutes-date-select {
  border: 1px solid #ccd;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  color: #1a1a2e;
  background: #fff;
  cursor: pointer;
}
.minutes-date-select:focus { outline: none; border-color: #1a1a2e; }

.minutes-loading { font-size: 13px; color: #888; padding: 40px; text-align: center; }

.minutes-result {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  padding: 24px 28px;
}

/* ---- Markdown rendered output ---- */
.markdown { font-size: 13px; color: #1a1a2e; line-height: 1.7; }
.markdown > *:last-child { margin-bottom: 0; }
.markdown h1 { font-size: 1.15rem; font-weight: 700; margin: 0 0 12px; }
.markdown h2 { font-size: 1rem; font-weight: 700; margin: 20px 0 8px; }
.markdown h3 { font-size: 0.9rem; font-weight: 700; margin: 16px 0 6px; color: #444; }
.markdown p { margin: 0 0 10px; }
.markdown ul, .markdown ol { margin: 0 0 10px; padding-left: 22px; }
.markdown li { margin: 3px 0; }
.markdown strong { font-weight: 700; }
.markdown em { font-style: italic; }
.markdown code { font-family: monospace; background: #f0f1f6; padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.markdown pre { background: #f0f1f6; padding: 12px; border-radius: 4px; overflow-x: auto; margin: 0 0 10px; }
.markdown pre code { background: none; padding: 0; }
.markdown blockquote { border-left: 3px solid #dde; padding-left: 12px; color: #666; margin: 0 0 10px; }
.markdown hr { border: none; border-top: 1px solid #eef; margin: 18px 0; }

.minutes-unavailable {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  font-size: 13px;
  color: #888;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.minutes-unavailable code {
  font-family: monospace;
  background: #f0f1f6;
  padding: 2px 5px;
  border-radius: 3px;
  color: #1a1a2e;
}

/* ---- Documents ---- */
.doc-search {
  border: 1px solid #ccd;
  border-radius: 5px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  min-width: 220px;
  flex: 1;
}
.view-toolbar > select {
  border: 1px solid #ccd;
  border-radius: 5px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
}

.doc-status {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
}
.doc-status-draft { background: #fff3cd; color: #856404; }
.doc-status-published { background: #d4edda; color: #155724; }
.doc-status-archived { background: #e8eaf0; color: #777; }

.draft-marker { color: #d39e00; margin-left: 6px; font-size: 11px; vertical-align: middle; }

.review-overdue, td.review-overdue { color: #c0392b; font-weight: 600; }
.doc-meta-grid .review-overdue span { color: #c0392b; }

/* Detail */
.doc-detail-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.doc-detail-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.doc-detail-head h2 { font-size: 1.25rem; font-weight: 600; }
.doc-number { color: #1a1a2e; font-weight: 700; margin-right: 4px; }

.doc-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px 18px;
  background: #fff;
  border-radius: 6px;
  padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.doc-meta-grid > div { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.doc-meta-grid > div > span { font-size: 11px; font-weight: 600; color: #888; text-transform: uppercase; letter-spacing: 0.04em; }

.doc-archived-reason { color: #856404; background: #fff8e6; padding: 8px 12px; border-radius: 5px; font-size: 13px; }

.doc-content {
  background: #fff;
  border-radius: 6px;
  padding: 20px 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.doc-section {
  background: #fff;
  border-radius: 6px;
  padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.doc-section h3 { font-size: 14px; font-weight: 600; margin-bottom: 10px; color: #333; }

.sub-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sub-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: #888;
  padding: 4px 8px;
  border-bottom: 1px solid #eef;
}
.sub-table td { padding: 6px 8px; border-bottom: 1px solid #f2f2f7; vertical-align: top; }
.sub-actions { white-space: nowrap; text-align: right; }

.link-btn {
  background: none;
  border: none;
  color: #2d2d7e;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: #c0392b; }

.event-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.event-list li { display: flex; gap: 10px; font-size: 13px; align-items: baseline; flex-wrap: wrap; }
.event-time { color: #999; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.event-type { font-weight: 600; color: #333; }
.event-actor { color: #2d2d7e; }
.event-desc { color: #666; }

.attachment-list { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.attachment-list li { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.attachment-list a { color: #2d2d7e; text-decoration: none; font-weight: 500; }
.attachment-list a:hover { text-decoration: underline; }
.att-desc { color: #888; }
.attachment-upload { display: flex; gap: 8px; align-items: center; }
.attachment-upload input[type="text"] {
  border: 1px solid #ccd;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  flex: 1;
}
.file-btn { display: inline-block; }

/* Markdown editor with live preview */
.modal-wide { width: 900px; }
.modal-small { width: 440px; }
.md-editor { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.md-editor-pane { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.md-preview {
  border: 1px solid #eef;
  border-radius: 4px;
  padding: 10px 14px;
  overflow-y: auto;
  max-height: 360px;
  background: #fafafe;
}
.dialog-note { font-size: 12px; color: #888; margin-bottom: 12px; }
.modal-small .field { margin-bottom: 12px; }
