:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e0e0e0;
  --accent: #1a1a1a;
  --accent-fg: #ffffff;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --success: #1e7e34;
  --success-bg: #e8f5e9;
  --card: #f7f7f7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --fg: #f0f0f0;
    --muted: #9a9a9a;
    --border: #333537;
    --accent: #f0f0f0;
    --accent-fg: #17181a;
    --danger: #ff6b60;
    --danger-bg: #3a1f1d;
    --success: #6cd97e;
    --success-bg: #1c3320;
    --card: #212224;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  min-height: 100vh;
}

header {
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--fg);
}

.brand-logo {
  width: 26px;
  height: 26px;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-account {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.3;
}

.user-email {
  font-size: 12px;
  color: var(--muted);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.credit-balance {
  font-size: 12px;
  font-weight: 700;
  color: var(--fg);
}

.buy-tokens-link {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

.buy-tokens-link:hover {
  color: var(--fg);
}

#settingsBtn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
}

#settingsBtn:hover {
  color: var(--fg);
}

.auth-view {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  padding-top: 8%;
}

.auth-card {
  width: 100%;
  max-width: 340px;
}

.auth-logo {
  display: block;
  width: 56px;
  height: 56px;
  margin: 0 auto 10px;
}

.auth-title {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  margin: 0 0 6px;
}

.auth-tagline {
  font-size: 13.5px;
  text-align: center;
  color: var(--muted);
  line-height: 1.4;
  margin: 0 auto 6px;
  max-width: 280px;
}

.auth-no-subscription {
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  color: var(--fg);
  margin: 0 0 24px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.auth-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 16px;
}

.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 9px 0;
  font-weight: 600;
  color: var(--muted);
}

.auth-tab.active {
  background: var(--accent);
  color: var(--accent-fg);
}

#authSubmitBtn {
  width: 100%;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  font-weight: 600;
  margin-top: 4px;
}

.banner {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 24px;
  font-size: 13px;
  text-align: center;
}

.banner a {
  color: inherit;
  font-weight: 600;
}

.hidden {
  display: none !important;
}

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

.app-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 32px;
  align-items: start;
}

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

.app-primary {
  min-width: 0;
}

.app-sidebar {
  position: sticky;
  top: 24px;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-bottom: 6px;
}

.context-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
  margin-bottom: 14px;
}

.context-input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.context-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.drop-zone {
  position: relative;
}

textarea {
  width: 100%;
  min-height: 320px;
  resize: vertical;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
}

textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.drop-zone.dragging textarea {
  outline: 2px dashed var(--accent);
  outline-offset: -1px;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border: 2px dashed var(--accent);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  pointer-events: none;
}

.row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

#accountView > .row {
  margin-bottom: 12px;
}

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border-radius: 7px;
  padding: 10px 16px;
  border: 1px solid var(--border);
}

#gradeBtn {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  font-weight: 600;
}

#gradeBtn:disabled {
  opacity: 0.5;
  cursor: default;
}

.secondary {
  background: transparent;
  color: var(--fg);
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

.remember-me-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin: -4px 0 14px;
  cursor: pointer;
}

.remember-me-label input {
  cursor: pointer;
}

.forgot-password-link {
  display: block;
  margin: 12px auto 0;
  text-align: center;
}

.error {
  margin-top: 12px;
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 7px;
  font-size: 13px;
}

.success {
  margin-top: 12px;
  background: var(--success-bg);
  color: var(--success);
  padding: 10px 12px;
  border-radius: 7px;
  font-size: 13px;
}

.acct-menu {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 340px;
}

.acct-menu-item {
  width: 100%;
  text-align: left;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  font-weight: 600;
  padding: 12px 14px;
}

.acct-menu-item:hover {
  border-color: var(--muted);
}

.acct-menu-item.danger {
  color: var(--danger);
}

.acct-menu-divider {
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

.acct-panel-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 4px;
}

.acct-panel-subtitle {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 16px;
}

.plan-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  max-width: 700px;
}

.plan-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  background: var(--card);
}

.plan-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.plan-name {
  font-weight: 700;
  font-size: 14px;
}

.plan-price {
  font-weight: 700;
  font-size: 17px;
}

.plan-details {
  font-size: 12.5px;
  color: var(--muted);
  margin: 0 0 12px;
}

.plan-buy-btn {
  width: 100%;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  font-weight: 600;
}

.plan-buy-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

#loadingView {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 80px 0;
  color: var(--muted);
}

.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--fg);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#resultOutput {
  font-size: 14.5px;
  line-height: 1.6;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
}

#resultOutput h1,
#resultOutput h2,
#resultOutput h3 {
  margin: 20px 0 8px;
  font-size: 16px;
  font-weight: 700;
}

#resultOutput h1:first-child,
#resultOutput h2:first-child,
#resultOutput h3:first-child {
  margin-top: 0;
}

#resultOutput p {
  margin: 8px 0;
}

#resultOutput ul,
#resultOutput ol {
  margin: 8px 0;
  padding-left: 22px;
}

#resultOutput li {
  margin: 4px 0;
}

#resultOutput strong {
  font-weight: 700;
}

#historySection {
  padding-top: 4px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-header h2 {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin: 0;
}

#historyList {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#historyList li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

#historyList li:hover {
  border-color: var(--muted);
}

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

.history-preview {
  flex: 1;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.history-edit-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 4px;
  cursor: pointer;
}

.history-edit-btn:hover {
  color: var(--fg);
}

.history-rename-input {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-family: inherit;
  padding: 3px 6px;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--bg);
  color: var(--fg);
}

.history-meta {
  font-size: 11.5px;
  color: var(--muted);
}

.empty-note {
  color: var(--muted);
  font-size: 13px;
}
