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

:root {
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-success: #059669;
  --color-danger: #dc2626;
  --color-warning: #d97706;
  --sidebar-width: 240px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

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

a:hover {
  text-decoration: underline;
}

h1, h2, h3, h4 {
  margin: 0 0 0.5rem;
  font-weight: 600;
}

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

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--color-surface);
  color: var(--color-text);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--color-border);
}

.logo {
  color: var(--color-text);
  font-weight: 700;
  font-size: 1.125rem;
}

.logo:hover {
  text-decoration: none;
  color: var(--color-text);
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
}

.nav-item {
  display: block;
  padding: 0.625rem 1rem;
  color: var(--color-text-muted);
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: color-mix(in srgb, var(--color-primary) 10%, transparent);
  color: var(--color-text);
  text-decoration: none;
}

.nav-item.active {
  background: color-mix(in srgb, var(--color-primary) 16%, transparent);
  color: var(--color-text);
  border-left: 3px solid var(--color-primary);
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--color-border);
  font-size: 0.75rem;
}

.admin-email {
  display: block;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-link {
  color: var(--color-danger);
}

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 1.5rem 2rem;
  min-width: 0;
}

.email-page .main-content {
  padding: 0;
  background: #f8fafc;
}

.email-page .main-content > * {
  min-width: 0;
}

.auth-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--color-surface);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
}

.login-title {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-form .form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

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

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

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

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

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 14px;
}

.flash-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.flash-success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.flash-info {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

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

.page-header h1 {
  margin: 0;
}

.back-link {
  font-size: 12px;
  margin-right: 1rem;
}

.search-form {
  display: flex;
  gap: 0.5rem;
}

.search-form input,
.search-form select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 14px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--color-surface);
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-primary);
}

.stat-label {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 1.5rem;
}

.card {
  background: var(--color-surface);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.card-header h2 {
  font-size: 1rem;
  margin: 0;
}

.card-body {
  padding: 1rem 1.25rem;
}

.link {
  font-size: 12px;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  text-align: left;
  padding: 0.625rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

.table th {
  font-weight: 600;
  font-size: 12px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

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

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

.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 500;
  text-transform: capitalize;
}

.badge-success,
.badge-open,
.badge-completed {
  background: #dcfce7;
  color: #166534;
}

.badge-danger,
.badge-cancelled {
  background: #fee2e2;
  color: #b91c1c;
}

.badge-warning,
.badge-in_progress {
  background: #fef3c7;
  color: #92400e;
}

.badge-info,
.badge-pending {
  background: #dbeafe;
  color: #1e40af;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}

.page-info {
  font-size: 13px;
  color: var(--color-text-muted);
}

.detail-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
}

.detail-list dt {
  font-weight: 500;
  color: var(--color-text-muted);
}

.detail-list dd {
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.inline-form {
  display: inline;
}

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

.btn-success:hover {
  background: #047857;
}

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

.btn-warning:hover {
  background: #b45309;
}

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

.btn-danger:hover {
  background: #b91c1c;
}

.form {
  max-width: 500px;
}

.form-group {
  margin-bottom: 1rem;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-group.half {
  flex: 1;
}

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

.form-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.form-inline label {
  margin: 0;
  white-space: nowrap;
}

.form-inline select {
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 1rem 0;
}

.detail-description {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

.detail-description p {
  margin: 0.5rem 0 0;
  white-space: pre-wrap;
}

.actions {
  white-space: nowrap;
}

.actions .btn {
  margin-right: 0.25rem;
}

.actions .btn:last-child {
  margin-right: 0;
}

.text-success {
  color: var(--color-success);
}

.text-danger {
  color: var(--color-danger);
}

.text-bold {
  font-weight: 600;
}

.text-muted {
  color: var(--color-text-muted);
  font-size: 12px;
}

.nav-section {
  padding: 0.75rem 1rem 0.25rem;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  margin-top: 0.5rem;
}

.sidebar-nav {
  overflow-y: auto;
}

.nav-accordion {
  border-top: 1px solid rgba(255,255,255,0.05);
}

.nav-section-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: color 0.15s, background 0.15s;
}

.nav-section-btn:hover {
  color: #94a3b8;
  background: rgba(255,255,255,0.02);
}

.accordion-icon {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  transition: transform 0.2s;
}

.nav-accordion.open .accordion-icon {
  transform: rotate(180deg);
}

.nav-section-items {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease-out;
}

.nav-accordion.open .nav-section-items {
  max-height: 300px;
}

.nav-section-items .nav-item {
  padding-left: 1.5rem;
  font-size: 13px;
}

.header-stats {
  display: flex;
  gap: 0.5rem;
}

.stat-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 500;
}

.filter-bar {
  margin-bottom: 1rem;
}

.balance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}

.balance-section h4 {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
  letter-spacing: 0.025em;
}

.balance-row {
  display: flex;
  justify-content: space-between;
  padding: 0.375rem 0;
  font-size: 13px;
  border-bottom: 1px solid var(--color-border);
}

.balance-row:last-child {
  border-bottom: none;
}

.voided {
  opacity: 0.5;
  text-decoration: line-through;
}

.table-footer {
  background: var(--color-bg);
}

.table-footer td {
  border-top: 2px solid var(--color-border);
}

.conversation {
  margin-bottom: 1.5rem;
}

.message {
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  border-radius: 8px;
  max-width: 80%;
}

.message-user {
  background: #f1f5f9;
  margin-right: auto;
}

.message-admin {
  background: #dbeafe;
  margin-left: auto;
}

.message-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.25rem;
  font-size: 12px;
}

.message-body {
  white-space: pre-wrap;
}

.reply-form {
  border-top: 1px solid var(--color-border);
  padding-top: 1rem;
}

.action-buttons {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.input-inline {
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 13px;
  width: 200px;
}

.input-sm {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 12px;
  width: 60px;
}

.claim-actions {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.stat-sub {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.settings-card {
  display: block;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.25rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.settings-card:hover {
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  text-decoration: none;
}

.settings-card h3 {
  font-size: 1rem;
  margin: 0 0 0.5rem;
  color: var(--color-text);
}

.settings-card p {
  font-size: 13px;
  color: var(--color-text-muted);
  margin: 0 0 0.75rem;
}

.settings-count {
  font-size: 12px;
  color: var(--color-primary);
}

.settings-form {
  max-width: 600px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
}

.setting-row:last-of-type {
  border-bottom: none;
}

.setting-info {
  flex: 1;
}

.setting-info label {
  font-weight: 500;
  cursor: pointer;
}

.setting-input {
  flex: 0 0 180px;
  text-align: right;
}

.setting-input input[type="number"],
.setting-input input[type="text"],
.setting-input select {
  width: 100%;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 14px;
  text-align: right;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1;
  border-radius: 24px;
  transition: background-color 0.2s;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider {
  background-color: var(--color-primary);
}

.toggle input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 14px;
}

.alert-warning {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}

.alert-warning strong {
  font-weight: 600;
}

.password-field {
  display: flex;
  gap: 0.5rem;
}

.password-field input {
  flex: 1;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 14px;
  font-family: monospace;
}

.btn-reveal {
  padding: 0.25rem 0.5rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.btn-reveal:hover {
  background: var(--color-surface);
}

/* Neighborhood filter form */
.filter-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.filter-form .filter-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.filter-form .form-control {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--color-surface);
  color: var(--color-text);
  min-width: 140px;
}

.filter-form input[type="text"].form-control {
  flex: 2;
  min-width: 200px;
}

.filter-form select.form-control {
  flex: 1;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M2.5 4.5L6 8l3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.filter-form .form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-form .btn {
  white-space: nowrap;
}

.filter-form .btn-link {
  color: var(--color-text-muted);
  padding: 0.5rem;
}

.filter-form .btn-link:hover {
  color: var(--color-danger);
}

.hidden {
  display: none !important;
}
