:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4d;
  --text: #e8eef7;
  --muted: #8b9cb3;
  --accent: #3d9cf0;
  --accent-dim: #2563a8;
  --danger: #e85d5d;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse 120% 80% at 50% -20%, #1e3a5f 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
}

.sub {
  color: var(--muted);
  max-width: 52ch;
  margin: 0 0 1.25rem;
}

.banner {
  margin: 0.75rem 0 0;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid #6b4c1a;
  background: rgba(200, 150, 40, 0.12);
  color: #e8c97a;
  font-size: 0.88rem;
  max-width: 52rem;
  line-height: 1.45;
}

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

.user-email {
  color: var(--accent);
  font-size: 0.9rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  border-color: var(--accent-dim);
}

.btn.primary {
  background: linear-gradient(180deg, #4aa8ff 0%, var(--accent) 100%);
  border-color: #5ab0ff;
  color: #061018;
  font-weight: 600;
}

.btn.primary:hover {
  filter: brightness(1.06);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  border-color: #a33;
  background: #3a1f24;
  color: #ffb4b4;
}

.btn.danger:hover {
  background: #4f2830;
}

.btn.small {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.hidden {
  display: none !important;
}

.main {
  margin-top: 2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 1rem;
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.controls select {
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  min-width: 11rem;
}

input[type="month"] {
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

label.field-dimmed,
.field-dimmed {
  opacity: 0.55;
}

.range-help {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 42rem;
  line-height: 1.45;
}

.range-help code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.status {
  font-size: 0.9rem;
  color: var(--muted);
}

.hint-inline {
  flex-basis: 100%;
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 42rem;
  line-height: 1.45;
}

.hint-inline code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.summary h2,
.table-head h2 {
  font-size: 1.1rem;
  margin: 0 0 0.75rem;
}

.summary-text {
  white-space: pre-wrap;
  font-size: 0.95rem;
  color: #d0dae8;
}

.table-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.bulk {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

.meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

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

.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

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

.data th {
  color: var(--muted);
  font-weight: 600;
}

.data tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.data .chk {
  width: 2.25rem;
}

.data td.reason {
  color: #b8c5d6;
  max-width: 280px;
}

.error {
  color: #ffb4b4;
  background: #3a1f24;
  border: 1px solid #a33;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
}

.feedback-ok {
  margin: 0.35rem 0 0.5rem;
  font-size: 0.9rem;
  color: #8ef0b8;
}

/* Bottom assistant chat */
.chat-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  pointer-events: none;
}

.chat-dock > * {
  pointer-events: auto;
}

.chat-toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 auto 0 auto;
  max-width: 1100px;
  width: calc(100% - 2rem);
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(180deg, #243044 0%, var(--surface) 100%);
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
}

.chat-toggle:hover {
  border-color: var(--accent-dim);
}

.chat-toggle-label {
  font-weight: 600;
}

.chat-pill {
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--bg);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.chat-pill.ready {
  color: #7dffb0;
  background: rgba(40, 120, 80, 0.25);
}

.chat-panel {
  margin: 0 auto;
  max-width: 1100px;
  width: calc(100% - 2rem);
  border: 1px solid var(--border);
  border-bottom: none;
  background: var(--surface);
  max-height: min(52vh, 520px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.45);
}

.chat-panel.hidden {
  display: none !important;
}

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

.chat-disclaimer {
  margin: 0;
  padding: 0.45rem 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  line-height: 1.4;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.65rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 120px;
}

.chat-bubble {
  max-width: 92%;
  padding: 0.5rem 0.65rem;
  border-radius: 10px;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble.user {
  align-self: flex-end;
  background: #2a3f5c;
  border: 1px solid var(--border);
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
}

.chat-bubble .tool-note {
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: #9ab;
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
}

.chat-form input {
  flex: 1;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

body.chat-open .page {
  padding-bottom: 0.5rem;
}
