:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --ink: #1a1816;
  --muted: #5c5650;
  --subtle: #8a837a;
  --line: #e4dfd7;
  --accent: #2d4a3e;
  --accent-soft: #e8f0ec;
  --danger: #9b2c2c;
  --warn: #9a6b2f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(26, 24, 22, 0.06);
  --font: "DM Sans", "Segoe UI", system-ui, sans-serif;
}

html[data-theme="dark"] {
  --bg: #141312;
  --surface: #1e1c1a;
  --ink: #f2efe9;
  --muted: #b7b0a6;
  --subtle: #8a837a;
  --line: #35312c;
  --accent: #6f9b88;
  --accent-soft: #24342d;
  --danger: #e07a7a;
  --warn: #d4a35c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
}

.brand span {
  color: var(--subtle);
  font-weight: 400;
  margin-left: 0.4rem;
  font-size: 0.9rem;
}

.nav {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.nav a,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover,
.nav a:hover {
  background: var(--accent-soft);
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  filter: brightness(1.05);
  background: var(--accent);
  color: #fff;
}

.btn-danger {
  color: var(--danger);
  border-color: #efc2c2;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem;
}

.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.messages li {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid #c9ddd2;
  margin-bottom: 0.5rem;
}

.messages .warning {
  background: #fff7eb;
  border-color: #f0d9b0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
  align-items: end;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.input,
.textarea,
.select,
input[type="file"],
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
select,
textarea {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  min-width: 0;
}

.textarea,
textarea {
  min-height: 90px;
  resize: vertical;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  text-align: left;
  padding: 0.7rem 0.6rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--subtle);
  font-weight: 600;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #eeeae4;
  color: var(--muted);
}

.badge.open {
  background: #e8f0ec;
  color: var(--accent);
}

.badge.follow_up {
  background: #fff3df;
  color: var(--warn);
}

.badge.closed {
  background: #ececec;
  color: var(--subtle);
}

.muted {
  color: var(--muted);
}

.subtle {
  color: var(--subtle);
  font-size: 0.85rem;
}

.stack {
  display: grid;
  gap: 1rem;
}

.grid-2 {
  display: grid;
  gap: 1rem;
}

@media (min-width: 900px) {
  .grid-2 {
    grid-template-columns: 1.1fr 0.9fr;
  }
}

.note {
  border-left: 3px solid var(--accent);
  padding: 0.75rem 0.9rem;
  background: #fbfaf8;
  border-radius: 0 8px 8px 0;
}

.note-meta {
  font-size: 0.8rem;
  color: var(--subtle);
  margin-bottom: 0.35rem;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-card {
  width: min(400px, 100%);
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
  font-weight: 600;
}

.form-grid {
  display: grid;
  gap: 0.85rem;
}

.form-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.page-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.page-title h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

.year-pills {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.year-pills a {
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}

.year-pills a.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.75rem 0;
}

.page-size-pills {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.page-size {
  min-width: 2.4rem;
  text-align: center;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
  background: var(--surface);
}

.page-size:hover,
.page-size.active {
  text-decoration: none;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.page-num {
  min-width: 2.2rem;
  text-align: center;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
  background: var(--surface);
}

.page-num:hover {
  text-decoration: none;
  background: var(--accent-soft);
}

.page-num.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.th-sort {
  color: var(--subtle);
  text-decoration: none;
  white-space: nowrap;
}

.th-sort:hover {
  color: var(--ink);
  text-decoration: none;
}

html[data-theme="dark"] .input,
html[data-theme="dark"] .textarea,
html[data-theme="dark"] .select,
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: #171513;
  color: var(--ink);
  border-color: var(--line);
}

html[data-theme="dark"] .note {
  background: #181614;
}

html[data-theme="dark"] .btn-primary {
  color: #141312;
}
