:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #1a2332;
  --muted: #5c6b7a;
  --primary: #0b5fff;
  --primary-dark: #0847c4;
  --border: #d8dee6;
  --success: #0f7b3a;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
  --input-bg: #ffffff;
  --radius: 12px;
  --header-h: 3.5rem;
  --site-max: 72rem;
  --content-max: var(--site-max);
  --site-gutter: 1rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.read-only-banner {
  background: #fff8e6;
  border-bottom: 1px solid #f5d98c;
  color: #7a5d00;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  text-align: center;
}

.app-read-only .write-action {
  display: none !important;
}

.app-body {
  min-height: 100vh;
}

.app-body.nav-open {
  overflow: hidden;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 200;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  padding-top: env(safe-area-inset-top, 0);
}

.site-header__bar {
  max-width: min(100%, var(--site-max));
  margin: 0 auto;
  padding: 0.5rem var(--site-gutter);
  min-height: var(--header-h);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(5.5rem, 11rem) auto;
  align-items: center;
  column-gap: 0.5rem;
  row-gap: 0;
}

.site-header__left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  grid-column: 1;
  grid-row: 1;
}

.site-header__brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  color: #fff;
  text-decoration: none;
}

.site-header__logo {
  display: block;
  height: 1.65rem;
  width: auto;
  max-width: 8.5rem;
  object-fit: contain;
  flex-shrink: 0;
}

.site-header__search-wrap {
  grid-column: 3;
  grid-row: 1;
  min-width: 0;
}

.site-header__search {
  position: relative;
  width: 100%;
  min-width: 0;
}

.global-search-input {
  width: 100%;
  min-width: 0;
  padding: 0.45rem 0.7rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font: inherit;
  font-size: 0.86rem;
}

.global-search-input::placeholder {
  color: rgba(255, 255, 255, 0.75);
}

.global-search-input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.65);
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
}

.global-search-results {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  left: auto;
  width: max(100%, 22rem);
  min-width: 22rem;
  max-width: min(36rem, calc(100vw - 1.5rem));
  z-index: 300;
  max-height: min(70vh, 28rem);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 0.5rem;
}

.global-search-group__title {
  padding: 0.45rem 0.65rem 0.25rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.global-search-item {
  display: block;
  padding: 0.65rem;
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
}

.global-search-item:hover {
  background: var(--bg);
}

.global-search-item__type {
  display: inline-block;
  margin-bottom: 0.2rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--primary-dark);
  text-transform: uppercase;
}

.global-search-item__title {
  display: block;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
  word-break: break-word;
}

.global-search-item__meta {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.35;
  word-break: break-word;
}

.global-search-empty,
.global-search-footer {
  display: block;
  padding: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

.global-search-footer {
  border-top: 1px solid var(--border);
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

.global-search-footer:hover {
  background: var(--bg);
}

.global-search-page-form {
  margin-bottom: 1rem;
}

.search-results {
  display: grid;
  gap: 1.25rem;
}

.search-results-group__title {
  margin: 0 0 0.65rem;
  font-size: 1rem;
  color: var(--text);
}

.search-results-group__list {
  display: grid;
  gap: 0.65rem;
}

.search-result-item {
  display: block;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  text-decoration: none;
  color: inherit;
}

.search-result-item:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(11, 95, 255, 0.1);
}

.search-result-item__main {
  display: grid;
  gap: 0.35rem;
}

.search-result-item__meta {
  font-size: 0.88rem;
  color: var(--muted);
}

.site-header__nav {
  display: none;
}

.site-header__user {
  position: relative;
  flex-shrink: 0;
  grid-column: 4;
  grid-row: 1;
  justify-self: end;
}

.nav-toggle {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  border-radius: 8px;
  width: 2.35rem;
  height: 2.35rem;
  font-size: 1.15rem;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
  padding: 0;
}

.nav-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

.desktop-nav__link {
  color: rgba(255, 255, 255, 0.92);
  text-decoration: none;
  padding: 0.4rem 0.65rem;
  border-radius: 8px;
  font-size: 0.95rem;
  white-space: nowrap;
}

.desktop-nav__link:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.desktop-nav__link.is-active {
  background: rgba(255, 255, 255, 0.2);
  font-weight: 700;
  color: #fff;
}

.desktop-nav__link--disabled {
  opacity: 0.65;
  cursor: not-allowed;
  font-size: 0.95rem;
  padding: 0.4rem 0.65rem;
}

.user-menu-toggle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  border-radius: 999px;
  padding: 0.2rem 0.55rem 0.2rem 0.2rem;
  cursor: pointer;
  font: inherit;
}

.user-menu-toggle:hover {
  background: rgba(255, 255, 255, 0.18);
}

.user-menu-toggle__avatar {
  display: inline-grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  font-size: 0.85rem;
  font-weight: 700;
}

.user-menu-toggle__name {
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}

.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  min-width: 11rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  z-index: 120;
}

.user-menu a {
  display: block;
  padding: 0.65rem 0.85rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.user-menu a:hover,
.user-menu__action:hover {
  background: var(--bg);
}

.user-menu__action {
  display: block;
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.nav-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  z-index: 150;
}

.nav-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(18rem, 85vw);
  background: var(--surface);
  z-index: 160;
  padding: 1rem 0;
  overflow-y: auto;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
}

.nav-drawer__title {
  padding: 0.5rem 1rem 0.75rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}

.nav-drawer__link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.nav-drawer__link:hover {
  background: var(--bg);
}

.nav-drawer__link.is-active {
  background: #e8f0ff;
  color: var(--primary-dark);
}

.nav-drawer__link--disabled {
  opacity: 0.72;
  cursor: not-allowed;
}

.nav-drawer__link--logout {
  color: var(--danger);
}

.nav-drawer__badge {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #eef2f7;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
}

.nav-drawer__divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.5rem 0;
}

.nav-drawer__theme {
  width: 100%;
  background: transparent;
  border-radius: 0;
  cursor: pointer;
  text-align: left;
}

.desktop-only {
  display: none;
}

.app-main {
  max-width: var(--site-max);
  margin: 0 auto;
  padding: var(--site-gutter);
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
}

.page-intro {
  margin-bottom: 1rem;
}

.page-intro__title {
  margin: 0.35rem 0 0;
  font-size: 1.35rem;
}

@media (min-width: 900px) {
  .site-header__bar {
    grid-template-columns: auto minmax(0, 1fr) 11rem auto;
    align-items: center;
    column-gap: 0.5rem;
    row-gap: 0;
  }

  .nav-toggle {
    display: none;
  }

  .site-header__nav {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 0.1rem;
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
  }

  .site-header__search-wrap {
    grid-column: 3;
    grid-row: 1;
    min-width: 0;
  }

  .site-header__search {
    width: 11rem;
  }

  .global-search-input {
    padding: 0.38rem 0.65rem;
    font-size: 0.84rem;
  }

  .desktop-nav__link {
    padding: 0.35rem 0.5rem;
    font-size: 0.88rem;
  }

  .desktop-nav__link--disabled {
    padding: 0.35rem 0.5rem;
    font-size: 0.88rem;
  }

  .site-header__left {
    grid-column: 1;
  }

  .site-header__user {
    grid-column: 4;
  }

  .desktop-only {
    display: inline;
  }
}

@media (min-width: 900px) and (max-width: 1100px) {
  .user-menu-toggle__name {
    display: none;
  }

  .site-header__bar {
    grid-template-columns: auto minmax(0, 1fr) 9.5rem auto;
  }

  .site-header__search {
    width: 9.5rem;
  }

  .desktop-nav__link,
  .desktop-nav__link--disabled {
    padding: 0.3rem 0.4rem;
    font-size: 0.82rem;
  }
}

@media (max-width: 720px) {
  :root {
    --site-gutter: 0.75rem;
  }

  .app-main {
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
  }

  .site-header__bar {
    column-gap: 0.4rem;
    grid-template-columns: auto minmax(0, 1fr) minmax(4.5rem, 1fr) auto;
  }

  .site-header__search-wrap,
  .site-header__search {
    overflow: visible;
  }

  .global-search-input {
    padding: 0.42rem 0.6rem;
    font-size: 0.84rem;
  }

  .global-search-results {
    position: fixed;
    top: calc(var(--header-h) + env(safe-area-inset-top, 0px) + 0.35rem);
    left: var(--site-gutter);
    right: var(--site-gutter);
    width: auto;
    min-width: 0;
    max-width: none;
  }
}

.dashboard-welcome h2,
.dashboard-section h2,
.section-heading h2 {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
}

.dashboard-lead {
  margin: 0;
  color: var(--muted);
}

.dashboard-section {
  margin-top: 1rem;
}

.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.85rem;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fafc;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.stat-card:hover {
  border-color: #93c5fd;
  box-shadow: 0 2px 8px rgba(11, 95, 255, 0.08);
}

.stat-card--muted {
  cursor: default;
  background: #fff;
}

.stat-card--muted:hover {
  border-color: var(--border);
  box-shadow: none;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}

.stat-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.stat-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.coming-soon-panel {
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
}

.coming-soon-title {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.coming-soon-text {
  margin: 0;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 720px) {
  .grid.two {
    grid-template-columns: 1fr 1fr;
  }
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  background: var(--input-bg);
  color: var(--text);
}

textarea {
  min-height: 110px;
  resize: vertical;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font: inherit;
  cursor: pointer;
}

button.primary {
  background: var(--primary);
  color: #fff;
}

button.primary:hover {
  background: var(--primary-dark);
}

button.secondary {
  background: #eef2f7;
  color: var(--text);
}

button.danger {
  background: #fee4e2;
  color: var(--danger);
}

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge.online {
  background: #dcfae6;
  color: var(--success);
}

.badge.offline {
  background: #fef0c7;
  color: #b54708;
}

.report-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.report-item {
  border-top: 1px solid var(--border);
  padding: 0.85rem 0;
  display: grid;
  gap: 0.35rem;
}

.report-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.report-item strong {
  font-size: 0.95rem;
}

.report-meta {
  font-size: 0.82rem;
  color: var(--muted);
}

.report-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.report-actions button {
  padding: 0.4rem 0.65rem;
  font-size: 0.82rem;
}

.empty-state {
  color: var(--muted);
  font-size: 0.92rem;
}

.message {
  margin-top: 0.75rem;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  font-size: 0.875rem;
}

.message.success {
  background: #dcfae6;
  color: var(--success);
}

.message.error {
  background: #fee4e2;
  color: var(--danger);
}

.message.info {
  background: #eff8ff;
  color: #175cd3;
}

.hidden {
  display: none !important;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.25rem;
  padding: 0.35rem 0.85rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}

.back-link:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: var(--primary-dark);
  text-decoration: none;
}

.nav-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 720px) {
  .nav-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.nav-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  min-height: 160px;
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.nav-card:hover,
.nav-card:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(16, 24, 40, 0.12);
  outline: none;
}

.nav-icon {
  font-size: 2rem;
  line-height: 1;
}

.nav-label {
  font-size: 1.35rem;
  font-weight: 700;
}

.nav-hint {
  font-size: 0.92rem;
  color: var(--muted);
}

.nav-customers {
  border-top: 4px solid #0b5fff;
}

.nav-machines {
  border-top: 4px solid #7a5af8;
}

.nav-reports {
  border-top: 4px solid #12b76a;
}

.nav-users {
  border-top: 4px solid #f79009;
}

.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.page-toolbar .toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.list-search {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  margin-bottom: 1rem;
  min-height: 44px;
  background: #fff;
}

.list-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 95, 255, 0.12);
}

.list-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: -0.35rem 0 1rem;
}

.list-filter {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: min(100%, 11rem);
  flex: 1 1 11rem;
}

.list-filter-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.list-filter select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  min-height: 44px;
  background: #fff;
  color: inherit;
}

.list-filter select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 95, 255, 0.12);
}

.page-toolbar h2 {
  margin: 0;
}

.count-badge {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  background: #eef2f7;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
}

.data-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.data-item {
  display: grid;
  gap: 0.75rem;
  border-top: 1px solid var(--border);
  padding: 1rem 0;
}

@media (min-width: 720px) {
  .data-item {
    grid-template-columns: 1fr auto;
    align-items: start;
  }
}

.data-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.data-item-main strong {
  display: block;
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.data-meta {
  font-size: 0.88rem;
  color: var(--muted);
}

.data-notes {
  margin-top: 0.45rem;
  font-size: 0.88rem;
  color: var(--text);
}

.data-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #eef2f7;
  color: var(--text);
}

.muted {
  color: var(--muted);
}

.data-item-link {
  display: grid;
  gap: 0.75rem;
  color: inherit;
  text-decoration: none;
}

@media (min-width: 720px) {
  .data-item-link {
    grid-template-columns: 1fr auto;
    align-items: start;
  }
}

.data-item-link:hover strong {
  color: var(--primary);
}

.toolbar-actions a.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  background: var(--primary);
  color: #fff;
}

.toolbar-actions a.button-link:hover {
  background: var(--primary-dark);
}
