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

:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --line: #e2e5eb;
  --ink: #111827;
  --muted: #6b7280;
  --accent: #5b4bf3;
  --accent-strong: #4338ca;
  --accent-soft: #eef2ff;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'DM Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 16px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
}

.brand__logo {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.brand__name {
  font-size: 1rem;
}

.topnav {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.topnav__link {
  text-decoration: none;
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
}

.topnav__link.is-active {
  background: var(--accent);
  color: #fff;
}

.topbar__right {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
}

.user-pill {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px 12px;
  display: grid;
  gap: 2px;
  font-size: 0.8rem;
}

.user-pill__label {
  color: var(--muted);
}

.user-pill__value {
  font-weight: 600;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.ghost {
  border: 1px solid var(--line);
  background: transparent;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}

.content {
  padding: 28px 48px 64px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.page-header h1 {
  margin: 0 0 6px;
  font-size: 1.8rem;
}

.page-subtitle {
  margin: 0;
  color: var(--muted);
}

.section-head h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.muted {
  color: var(--muted);
}

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

.kpi-card {
  background: var(--surface);
  padding: 18px;
  border-radius: 16px;
  border: 1px solid var(--line);
  min-height: 140px;
  display: grid;
  gap: 8px;
}

.kpi-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-weight: 600;
}

.kpi-icon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  border: 2px solid currentColor;
}

.kpi-icon--danger { color: var(--danger); }
.kpi-icon--warn { color: var(--warning); }
.kpi-icon--accent { color: var(--accent); }
.kpi-icon--ok { color: #0ea5e9; }

.kpi-value {
  font-size: 1.8rem;
  margin: 0;
  font-weight: 700;
}

.kpi-sub a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.panel {
  background: var(--surface);
  padding: 20px;
  border-radius: 16px;
  border: 1px solid var(--line);
  min-height: 280px;
}

.panel--large {
  min-height: 320px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-head h3 {
  margin: 0 0 4px;
}

.panel-head a {
  text-decoration: none;
  color: var(--ink);
  font-weight: 600;
}

.panel-empty {
  display: grid;
  place-items: center;
  text-align: center;
  gap: 10px;
  margin-top: 32px;
  color: var(--muted);
}

.panel-icon {
  font-size: 2rem;
  color: #c4c7cf;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 16px;
  flex-wrap: wrap;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  min-width: 240px;
}

.search input {
  border: none;
  outline: none;
  background: transparent;
  width: 100%;
  font-family: inherit;
}

.filter {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--surface);
}

.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
}

.primary:hover {
  background: var(--accent-strong);
}

.table-wrap {
  background: var(--surface);
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
}

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

.data-table th,
.data-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

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

.data-table td.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 12px;
}

.tabs {
  display: inline-flex;
  gap: 8px;
  padding: 4px;
  background: #f1f3f5;
  border-radius: 10px;
  margin: 16px 0;
}

.tab {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
}

.tab.is-active {
  background: var(--surface);
  border: 1px solid var(--line);
}

.project-header {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.project-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}

.list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal.is-open {
  display: flex;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 20, 0.55);
}

.modal__dialog {
  position: relative;
  background: #f8f9fb;
  border-radius: 16px;
  padding: 24px;
  width: min(720px, 90vw);
  max-height: 90vh;
  overflow: auto;
  z-index: 1;
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.modal__body {
  margin-top: 16px;
  display: grid;
  gap: 14px;
}

.modal__body label {
  display: grid;
  gap: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}

.modal__body input,
.modal__body select,
.modal__body textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  background: #fff;
}

.modal__grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.line-items {
  display: grid;
  gap: 10px;
  background: #f2f4f8;
  border: 1px solid var(--line);
  padding: 12px;
  border-radius: 12px;
}

.line-items__head,
.line-items__row {
  display: grid;
  grid-template-columns: 2fr 0.8fr 0.9fr 1fr;
  gap: 10px;
  align-items: center;
}

.line-items__head {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.line-items__row select,
.line-items__row input {
  width: 100%;
}

.invoice-sheet {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 18px;
  padding: 28px;
  font-family: 'DM Sans', sans-serif;
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 18px;
  margin-bottom: 18px;
}

.invoice-header h1 {
  margin: 0 0 6px;
}

.invoice-meta {
  display: grid;
  gap: 8px;
  font-size: 0.9rem;
}

.invoice-meta span {
  color: var(--muted);
  display: inline-block;
  width: 80px;
}

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

.invoice-table th,
.invoice-table td {
  border-bottom: 1px solid #e5e7eb;
  padding: 10px 8px;
  text-align: left;
}

.invoice-total {
  display: flex;
  justify-content: space-between;
  font-size: 1.1rem;
  margin-top: 16px;
}

.icon-btn {
  border: none;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
}

.assistant {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  min-height: 520px;
  display: grid;
  gap: 20px;
}

.assistant-header {
  display: flex;
  align-items: center;
  gap: 16px;
}

.assistant-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.assistant-body {
  display: grid;
  place-items: center;
  text-align: center;
}

.assistant-hero {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  color: var(--accent);
  margin-bottom: 16px;
}

.assistant-suggestions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.assistant-input {
  display: flex;
  gap: 12px;
}

.assistant-input input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-family: inherit;
}

.assistant-response {
  background: #f8f9fb;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  white-space: pre-wrap;
}

.assistant-response pre {
  margin: 0;
  font-family: 'DM Sans', sans-serif;
  white-space: pre-wrap;
}

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

.chat__row {
  display: flex;
}

.chat__row--user {
  justify-content: flex-end;
}

.chat__row--assistant {
  justify-content: flex-start;
}

.chat__bubble {
  max-width: 70%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
}

.chat__bubble--user {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chat__bubble p {
  margin: 0;
  white-space: pre-wrap;
  font-family: 'DM Sans', sans-serif;
}

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 28px;
  border: 1px solid var(--line);
  max-width: 360px;
  width: 100%;
}

.login-card form {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.login-card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-family: inherit;
}

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

@media (max-width: 960px) {
  .topbar {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .topbar__right {
    justify-content: center;
    flex-wrap: wrap;
  }
  .content {
    padding: 24px;
  }
}
