@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #090d16;
  --panel: #111827;
  --panel-hover: #1f2937;
  --ink: #f3f4f6;
  --muted: #9ca3af;
  --line: #374151;
  --accent: #10b981;
  --accent-dark: #059669;
  --good: #34d399;
  --bad: #f87171;
  --warning: #fbbf24;
  --accent-rgb: 16, 185, 129;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

aside {
  background: #0f172a;
  color: #ffffff;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}

aside h1 {
  margin: 0 0 28px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

aside h1::before {
  content: "📊";
  font-size: 22px;
}

nav {
  display: grid;
  gap: 8px;
}

nav a {
  color: #94a3b8;
  text-decoration: none;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 10px;
}

nav a:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #f8fafc;
}

nav a.active {
  background: rgba(16, 185, 129, 0.15);
  color: var(--good);
  font-weight: 600;
}

main {
  padding: 32px;
  overflow-y: auto;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

section {
  margin-bottom: 32px;
}

h2, h3 {
  margin: 0;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 28px;
  font-weight: 700;
}

h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  color: #f3f4f6;
}

p {
  margin: 8px 0 0;
}

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
  margin-bottom: 28px;
}

.titlebar p,
.muted {
  color: var(--muted);
  font-size: 13.5px;
}

.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--accent);
  color: #ffffff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.button:hover,
button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.button:active,
button:active {
  transform: translateY(0);
}

.button.secondary {
  background: #374151;
  color: #f3f4f6;
  border: 1px solid var(--line);
}

.button.secondary:hover {
  background: #4b5563;
}

.button.danger {
  background: #ef4444;
}

.button.danger:hover {
  background: #dc2626;
}

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

.metrics div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.metrics div:hover {
  transform: translateY(-2px);
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.metrics strong {
  display: block;
  font-size: 24px;
  font-weight: 700;
  color: #ffffff;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 28px;
  margin-bottom: 28px;
}

.dashboard-grid.second-row {
  grid-template-columns: 1fr 1fr;
}

.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stats-panel .metrics {
  grid-template-columns: repeat(2, 1fr);
}

.chart-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  height: 380px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.chart-panel canvas {
  display: block;
  width: 100% !important;
  height: 300px !important;
  max-height: 300px;
  flex: 1 1 auto;
}

.good {
  color: var(--good) !important;
}

.bad {
  color: var(--bad) !important;
}

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
  margin-bottom: 24px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #1f2937;
  color: #e5e7eb;
  font-weight: 600;
  user-select: none;
  letter-spacing: -0.01em;
}

th::after {
  content: " \2195";
  opacity: 0.3;
  font-size: 10px;
}

th[data-order="asc"]::after {
  content: " \2193";
  opacity: 1;
  color: var(--accent);
}

th[data-order="desc"]::after {
  content: " \2191";
  opacity: 1;
  color: var(--accent);
}

tr {
  transition: background 0.15s ease;
}

tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

tr:last-child td {
  border-bottom: 0;
}

tr.issue-row td {
  background: rgba(239, 68, 68, 0.08);
}

tr.issue-row td:nth-child(2),
tr.issue-row td:nth-child(5),
tr.issue-row td:nth-child(8) {
  color: var(--bad);
  font-weight: 600;
}

tr.missing-row td {
  background: rgba(251, 191, 36, 0.08);
  color: #f59e0b;
}

.audit-details {
  margin-bottom: 16px;
}

.audit-details summary {
  cursor: pointer;
  padding: 14px 18px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 12px;
  font-weight: 600;
  transition: all 0.2s ease;
  color: #fca5a5;
  outline: none;
}

.audit-details summary:hover {
  background: rgba(239, 68, 68, 0.12);
}

.audit-details .table-wrap {
  margin-top: 12px;
}

.filters,
.edit-form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
}

.filters {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.filters input {
  max-width: 380px;
}

.report-filters select {
  max-width: 200px;
}

.operation-filters {
  flex-wrap: wrap;
}

.operation-filters select {
  max-width: 200px;
}

.edit-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 18px;
  max-width: 900px;
}

label {
  display: grid;
  gap: 8px;
  color: #e5e7eb;
  font-size: 13px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  font: inherit;
  background: #1f2937;
  transition: all 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

textarea {
  min-height: 100px;
  resize: vertical;
}

.edit-form button {
  width: max-content;
  align-self: end;
}

.notice {
  max-width: 900px;
  margin-bottom: 20px;
  padding: 14px 18px;
  border: 1px solid rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.08);
  border-radius: 12px;
  color: #34d399;
  font-size: 14px;
}

.ai-chat {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.ai-chat-toggle {
  width: 56px;
  height: 56px;
  min-height: 56px;
  border-radius: 50%;
  padding: 0;
  font-size: 16px;
}

.ai-chat-panel {
  width: min(420px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 112px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ai-chat-panel[hidden] {
  display: none;
}

.ai-chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #1f2937;
}

.ai-chat-header strong,
.ai-chat-header span {
  display: block;
}

.ai-chat-header span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.ai-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-chat .message {
  max-width: 86%;
  padding: 12px 14px;
  border-radius: 12px;
  line-height: 1.45;
  font-size: 14px;
  border: 1px solid var(--line);
}

.ai-chat .ai-message {
  align-self: flex-start;
  background: #1f2937;
}

.ai-chat .user-message {
  align-self: flex-end;
  background: rgba(16, 185, 129, 0.15);
  color: var(--good);
  border-color: rgba(16, 185, 129, 0.3);
}

.ai-chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #111827;
}

.ai-chat-form input {
  min-width: 0;
}

.row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.action-btn {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  border: 0;
  display: inline-flex;
  align-items: center;
  transition: background 0.2s;
}

.action-btn.edit {
  background: #374151;
  color: #9ca3af;
}

.action-btn.edit:hover {
  background: #4b5563;
  color: #ffffff;
}

.action-btn.delete {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.action-btn.delete:hover {
  background: #ef4444;
  color: #ffffff;
}

@media (max-width: 1024px) {
  body {
    grid-template-columns: 1fr;
  }

  aside {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  nav {
    grid-template-columns: repeat(3, 1fr);
  }

  main {
    padding: 20px;
  }

  .dashboard-grid,
  .dashboard-grid.second-row,
  .metrics,
  .edit-form {
    grid-template-columns: 1fr;
  }

  .titlebar {
    display: grid;
    gap: 12px;
  }
}

/* Method chips filter layout */
.method-chips-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0 0;
  max-height: 200px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
}

.method-chip {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 30px;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
  font-size: 13px;
}

.method-chip:hover {
  border-color: #4b5563;
  background: var(--panel-hover);
}

.method-chip:has(input:checked) {
  border-color: var(--good);
  background: rgba(16, 185, 129, 0.1);
  color: #fff;
}

.method-chip input[type="checkbox"] {
  accent-color: var(--good);
  cursor: pointer;
  margin-right: 6px;
  width: 15px;
  height: 15px;
  min-height: unset;
}

.chip-name {
  font-weight: 500;
}

.chip-totals {
  font-size: 11px;
  color: var(--muted);
  margin-left: 6px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--good);
  cursor: pointer;
  padding: 0;
  font-size: 12px;
  text-decoration: underline;
  box-shadow: none !important;
  min-height: unset !important;
}

.link-btn:hover {
  color: #34d399;
}

/* User management specific styles */
.small-btn {
  font-size: 12px;
  min-height: 28px !important;
  padding: 0 10px !important;
}

.danger-btn {
  background: #ef4444 !important;
}

.danger-btn:hover {
  background: #dc2626 !important;
}
