:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e2e4e9;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #2f6feb;
  --accent-dark: #2255c4;
  --danger: #d64545;
  --success: #1f9d55;
  --radius: 10px;
}

html[data-theme="dark"] {
  --bg: #14161c;
  --card: #1d2027;
  --border: #2d313b;
  --text: #e8e9ed;
  --muted: #9aa0ac;
  --accent: #4f8cff;
  --accent-dark: #6ea1ff;
  --danger: #f0645f;
  --success: #35c46a;
}
html[data-theme="dark"] .progress-track { background: #2a2e37; }
html[data-theme="dark"] .badge { background: #1f2b4d; }
html[data-theme="dark"] .badge-paid { background: #123b25; }
html[data-theme="dark"] .field-list code { background: #262b35; }

body {
  transition: background-color .15s ease, color .15s ease;
}


* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.brand { font-weight: 600; font-size: 1.05rem; }

.topbar nav a {
  color: var(--text);
  text-decoration: none;
  margin-left: 18px;
  font-size: 0.92rem;
}
.topbar nav a:hover { color: var(--accent); }
.topbar nav a.logout { color: var(--danger); }
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  padding: 0;
  margin-left: 14px;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
}
.theme-toggle:hover { background: var(--bg); }

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

h1 { font-size: 1.5rem; margin-bottom: 6px; }
h2 { font-size: 1.15rem; margin-top: 28px; }
.subtitle { color: var(--muted); margin-top: 0; margin-bottom: 24px; }

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

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }

.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}
.stat .num { font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.stat .label { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: #fafbfc; }

a.button, button, input[type="submit"] {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 0.92rem;
  text-decoration: none;
  cursor: pointer;
}
a.button:hover, button:hover { background: var(--accent-dark); }
a.button.secondary, button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
a.button.secondary:hover { background: #f0f1f3; }
button.danger, a.button.danger { background: var(--danger); }

form.inline { display: inline; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 12px 0 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="file"], textarea, select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }

.actions { margin-top: 20px; display: flex; gap: 10px; }
.actions-center { justify-content: center; flex-wrap: wrap; }
.nowrap-money { white-space: nowrap; }

.collapsible-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: transparent;
  border: none;
  padding: 16px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.collapsible-toggle:hover { background: var(--bg); }

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.preview-title { font-weight: 600; }
.preview-buttons { display: flex; gap: 8px; }
.preview-frame-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  height: 80vh;
}
.preview-frame { width: 100%; height: 100%; border: none; }

.notes-list { margin-top: 18px; }
.note-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}
.note-summary {
  padding: 10px 12px;
  cursor: pointer;
}
.note-summary:hover { background: var(--bg); }
.note-meta { color: var(--muted); font-size: 0.78rem; }
.note-preview {
  font-weight: 600;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-full {
  display: none;
  padding: 0 12px 12px;
  border-top: 1px solid var(--border);
}
.note-full.open { display: block; padding-top: 12px; }

.pagination { display: flex; gap: 6px; margin-top: 14px; }
.pagination a {
  display: inline-block;
  min-width: 28px;
  text-align: center;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
}
.pagination a.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pagination a:hover:not(.active) { background: var(--bg); }

table.table-fixed { table-layout: fixed; width: 100%; }
table.table-fixed td { overflow-wrap: break-word; }
.doc-row { white-space: nowrap; margin-bottom: 4px; }
.contract-actions { display: flex; gap: 4px; flex-wrap: nowrap; }
.contract-actions .button, .contract-actions button {
  padding: 4px 9px;
  font-size: 0.85rem;
}

.flashes { margin-bottom: 18px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-size: 0.9rem; }
.flash-success { background: #e5f7ea; color: var(--success); }
.flash-error { background: #fdeaea; color: var(--danger); }

.badge {
  display: inline-block;
  background: #eef2ff;
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.78rem;
}

.empty { color: var(--muted); font-style: italic; padding: 20px 0; }

.searchbar { margin-bottom: 16px; display: flex; gap: 10px; }
.searchbar input { flex: 1; }

.login-wrap {
  max-width: 380px;
  margin: 80px auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px;
}
.login-wrap h1 { text-align: center; }

.field-list { list-style: none; padding: 0; margin: 8px 0; }
.field-list li { padding: 4px 0; font-size: 0.9rem; }
.field-list code { background: #f0f1f3; padding: 2px 6px; border-radius: 4px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.progress-track {
  margin-top: 14px;
  height: 10px;
  border-radius: 999px;
  background: #eef0f3;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width .3s ease;
}
.progress-fill.over { background: var(--danger); }

.badge-paid {
  background: #e5f7ea;
  color: var(--success);
}

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 40px;
  padding: 22px 20px 30px;
}
.footer-inner {
  max-width: 1000px;
  margin: 0 auto;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}
.footer-line { margin-top: 4px; }
.footer-line:first-child { margin-top: 0; font-weight: 600; color: var(--text); }
.footer-inner a { color: inherit; text-decoration: none; }
.footer-inner a:hover { color: var(--accent); text-decoration: underline; }
.footer-version { color: var(--muted); font-size: 0.78rem; }
@media (max-width: 700px) {
  .two-col { grid-template-columns: 1fr; }
  .topbar nav a { margin-left: 0; margin-right: 14px; }
}
