:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1d23;
  --text-dim: #5b6372;
  --border: #e3e6ea;
  --accent: #2f6fed;
  --accent-light: #e8f0ff;
  --good: #1f9d55;
  --good-light: #e5f6ec;
  --warn: #c98500;
  --warn-light: #fdf3e0;
  --bad: #d03b3b;
  --bad-light: #fbe9e9;
  --radius: 10px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --text: #e8eaed;
    --text-dim: #9aa2af;
    --border: #2c3038;
    --accent: #5b8dfb;
    --accent-light: #233253;
    --good: #3fcc7e;
    --good-light: #1c3327;
    --warn: #e0a429;
    --warn-light: #332a15;
    --bad: #e66767;
    --bad-light: #331c1c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.topbar h1 { margin: 0; font-size: 1.3rem; letter-spacing: -0.015em; }

.topbar-right { display: flex; align-items: center; gap: 1rem; font-size: 0.85rem; color: var(--text-dim); }

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

.tab-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, transform 120ms var(--ease-out);
}
.tab-btn:active { transform: scale(0.97); }
.tab-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card h2 { margin: 0 0 0.8rem 0; font-size: 1.05rem; }

.hint { color: var(--text-dim); font-size: 0.85rem; }

.inline-form { display: flex; gap: 1rem; flex-wrap: wrap; align-items: end; }
.inline-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--text-dim); }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: filter 150ms ease, transform 120ms var(--ease-out), opacity 150ms ease;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:active { transform: scale(0.97); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.small-btn {
  background: var(--accent-light);
  color: var(--accent);
  border: none;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: filter 150ms ease, transform 120ms var(--ease-out), opacity 150ms ease;
}
.small-btn:hover { filter: brightness(0.96); }
.small-btn:active { transform: scale(0.97); }
.small-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.danger-btn { background: var(--bad-light); color: var(--bad); }
.danger-btn:hover { filter: brightness(0.95); }

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

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.data-table th { color: var(--text-dim); font-weight: 600; text-transform: uppercase; font-size: 0.72rem; }
.data-table tbody tr { transition: background-color 150ms ease; }
.data-table tbody tr:hover { background: var(--accent-light); cursor: pointer; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}
.badge.status-new { background: var(--border); color: var(--text-dim); }
.badge.status-building { background: var(--accent-light); color: var(--accent); }
.badge.status-contacted { background: var(--accent-light); color: var(--accent); }
.badge.status-discussing { background: var(--warn-light); color: var(--warn); }
.badge.status-agreed { background: var(--good-light); color: var(--good); }
.badge.status-rejected { background: var(--bad-light); color: var(--bad); }
.badge.status-delivered { background: var(--good-light); color: var(--good); }
.badge.status-paid { background: var(--good); color: #fff; }
.badge.status-lost { background: var(--bad-light); color: var(--bad); }

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.7rem;
  flex-wrap: wrap;
}
.result-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 0.2rem; }
.result-meta { color: var(--text-dim); font-size: 0.82rem; line-height: 1.6; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 1rem;
  transition: background-color 200ms ease, display 200ms allow-discrete, overlay 200ms allow-discrete;
}
.modal-overlay[hidden] {
  display: none;
  background: rgba(0,0,0,0);
}
@starting-style {
  .modal-overlay:not([hidden]) { background: rgba(0,0,0,0); }
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  transform-origin: center;
  transform: scale(1);
  opacity: 1;
  transition: transform 220ms var(--ease-out), opacity 220ms var(--ease-out);
}
.modal-overlay[hidden] .modal-card { transform: scale(0.95); opacity: 0; }
@starting-style {
  .modal-overlay:not([hidden]) .modal-card { transform: scale(0.95); opacity: 0; }
}
.modal-close {
  float: right; background: none; border: none; color: var(--text-dim);
  font-size: 1.2rem; cursor: pointer;
  transition: color 150ms ease, transform 120ms var(--ease-out);
}
.modal-close:hover { color: var(--text); }
.modal-close:active { transform: scale(0.9); }

.field-row { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.8rem; font-size: 0.85rem; }
.field-row .label { color: var(--text-dim); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }

.activity-line { padding: 0.5rem 0; border-bottom: 1px solid var(--border); font-size: 0.82rem; }
.activity-line:last-child { border-bottom: none; }
.activity-line .meta { color: var(--text-dim); font-size: 0.72rem; }

.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
}
.login-card { width: 320px; }
.login-card h1 { font-size: 1.3rem; margin-bottom: 1.2rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.9rem; font-size: 0.85rem; color: var(--text-dim); }
.login-card input { width: 100%; }
.error-text { color: var(--bad); font-size: 0.85rem; margin-top: 0.6rem; }
.error-text, #accountSuccess {
  opacity: 1;
  transition: opacity 200ms ease, display 200ms allow-discrete;
}
.error-text[hidden], #accountSuccess[hidden] { display: none; opacity: 0; }
@starting-style {
  .error-text:not([hidden]), #accountSuccess:not([hidden]) { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .modal-card, .tab-btn, .primary-btn, .small-btn { transform: none !important; }
}
