:root {
  --navy: #002244;
  --blue: #00cef7;
  --yellow: #fff500;
  --grey: #e3e3e3;
  --soft: #f5f8fa;
  --line: #d5dfe5;
  --muted: #436078;
  --danger: #b3261e;
  --ok: #0f7b45;
  --warn: #8a5a00;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--navy);
  background: var(--soft);
  font-family: Poppins, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--navy);
  text-underline-offset: 3px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(24px, 2.6vw, 34px);
  line-height: 1.24;
  letter-spacing: -0.5px;
  margin-bottom: 10px;
}

h2 {
  font-size: 20px;
  line-height: 1.3;
}

h3 {
  font-size: 16px;
}

small,
.small {
  font-size: 12px;
  color: var(--muted);
}

/* ── Login ─────────────────────────────────────────────────────────── */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--navy), #013a63 70%);
}

.login-card {
  width: min(460px, 100%);
  background: white;
  border-radius: 18px;
  padding: 34px;
  box-shadow: 0 24px 60px rgba(0, 20, 40, 0.35);
}

.login-card h1 {
  font-size: 26px;
}

.login-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 16px;
}

.google-button {
  display: flex;
  justify-content: center;
  min-height: 44px;
  margin-top: 18px;
}

/* ── Layout ────────────────────────────────────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: white;
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: auto;
}

.brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.2px;
}

.brand-mark {
  color: var(--blue);
}

.sidebar nav {
  display: grid;
  gap: 3px;
}

.sidebar nav button {
  text-align: left;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  gap: 10px;
  align-items: baseline;
  cursor: pointer;
}

.sidebar nav button:hover,
.sidebar nav button:focus-visible {
  background: var(--soft);
}

.sidebar nav button.active {
  background: var(--navy);
  color: white;
}

.sidebar nav button span {
  opacity: 0.55;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}

.sidebar-note {
  margin-top: auto;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--grey);
  padding-top: 14px;
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 64px;
  padding: 12px 28px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: white;
  position: sticky;
  top: 0;
  z-index: 5;
}

.page {
  padding: 28px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.page.with-assistant {
  padding-right: 28px;
}

/* ── Elementy ──────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--navy);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.blue {
  background: var(--blue);
  border-color: var(--blue);
}

.badge.yellow {
  background: var(--yellow);
  border-color: var(--yellow);
}

.badge.grey {
  background: var(--grey);
  border-color: var(--grey);
}

.badge.ok {
  background: #d6f5e3;
  border-color: #7fd3a5;
  color: var(--ok);
}

.badge.danger {
  background: #ffe3e0;
  border-color: #f0a9a1;
  color: var(--danger);
}

.card {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
}

.grid.four {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.hero {
  background: var(--navy);
  color: white;
  border-radius: 18px;
  padding: 30px;
  margin-bottom: 18px;
}

.hero p {
  color: #d9e6ee;
  max-width: 760px;
}

.hero mark {
  background: var(--yellow);
  color: var(--navy);
  padding: 0 6px;
}

.metric strong {
  display: block;
  font-size: 30px;
  line-height: 1.2;
  margin: 4px 0 6px;
}

.metric .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 700;
}

.bar {
  height: 6px;
  background: var(--grey);
  border-radius: 999px;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--blue);
}

.bar.warn > span {
  background: #e2a33a;
}

.callout {
  border-left: 4px solid var(--blue);
  background: #eef8fc;
  padding: 14px 16px;
  border-radius: 0 10px 10px 0;
  margin: 14px 0;
}

.callout.warn {
  border-color: #e2a33a;
  background: #fdf5e6;
}

.callout.danger {
  border-color: var(--danger);
  background: #fdeceb;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

button.action {
  border: 1px solid var(--line);
  background: white;
  border-radius: 9px;
  padding: 8px 13px;
  font-weight: 600;
  cursor: pointer;
}

button.action:hover:not(:disabled) {
  border-color: var(--navy);
  background: var(--blue);
}

button.action:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.action.primary {
  background: var(--navy);
  border-color: var(--navy);
  color: white;
}

button.action.primary:hover:not(:disabled) {
  background: #013a63;
}

button.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--navy);
  text-decoration: underline;
  cursor: pointer;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  background: white;
}

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

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
}

label > input,
label > select,
label > textarea {
  margin-top: 4px;
  font-weight: 400;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.filters > * {
  flex: 1 1 190px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  background: var(--soft);
  position: sticky;
  top: 0;
}

tbody tr:hover {
  background: #f7fbfd;
}

.table-scroll {
  overflow: auto;
  max-height: 62vh;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
}

.list-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  text-align: left;
  width: 100%;
  background: none;
  border-left: 0;
  border-right: 0;
  border-top: 0;
}

.list-row:last-child {
  border-bottom: 0;
}

/* ── Panel szczegółów ──────────────────────────────────────────────── */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 20, 40, 0.45);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 40;
}

.drawer {
  background: white;
  border-radius: 16px;
  width: min(980px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 24px;
}

.drawer header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

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

.field {
  font-size: 13px;
}

.field b {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  margin-bottom: 2px;
}

.markdown {
  white-space: pre-wrap;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.65;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  max-height: 42vh;
  overflow: auto;
}

/* ── Asystent ──────────────────────────────────────────────────────── */
.assistant {
  border-left: 1px solid var(--line);
  background: white;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}

.assistant.with-sidebar {
  height: 100vh;
}

.assistant-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.assistant-body {
  flex: 1;
  overflow: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.assistant-message {
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 13px;
  white-space: pre-wrap;
}

.assistant-message.user {
  background: var(--navy);
  color: white;
  align-self: flex-end;
  max-width: 92%;
}

.assistant-message.assistant {
  background: var(--soft);
  border: 1px solid var(--line);
}

.assistant-message.system {
  background: #fdf5e6;
  border: 1px solid #e2c894;
  font-size: 12px;
}

.assistant-cite {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}

.assistant-form {
  border-top: 1px solid var(--line);
  padding: 12px 16px;
}

.assistant-form textarea {
  min-height: 68px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.quick-actions button {
  font-size: 11px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: white;
  cursor: pointer;
}

.layout-with-assistant {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  min-height: 100vh;
}

@media (max-width: 1100px) {
  .layout-with-assistant {
    grid-template-columns: minmax(0, 1fr);
  }
  .assistant {
    position: fixed;
    right: 0;
    bottom: 0;
    width: min(420px, 100%);
    height: min(70vh, 560px);
    border: 1px solid var(--line);
    border-radius: 16px 0 0 0;
    box-shadow: 0 12px 40px rgba(0, 20, 40, 0.25);
    z-index: 30;
  }
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: static;
    height: auto;
  }
  .sidebar nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
  }
  .page {
    padding: 18px;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid var(--line);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.notice {
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 13px;
  margin-bottom: 12px;
}

.notice.error {
  background: #fdeceb;
  border: 1px solid #f0a9a1;
  color: var(--danger);
}

.notice.ok {
  background: #e8f7ee;
  border: 1px solid #a5d9bd;
  color: var(--ok);
}
