.app-layout {
  min-height: 100vh;
  padding-bottom: 78px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: inline-grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 800;
}

.brand h1, .brand-block h1 {
  margin: 0;
  font-size: 1rem;
}

.brand p, .brand-block p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: .85rem;
}

.content {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: 18px 16px 28px;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-top: 1px solid var(--line);
  background: var(--nav-bg);
}

.bottom-nav a {
  display: grid;
  gap: 3px;
  min-height: 64px;
  place-items: center;
  padding: 8px 4px;
  color: var(--muted);
  font-size: .72rem;
}

.bottom-nav a.active {
  color: var(--primary);
  background: rgba(37, 99, 235, .10);
}

.nav-icon { font-size: 1.25rem; line-height: 1; }

.page-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.page-title h2 { margin: 0; font-size: 1.45rem; }
.page-title p { margin: 4px 0 0; color: var(--muted); }

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

.grid.two, .grid.three { grid-template-columns: 1fr; }

.content > .grid,
.content > .panel {
  margin-bottom: 16px;
}

.content > .grid + .panel,
.content > .panel + .panel,
.content > .panel + .grid {
  margin-top: 16px;
}

.card, .panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card { padding: 16px; }
.panel { padding: 18px; margin-bottom: 16px; }

.panel h3 {
  margin-bottom: 18px;
}

.stat-value {
  margin: 4px 0 0;
  font-size: 1.6rem;
  font-weight: 800;
}

.form-stack {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: .9rem;
}

input, select, textarea {
  width: 100%;
  max-width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field-bg);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 19px, calc(100% - 12px) 19px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }

.native-select-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 1px;
  margin: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.custom-select {
  position: relative;
  width: 100%;
}

.custom-select-button {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field-bg);
  color: var(--text);
  padding: 11px 34px 11px 12px;
  text-align: left;
  font: inherit;
}

.custom-select-button::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 0;
  height: 0;
  border-right: 6px solid transparent;
  border-left: 6px solid transparent;
  border-top: 7px solid var(--muted);
  transform: translateY(-35%);
}

.custom-select.open .custom-select-button {
  border-color: var(--primary);
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0;
}

.custom-select-menu {
  position: absolute;
  top: calc(100% - 1px);
  right: 0;
  left: 0;
  z-index: 80;
  display: none;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--primary);
  border-top: 0;
  border-bottom-right-radius: var(--radius);
  border-bottom-left-radius: var(--radius);
  background: var(--field-bg);
  box-shadow: 0 14px 30px rgba(0, 0, 0, .32);
}

.custom-select.open .custom-select-menu {
  display: grid;
}

.custom-select-option {
  width: 100%;
  min-height: 42px;
  border: 0;
  background: var(--field-bg);
  color: var(--text);
  padding: 10px 12px;
  text-align: left;
  font: inherit;
}

.custom-select-option:hover,
.custom-select-option:focus,
.custom-select-option.selected {
  background: rgba(37, 99, 235, .14);
  color: var(--text);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-weight: 700;
}

.button.primary { background: transparent; color: var(--primary); border-color: var(--primary); }
.button.secondary { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.button.ghost { background: transparent; color: var(--primary); border-color: var(--line); }
.button.danger { background: var(--danger); color: #2b070e; }
.button:disabled { opacity: .55; cursor: not-allowed; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

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

.list-item {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field-bg);
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: .78rem;
  font-weight: 800;
}

.badge.open { background: rgba(34, 197, 94, .14); color: #86efac; }
.badge.draft { background: rgba(148, 163, 184, .14); color: #cbd5e1; }
.badge.closing { background: rgba(245, 158, 11, .16); color: #fcd34d; }
.badge.closed { background: rgba(96, 165, 250, .16); color: #bfdbfe; }
.badge.cancelled { background: rgba(251, 113, 133, .16); color: #fecdd3; }
.badge.payment-paid { background: rgba(34, 197, 94, .16); color: #86efac; }
.badge.payment-pending { background: rgba(245, 158, 11, .18); color: #fcd34d; }

.message {
  min-height: 22px;
  color: var(--muted);
}

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

@media (min-width: 760px) {
  .app-layout { padding-bottom: 0; padding-left: 220px; }
  .bottom-nav {
    top: 0;
    right: auto;
    width: 220px;
    grid-template-columns: 1fr;
    align-content: start;
    border-top: 0;
    border-right: 1px solid var(--line);
  }
  .bottom-nav a {
    grid-template-columns: 28px 1fr;
    justify-items: start;
    min-height: 52px;
    padding: 10px 16px;
    font-size: .92rem;
  }
  .topbar { left: 220px; }
  .grid.two { grid-template-columns: repeat(2, 1fr); }
  .grid.three { grid-template-columns: repeat(3, 1fr); }
}
