/* AppSystem — wspólna warstwa nowoczesnego interfejsu i responsywności. */
:root {
  --app-canvas: #f3f7fb;
  --app-surface-soft: #f7fafd;
  --app-border: #dce6ef;
  --app-border-strong: #bdcbd8;
  --app-shadow: 0 14px 38px rgba(18, 45, 72, .075);
  --app-shadow-hover: 0 20px 48px rgba(18, 45, 72, .13);
  --radius: 16px;
  --sidebar: 256px;
}

body {
  min-width: 320px;
  background:
    radial-gradient(circle at 72% -20%, rgba(8, 120, 189, .07), transparent 35rem),
    var(--app-canvas);
}

:where(button, a, input, select, textarea):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--app-focus) 78%, white);
  outline-offset: 2px;
}

.btn,
.icon-btn,
.profile-btn,
.nav-item,
.nav-group-toggle {
  transition: background-color .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.btn:active,
.icon-btn:active,
.profile-btn:active {
  transform: translateY(1px);
}

/* Logowanie i pola haseł */
.login-shell {
  background:
    radial-gradient(circle at 16% 12%, rgba(0, 67, 129, .16), transparent 31rem),
    radial-gradient(circle at 86% 86%, rgba(8, 120, 189, .12), transparent 28rem),
    #f5f8fc;
}

.login-card {
  width: min(460px, 100%);
  padding: 38px;
  border: 1px solid rgba(255, 255, 255, .82);
  border-top: 4px solid var(--app-primary);
  border-radius: 26px;
  box-shadow: 0 28px 75px rgba(20, 48, 77, .15);
}

.password-field {
  position: relative;
  display: block;
}

.password-field input {
  padding-right: 76px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 7px;
  min-width: 58px;
  min-height: 34px;
  padding: 0 8px;
  transform: translateY(-50%);
  border: 0;
  border-radius: 9px;
  background: var(--app-hover-bg);
  color: var(--app-primary);
  font-size: .72rem;
  font-weight: 800;
}

.password-toggle:hover {
  background: var(--app-selected-bg);
}

/* Wybór strefy */
.access-shell {
  align-items: start;
  padding: clamp(26px, 5vh, 54px) 24px;
  background:
    radial-gradient(circle at 8% 6%, rgba(0, 67, 129, .13), transparent 30rem),
    radial-gradient(circle at 92% 92%, rgba(22, 116, 91, .09), transparent 26rem),
    #f5f8fc;
}

.access-panel {
  width: min(1160px, 100%);
  margin: 0 auto;
}

.access-head {
  align-items: center;
  margin-bottom: 22px;
}

.access-head h1 {
  margin-top: 0;
  font-size: clamp(2rem, 4vw, 2.8rem);
  letter-spacing: -.035em;
}

.access-tiles {
  gap: 16px;
}

.access-tile {
  position: relative;
  min-height: 224px;
  gap: 12px;
  overflow: hidden;
  padding: 22px;
  border-radius: 20px;
  box-shadow: var(--app-shadow);
}

.access-tile::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--area);
  opacity: .82;
}

.access-tile:not(.locked):hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--area) 30%, var(--app-border));
  box-shadow: var(--app-shadow-hover);
}

.access-icon {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  font-size: .9rem;
  letter-spacing: .04em;
}

.access-tile h2 {
  margin: 2px 0 0;
  font-size: 1.27rem;
  letter-spacing: -.015em;
}

.access-tile p {
  max-width: 34ch;
  line-height: 1.5;
  font-size: .9rem;
}

.access-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  margin-top: auto;
  padding-top: 4px;
  color: var(--area);
  font-size: .86rem;
}

.access-state span {
  font-size: 1.2rem;
  transition: transform .16s ease;
}

.access-tile:hover .access-state span {
  transform: translateX(3px);
}

/* Nawigacja i pasek aplikacji */
.sidebar {
  padding: 18px 13px 12px;
  box-shadow: 10px 0 34px rgba(2, 35, 67, .08);
}

.sidebar-brand {
  padding-bottom: 16px;
}

.nav-list {
  flex: 1 1 auto;
  min-height: 0;
  align-content: start;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px 4px 10px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .28) transparent;
}

.nav-item,
.nav-group-toggle {
  min-height: 43px;
}

.nav-item.active {
  box-shadow: inset 3px 0 rgba(255, 255, 255, .82);
}

.sidebar-footer {
  position: relative;
  bottom: auto;
  flex: 0 0 auto;
  margin-top: 6px;
  padding: 10px 5px 2px;
  background: linear-gradient(180deg, transparent, rgba(2, 34, 65, .6));
}

.accessibility-sidebar-btn {
  min-height: 42px;
  padding: 8px 10px;
  font-size: .78rem;
}

.topbar {
  min-height: 68px;
  gap: 12px;
  padding: 10px 20px;
}

.search-wrap {
  min-width: 180px;
  min-height: 44px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--app-surface-soft) 88%, transparent);
}

.topbar-actions {
  min-width: 0;
  flex: 0 1 auto;
  gap: 8px;
}

.topbar-actions .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  white-space: nowrap;
}

.profile-btn {
  min-width: 0;
}

.profile-copy {
  max-width: 220px;
}

.profile-copy strong,
.profile-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.archive-workspace .topbar > .search-wrap {
  display: none;
}

body.archive-workspace .topbar {
  justify-content: flex-end;
}

/* Pulpity, karty, tabele i okna */
.content {
  width: 100%;
  padding: clamp(18px, 2.2vw, 30px);
}

.dashboard-grid {
  align-items: start;
}

.dashboard-grid > .side-panel {
  position: sticky;
  top: 92px;
  align-self: start;
}

.tile,
.panel,
.side-panel,
.item-card {
  box-shadow: var(--app-shadow);
}

.tile {
  min-height: 156px;
}

.tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--app-shadow-hover);
}

.dashboard-tile-main {
  padding: 18px;
}

.dashboard-unpin {
  opacity: 0;
  transform: scale(.92);
  transition: opacity .16s ease, transform .16s ease, background-color .16s ease;
}

.dashboard-tile:hover .dashboard-unpin,
.dashboard-tile:focus-within .dashboard-unpin {
  opacity: 1;
  transform: scale(1);
}

.empty-state {
  padding: 32px 20px;
  background: var(--app-surface);
}

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

.table-wrap th {
  background: var(--app-surface-soft);
}

.modal {
  border: 1px solid color-mix(in srgb, var(--app-border) 80%, white);
  box-shadow: 0 34px 90px rgba(8, 28, 48, .28);
}

body.app-shell-active > .messenger-float-btn {
  display: none !important;
}

/* Zwykły tryb ciemny */
html.app-dark .login-shell,
html.app-dark .access-shell {
  background:
    radial-gradient(circle at 10% 8%, rgba(49, 147, 207, .13), transparent 30rem),
    var(--app-canvas);
}

html.app-dark .password-toggle {
  background: var(--app-surface-soft);
  color: var(--app-link);
}

html.app-dark .pwa-update-banner {
  background: var(--app-surface);
  color: var(--app-text);
  border-color: var(--app-border-strong);
}

html.app-dark .pwa-update-banner span {
  color: var(--app-muted);
}

/* Laptop i tablet */
@media (max-width: 1440px) {
  .app-clock,
  .profile-copy {
    display: none;
  }
}

@media (min-width: 901px) and (max-width: 1180px) {
  #archiveGlobalAddBtn {
    width: 42px;
    padding-inline: 0;
  }

  #archiveGlobalAddBtn .btn-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
}

@media (max-width: 1180px) {
  .dashboard-grid > .side-panel {
    position: static;
  }
}

@media (max-width: 980px) {
  .access-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .access-tile {
    min-height: 210px;
  }
}

/* Telefon */
@media (max-width: 900px) {
  body.nav-open {
    overflow: hidden;
  }

  body.nav-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 19;
    background: rgba(7, 24, 42, .48);
    backdrop-filter: blur(2px);
  }

  .sidebar {
    left: min(-292px, -88vw);
    width: min(280px, 86vw);
    padding-top: max(16px, env(safe-area-inset-top));
  }

  .sidebar.open {
    left: 0;
  }

  .content {
    padding: 18px 12px 28px;
  }
}

@media (max-width: 700px) {
  .topbar {
    padding: max(8px, env(safe-area-inset-top)) 10px 9px;
  }

  .topbar-actions {
    gap: 5px;
  }

  .app-clock,
  #themeModeBtn,
  #changeAreaBtn,
  #archiveGlobalAddBtn,
  .pwa-install-top {
    display: none !important;
  }

  #quickAddBtn {
    display: inline-grid !important;
    width: 42px;
    min-width: 42px;
    height: 42px;
    padding: 0;
  }

  #quickAddBtn .btn-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  #quickAddBtn .btn-icon {
    font-size: 1.35rem;
    line-height: 1;
  }

  .profile-btn {
    width: 42px;
    height: 42px;
    padding: 2px;
  }

  .avatar {
    width: 36px;
    height: 36px;
  }

  .search-wrap {
    min-width: 0;
  }

  .page-header {
    margin-bottom: 18px;
  }

  .page-header h1 {
    font-size: clamp(1.65rem, 8vw, 2rem);
  }

  .dashboard-grid {
    gap: 16px;
  }

  .dashboard-grid > .side-panel {
    order: -1;
  }

  .dashboard-unpin {
    opacity: .58;
    transform: none;
  }
}

@media (max-width: 640px) {
  .access-shell {
    padding: 22px 13px;
  }

  .access-head {
    gap: 14px;
  }

  .access-tiles {
    grid-template-columns: 1fr;
  }

  .access-tile {
    min-height: 190px;
    padding: 20px;
  }

  .login-card {
    padding: 28px 20px;
  }
}

@media (hover: none) {
  .tile:hover,
  .access-tile:not(.locked):hover,
  .messenger-float-btn:hover {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .icon-btn,
  .profile-btn,
  .nav-item,
  .nav-group-toggle,
  .access-tile,
  .access-state span,
  .dashboard-unpin {
    transition: none;
  }
}
