:root {
  --af-bg: #f3f6fa;
  --af-topbar: #ffffff;
  --af-card: #ffffff;
  --af-surface: #f8fafc;
  --af-surface-2: #eff4f8;
  --af-text: #344054;
  --af-strong: #1f2937;
  --af-muted: #667085;
  --af-border: #d8e0ea;
  --af-border-strong: #c4d0dd;
  --af-primary: #0d8bf2;
  --af-primary-dark: #0a73c9;
  --af-success: #177d4c;
  --af-danger: #cc4b4b;
  --af-danger-dark: #af3f3f;
  --af-danger-soft: #fff0f0;
  --af-orange: #e3a62f;
  --af-terminal-bg: #24303f;
  --af-terminal-text: #a9d0ff;
  --af-shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --af-shadow-md: 0 12px 26px rgba(16, 24, 40, .10);
  --af-radius-sm: 6px;
  --af-radius-md: 8px;
  --af-radius-lg: 12px;
  --af-font: Inter, Mulish, Arial, sans-serif;
}

html[data-theme="dark"] {
  --af-bg: #20262d;
  --af-topbar: #161b21;
  --af-card: #2a3138;
  --af-surface: #313841;
  --af-surface-2: #262d35;
  --af-text: #d7e0ea;
  --af-strong: #ffffff;
  --af-muted: #aeb9c5;
  --af-border: #414b57;
  --af-border-strong: #56616f;
  --af-primary: #168ff0;
  --af-primary-dark: #0f79cf;
  --af-success: #179257;
  --af-danger: #d16060;
  --af-danger-dark: #c34a4a;
  --af-danger-soft: #4b2528;
  --af-orange: #e2ab3d;
  --af-terminal-bg: #1f252c;
  --af-terminal-text: #a9d0ff;
  --af-shadow-sm: 0 1px 2px rgba(0, 0, 0, .22);
  --af-shadow-md: 0 12px 26px rgba(0, 0, 0, .28);
}

* {
  box-sizing: border-box;
}

html,
body,
button,
input,
select,
textarea,
table {
  font-family: var(--af-font);
}

body {
  margin: 0;
  background: var(--af-bg);
  color: var(--af-text);
  line-height: 1.45;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--af-border-strong);
  border-radius: var(--af-radius-sm);
  background: var(--af-card);
  color: var(--af-text);
  padding: 10px 12px;
  font-size: 14px;
}

button:focus-visible,
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--af-primary);
  box-shadow: 0 0 0 4px rgba(13, 139, 242, .14);
}

.hidden,
[hidden] {
  display: none !important;
}

.af-app {
  min-height: 100vh;
}

.af-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--af-topbar);
  border-bottom: 1px solid var(--af-border);
  box-shadow: var(--af-shadow-sm);
}

.af-topbar-inner {
  max-width: 1640px;
  margin: 0 auto;
  padding: 12px;
  display: grid;
  grid-template-columns: 240px minmax(260px, 1fr) auto;
  gap: 16px;
  align-items: center;
}

.af-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.af-brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--af-primary), var(--af-primary-dark));
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 900;
  letter-spacing: -.03em;
  box-shadow: var(--af-shadow-sm);
}

.af-brand-text strong {
  display: block;
  color: var(--af-strong);
  font-size: 16px;
  line-height: 1.2;
}

.af-brand-text span {
  display: block;
  color: var(--af-muted);
  font-size: 12px;
  margin-top: 2px;
}

.af-global-search {
  border-radius: 999px;
  background: var(--af-surface);
}

.af-topbar-actions,
.af-module-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
}

.af-tabs {
  max-width: 1640px;
  margin: 0 auto;
  padding: 0 12px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.af-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--af-muted);
  padding: 14px 10px 12px;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.af-tab:hover {
  color: var(--af-strong);
}

.af-tab.active {
  color: var(--af-strong);
  border-bottom-color: var(--af-primary);
}

.af-tab:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.af-main {
  max-width: 1640px;
  margin: 0 auto;
  padding: 16px 12px 20px;
}

.af-module-host {
  min-height: 360px;
}

.af-module {
  display: block;
}

.af-module-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin: 0 0 12px;
}

.af-module-title h1 {
  margin: 0 0 4px;
  color: var(--af-strong);
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -.02em;
}

.af-module-title p {
  margin: 0;
  color: var(--af-muted);
  font-size: 13px;
}

.af-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--af-surface);
  border: 1px solid var(--af-border);
  color: var(--af-muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .03em;
  white-space: nowrap;
}

.af-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.af-card {
  background: var(--af-card);
  border: 1px solid var(--af-border);
  border-radius: var(--af-radius-lg);
  box-shadow: var(--af-shadow-sm);
  padding: 16px;
}

.af-card h2,
.af-card h3 {
  margin: 0 0 8px;
  color: var(--af-strong);
  font-size: 15px;
  font-weight: 900;
}

.af-card p {
  margin: 0 0 10px;
  color: var(--af-muted);
  font-size: 13px;
}

.af-card ul {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--af-text);
  font-size: 13px;
}

.af-card li + li {
  margin-top: 4px;
}

.af-btn {
  border: 1px solid transparent;
  border-radius: var(--af-radius-md);
  font-weight: 900;
  cursor: pointer;
  padding: 8px 14px;
  min-height: 34px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .16s ease, background .16s ease, border-color .16s ease, color .16s ease;
}

.af-btn:hover {
  transform: translateY(-1px);
}

.af-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}

.af-btn-small {
  min-height: 30px;
  padding: 6px 10px;
  font-size: 11px;
}

.af-btn-blue {
  background: var(--af-primary);
  color: #fff;
}

.af-btn-blue:hover {
  background: var(--af-primary-dark);
}

.af-btn-green {
  background: var(--af-success);
  color: #fff;
}

.af-btn-orange {
  background: var(--af-orange);
  color: #3a2d09;
}

.af-btn-outline {
  background: var(--af-card);
  color: var(--af-strong);
  border-color: var(--af-border-strong);
}

.af-btn-danger {
  background: var(--af-danger);
  color: #fff;
}

.af-btn-danger:hover {
  background: var(--af-danger-dark);
}

.af-placeholder-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.af-terminal-panel {
  max-width: 1640px;
  margin: 0 auto 24px;
  padding: 0 12px;
}

.af-terminal-head {
  background: var(--af-card);
  border: 1px solid var(--af-border);
  border-bottom: 0;
  border-radius: var(--af-radius-lg) var(--af-radius-lg) 0 0;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.af-terminal-head h2 {
  margin: 0;
  color: var(--af-strong);
  font-size: 14px;
  font-weight: 900;
}

.af-terminal-head p {
  margin: 3px 0 0;
  color: var(--af-muted);
  font-size: 12px;
}

.af-terminal-progress {
  height: 4px;
  background: var(--af-surface-2);
  border-left: 1px solid var(--af-border);
  border-right: 1px solid var(--af-border);
  overflow: hidden;
}

.af-terminal-progress-fill {
  height: 100%;
  width: 0;
  background: var(--af-primary);
  transition: width .2s ease;
}

.af-terminal-output {
  margin: 0;
  min-height: 88px;
  max-height: 220px;
  overflow: auto;
  background: var(--af-terminal-bg);
  color: var(--af-terminal-text);
  border-radius: 0 0 var(--af-radius-lg) var(--af-radius-lg);
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  box-shadow: var(--af-shadow-sm);
}

.af-modal-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
}

.af-modal-root.active {
  display: block;
}

.af-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .55);
}

.af-modal-dialog {
  position: relative;
  width: min(620px, calc(100vw - 24px));
  margin: 9vh auto 0;
  background: var(--af-card);
  border: 1px solid var(--af-border);
  border-radius: var(--af-radius-lg);
  box-shadow: var(--af-shadow-md);
  overflow: hidden;
}

.af-modal-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--af-border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.af-modal-head h2 {
  margin: 0;
  color: var(--af-strong);
  font-size: 16px;
  font-weight: 900;
}

.af-modal-body {
  padding: 16px;
  color: var(--af-text);
  font-size: 14px;
}

.af-modal-actions {
  padding: 12px 16px;
  border-top: 1px solid var(--af-border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

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

.af-code {
  display: inline-flex;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--af-surface);
  border: 1px solid var(--af-border);
  color: var(--af-strong);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

/* Tymczasowa warstwa kompatybilności dla późniejszej integracji modułów */
.box,
.panel,
.action-panel,
.panel-card {
  background: var(--af-card);
  border: 1px solid var(--af-border);
  border-radius: var(--af-radius-lg);
  box-shadow: var(--af-shadow-sm);
  padding: 16px;
}

.btn {
  border-radius: var(--af-radius-md);
  border: 1px solid transparent;
  font-weight: 900;
  cursor: pointer;
  padding: 8px 14px;
  min-height: 34px;
  font-size: 12px;
}

.console {
  background: var(--af-terminal-bg);
  color: var(--af-terminal-text);
  border-radius: var(--af-radius-md);
  padding: 10px 12px;
  font-size: 12px;
}

@media (max-width: 980px) {
  .af-topbar-inner {
    grid-template-columns: 1fr;
  }

  .af-topbar-actions {
    justify-content: flex-start;
  }

  .af-grid {
    grid-template-columns: 1fr;
  }

  .af-module-header {
    flex-direction: column;
  }
}