@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=Source+Serif+4:opsz,wght@8..60,500;8..60,600&display=swap');

:root {
  --bg-main: #FFFFFF;
  --bg-secondary: #F7F7FA;
  --text: #25233A;
  --text-muted: #6B6980;
  --violet: #6C4DE6;
  --violet-dark: #5B3FD1;
  --blue-violet: #5667E8;
  --border: #E7E7EF;
  --green: #1F9D6E;
  --green-bg: #E7F7F0;
  --amber: #B8862A;
  --amber-bg: #FBF2E1;
  --red: #C6423E;
  --red-bg: #FBEAE9;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-card: 0 1px 2px rgba(37, 35, 58, 0.04), 0 1px 8px rgba(37, 35, 58, 0.03);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: 'Source Serif 4', Georgia, serif;
  font-weight: 600;
  margin: 0 0 4px 0;
  color: var(--text);
}
h1 { font-size: 26px; letter-spacing: -0.01em; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

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

button, input, select, textarea {
  font-family: inherit;
  font-size: 14px;
}

/* --- Layout --- */

#app { min-height: 100vh; }

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #F7F7FA 0%, #EFEBFB 100%);
  padding: 24px;
}

.auth-card {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.auth-brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 28px;
}
.auth-brand .mark { font-size: 22px; }
.auth-brand .name { font-family: 'Source Serif 4', serif; font-weight: 600; font-size: 19px; }
.auth-brand .sub { color: var(--text-muted); font-size: 13px; }

.app-shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-main);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px 20px 10px;
}
.sidebar .brand .mark { font-size: 20px; }
.sidebar .brand .name { font-family: 'Source Serif 4', serif; font-weight: 600; font-size: 16px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
}
.nav-link:hover { background: var(--bg-secondary); text-decoration: none; }
.nav-link.active { background: #F0ECFC; color: var(--violet-dark); }
.nav-section-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
  padding: 16px 12px 4px 12px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.sidebar-user { padding: 8px 10px; }
.sidebar-user .name { font-weight: 600; font-size: 13.5px; }
.sidebar-user .role { color: var(--text-muted); font-size: 12px; }

.main {
  padding: 28px 36px 60px 36px;
  max-width: 1180px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.search-input {
  width: 280px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
}
.search-input:focus { outline: 2px solid var(--violet); outline-offset: -1px; background: white; }

/* --- Components --- */

.card {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.card + .card { margin-top: 16px; }

.grid-cols {
  display: grid;
  gap: 16px;
}
.grid-cols.n2 { grid-template-columns: 1fr 1fr; }
.grid-cols.n3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols.n5 { grid-template-columns: repeat(5, 1fr); }

.stat-card {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-card .value { font-family: 'Source Serif 4', serif; font-size: 28px; font-weight: 600; color: var(--violet-dark); }
.stat-card .label { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  background: var(--violet);
  color: white;
  transition: background 0.12s ease;
}
.btn:hover { background: var(--violet-dark); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: white; color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--bg-secondary); }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #A8332F; }
.btn.ghost { background: transparent; color: var(--violet-dark); padding: 6px 10px; }
.btn.ghost:hover { background: #F0ECFC; }
.btn.small { padding: 6px 12px; font-size: 12.5px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text);
}
.field .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=file], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--violet); outline-offset: -1px; }
textarea { resize: vertical; min-height: 80px; }
input:disabled, select:disabled, textarea:disabled { background: var(--bg-secondary); color: var(--text-muted); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.neutral { background: var(--bg-secondary); color: var(--text-muted); }
.badge.violet { background: #F0ECFC; color: var(--violet-dark); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 12px;
  text-transform: none;
  color: var(--text-muted);
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--bg-secondary); }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 16px;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--violet-dark); border-bottom-color: var(--violet); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.timeline { display: flex; flex-direction: column; gap: 2px; }
.timeline-item {
  display: flex;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-icon {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--bg-secondary);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}
.timeline-time { font-size: 11.5px; color: var(--text-muted); margin-bottom: 2px; }
.timeline-body { font-size: 14px; }
.timeline-author { font-weight: 700; }

.message-composer {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  align-items: flex-start;
}
.message-composer textarea { flex: 1; min-height: 44px; }

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--text);
  color: white;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.18);
  max-width: 340px;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(37, 35, 58, 0.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
  padding: 20px;
}
.modal {
  background: white;
  border-radius: var(--radius);
  padding: 26px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.filters-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.filters-bar select, .filters-bar input { width: auto; min-width: 150px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  gap: 16px;
}
.page-header .subtitle { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.kv-item .kv-label { font-size: 12px; color: var(--text-muted); }
.kv-item .kv-value { font-size: 14.5px; font-weight: 600; margin-top: 2px; }

.doc-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.doc-row:last-child { border-bottom: none; }
.doc-name { font-weight: 600; font-size: 14px; }
.doc-meta { font-size: 12px; color: var(--text-muted); }

.locked-field-row { display: flex; align-items: center; gap: 8px; }
.locked-field-row input { flex: 1; }

.link-row { display: flex; align-items: center; gap: 8px; }
.copy-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: monospace;
  font-size: 12.5px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spinner {
  border: 2px solid var(--border);
  border-top-color: var(--violet);
  border-radius: 50%;
  width: 20px; height: 20px;
  animation: spin 0.7s linear infinite;
  margin: 30px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 18px; }
  .grid-cols.n3, .grid-cols.n5, .grid-cols.n2 { grid-template-columns: 1fr; }
}
