:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --sidebar-bg: #1d1d1b;
  --sidebar-text: #d8d8d6;
  --accent: #00c853;
  --accent-dark: #00a844;
  --text: #1d1d1b;
  --text-muted: #6b6b6b;
  --border: #e3e6e4;
  --danger: #d64545;
  --danger-dark: #b93a3a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
}

.sidebar__logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 20px;
}

.sidebar__logo img {
  height: 22px;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--sidebar-text);
  font-size: 14px;
  transition: background 0.15s ease;
}

.sidebar__link:hover {
  background: rgba(255, 255, 255, 0.06);
}

.sidebar__link.active {
  background: var(--accent);
  color: #06210f;
  font-weight: 600;
}

.sidebar__footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 16px;
  font-size: 12px;
}

.sidebar__footer form {
  margin-top: 8px;
}

.sidebar__footer button {
  background: none;
  border: none;
  color: #ff8a8a;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  margin-left: 240px;
  padding: 32px 40px;
  max-width: 1200px;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.page-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-badge {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 600;
}

.tab-hint {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 16px;
}

/* ---------- KPI cards ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  display: block;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

.kpi-card__label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.kpi-card__value {
  font-size: 32px;
  font-weight: 700;
}

.kpi-card__hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--accent-dark);
  font-weight: 600;
}

/* ---------- Table ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.toolbar input[type='search'] {
  flex: 1;
  max-width: 320px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: #06210f;
}

.btn-primary:hover {
  background: var(--accent-dark);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-dark);
}

.btn-row-delete {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 15px;
  cursor: pointer;
  color: var(--danger);
}

.btn-row-delete:hover {
  background: #fdecea;
  border-color: #f0c8bd;
}

.btn-row-cancel {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 15px;
  cursor: pointer;
  color: var(--text-muted);
}

.btn-row-cancel:hover {
  background: var(--bg);
  border-color: var(--border);
}

.id-cell {
  font-family: monospace;
  font-size: 12px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.bulk-bar {
  display: none;
  align-items: center;
  gap: 12px;
  background: #fff4f0;
  border: 1px solid #f0c8bd;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 14px;
}

.bulk-bar.visible {
  display: flex;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  text-align: left;
  background: var(--bg);
  padding: 12px 14px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr.row-clickable {
  cursor: pointer;
}

tbody tr.row-clickable:hover {
  background: #fafcfb;
}

.agency-tag {
  display: inline-block;
  background: #eef7f0;
  color: #1f7a3d;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  margin: 2px 4px 2px 0;
}

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

.pagination {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- Modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 560px;
  max-width: 92vw;
  max-height: 86vh;
  overflow-y: auto;
  padding: 24px;
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.modal__close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 20px;
  margin-bottom: 16px;
}

.detail-grid__full {
  grid-column: 1 / -1;
}

.detail-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.detail-value {
  font-size: 14px;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

/* ---------- Notifications page ---------- */
.template-sections {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

.template-column {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

@media (max-width: 900px) {
  .template-sections {
    grid-template-columns: 1fr;
  }
}

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.template-title {
  font-size: 16px;
  margin: 0 0 16px;
}

.template-column-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin: 0 0 4px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

.form-group textarea {
  min-height: 200px;
  resize: vertical;
}

.placeholders {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.placeholder-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
  font-family: monospace;
}

.placeholder-chip:hover {
  background: #eef7f0;
  border-color: #bfe6cb;
}

.preview-box {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 16px;
  background: var(--bg);
  margin-top: 10px;
  font-size: 14px;
}

.preview-box__subject {
  font-weight: 700;
  margin-bottom: 10px;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1d1d1b;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 100;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: var(--danger);
}

/* ---------- Login ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-bg);
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 36px;
  width: 360px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.login-card__logo {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.login-card h1 {
  font-size: 18px;
  text-align: center;
  margin: 0 0 20px;
}

.login-card .form-group {
  margin-bottom: 14px;
}

.login-error {
  background: #fdecea;
  color: var(--danger-dark);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

.login-card button {
  width: 100%;
  margin-top: 6px;
}
