html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, "Segoe UI", sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
}

a {
  text-decoration: none;
}

.app-body-shell {
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

.app-main {
  flex: 1;
  min-width: 0;
  padding: 24px;
  overflow-y: auto;
  background: var(--bg-base);
}

.app-main-shell {
  width: min(1400px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 56px;
  padding: 0 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-default);
  position: sticky;
  top: 0;
  z-index: 40;
  flex-shrink: 0;
}

.topbar-left,
.topbar-actions,
.topbar-user-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-left {
  min-width: 0;
}

.topbar-brand-link {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  min-width: 0;
}

.topbar-brand-logo {
  height: 40px;
  width: auto;
  display: block;
  flex-shrink: 0;
}

.topbar-brand-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar-brand-title,
.topbar-user-name {
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-brand-title {
  font-size: 0.98rem;
  line-height: 1.1;
}

.topbar-brand-subtitle {
  color: var(--text-secondary);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  line-height: 1.15;
}

.topbar-mode-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(247, 184, 75, 0.12);
  color: var(--text-primary);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.topbar-toggle {
  display: none;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border-default);
  border-radius: 10px;
  background: var(--surface-1);
  color: var(--text-secondary);
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.18s ease-out, border-color 0.18s ease-out, color 0.18s ease-out;
}

.topbar-toggle:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.topbar-toggle svg {
  width: 18px;
  height: 18px;
}

.topbar-actions {
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 10px;
  border: 1px solid var(--border-default);
  background: var(--surface-3);
}

.topbar-control-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.topbar-control-group .inline-form {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.topbar-control {
  min-width: 112px;
  border-color: var(--border-default);
  background: var(--surface-2);
}

.topbar-select {
  font-size: 0.78rem;
}

.topbar-lang-btn {
  padding: 3px 8px;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.topbar-lang-btn.active,
.topbar-lang-btn:hover {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  color: var(--text-inverse);
}

.topbar-user-card {
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid var(--border-default);
  border-radius: 12px;
  background: var(--surface-1);
  min-width: 0;
}

.topbar-user-button {
  color: inherit;
  cursor: pointer;
}

.topbar-user-button:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
  color: inherit;
}

.topbar-user-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.topbar-user-name {
  font-size: 0.82rem;
  line-height: 1.1;
}

.topbar-user-role,
.stat-label,
.stat-subtext,
.page-header p,
.text-secondary {
  color: var(--text-secondary) !important;
}

.topbar-user-role {
  font-size: 0.72rem;
  line-height: 1.1;
}

.topbar-logout-button {
  min-height: 38px;
}

.topbar-actions-phone {
  flex: 0 0 auto !important;
  min-width: auto !important;
  gap: 6px !important;
  overflow: visible !important;
}

.topbar-control-group-phone {
  padding: 4px 6px !important;
  gap: 4px !important;
}

.topbar-control-group-phone .inline-form {
  gap: 6px !important;
}

.topbar-control-group-phone .topbar-lang-btn {
  min-width: 34px;
  padding: 2px 6px;
}

.topbar-user-card-phone {
  width: 42px !important;
  min-width: 42px !important;
  flex: 0 0 42px !important;
  padding: 4px !important;
  gap: 0 !important;
  justify-content: center !important;
  border-radius: 9999px !important;
}

.topbar-user-card-phone .topbar-user-meta {
  display: none !important;
}

.topbar-user-card-phone .avatar-circle {
  width: 32px;
  height: 32px;
}

.topbar-logout-button-phone {
  min-width: 42px !important;
  padding: 0 !important;
}

.avatar-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand-primary);
  color: var(--text-inverse);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.app-sidebar-frame {
  width: 240px;
  flex-shrink: 0;
}

.sidebar-shell {
  width: 240px;
  height: calc(100vh - 56px);
  padding: 16px 12px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
  position: sticky;
  top: 56px;
  overflow-y: auto;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-heading {
  padding: 0 8px 10px;
  color: var(--sidebar-muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--sidebar-muted);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background 0.18s ease-out, color 0.18s ease-out, border-color 0.18s ease-out;
}

.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

.sidebar-link.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text);
  border-color: rgba(255, 255, 255, 0.12);
}

.sidebar-link-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-link-icon svg {
  width: 16px;
  height: 16px;
}

.sidebar-link-label {
  min-width: 0;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 56px 0 0;
  border: 0;
  padding: 0;
  background: rgba(15, 23, 42, 0.36);
  z-index: 29;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow-soft);
}

.btn {
  border-radius: 8px;
  font-weight: 500;
}

.btn-primary {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
}

.btn-primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}

.btn-secondary {
  background: var(--surface-3);
  border-color: var(--border-default);
  color: var(--text-primary);
}

.btn-danger {
  background: rgba(240, 101, 72, 0.12);
  border-color: rgba(240, 101, 72, 0.28);
  color: var(--danger);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.badge {
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 600;
}

.badge-primary {
  background: rgba(64, 81, 137, 0.12);
  color: var(--brand-primary);
}

.badge-success {
  background: rgba(10, 179, 156, 0.14);
  color: var(--success);
}

.badge-warning {
  background: rgba(247, 184, 75, 0.18);
  color: #8b5e05;
}

.badge-danger {
  background: rgba(240, 101, 72, 0.14);
  color: var(--danger);
}

.form-input {
  border-radius: 8px;
  border-color: var(--border-default);
  background: var(--surface-2);
}

.form-input:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 0.25rem var(--focus-ring);
}

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

.page-header.split {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.page-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.stats-grid,
.form-card-grid,
.team-grid {
  display: grid;
  gap: 16px;
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 22px;
}

.content-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 18px;
}

.settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card {
  min-height: 140px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--brand-primary);
}

.section-header {
  margin-bottom: 16px;
}

.section-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.activity-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.activity-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  align-items: center;
  gap: 12px;
}

.activity-bar {
  height: 8px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}

.activity-bar span {
  display: block;
  height: 100%;
  background: var(--brand-primary);
}

.app-table th {
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border-default);
}

.app-table td {
  vertical-align: middle;
  border-bottom-color: var(--border-subtle);
}

.mono-text,
.text-brand {
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

.text-brand {
  color: var(--brand-hover);
}

.custom-modal-shell {
  border: 1px solid var(--border-default);
  border-radius: 16px;
}

.detail-grid,
.settings-list,
.submission-values {
  display: grid;
  gap: 12px;
}

.detail-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.detail-item,
.submission-value-row,
.team-stat-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.settings-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.settings-list dt {
  color: var(--text-secondary);
}

.attachment-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.attachment-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border-default);
  border-radius: 10px;
  color: var(--text-primary);
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(64, 81, 137, 0.18), transparent 30%),
    linear-gradient(135deg, #eef2ff, #f8fafc 55%, #eef8f6);
}

.auth-shell {
  width: min(1120px, 100%);
}

.auth-card {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 24px;
  align-items: stretch;
}

.auth-card.single-column {
  grid-template-columns: 1fr;
  max-width: 520px;
  margin-inline: auto;
}

.auth-card-copy,
.auth-form-card {
  padding: 32px;
}

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

.auth-brand-full {
  margin-bottom: 16px;
}

.auth-brand-logo {
  height: 40px;
  width: auto;
  display: block;
  flex-shrink: 0;
}

.auth-brand-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.auth-brand-label {
  color: var(--brand-primary);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.1;
  text-transform: uppercase;
}

.auth-card-copy > p {
  margin-top: 0;
}

.auth-card-copy h1 {
  margin-top: 16px;
  font-size: 2.6rem;
  font-weight: 700;
}

.builder-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 320px;
  gap: 18px;
}

.builder-sidebar {
  align-self: start;
}

.builder-palette,
.builder-canvas-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.builder-palette-item,
.builder-canvas-item {
  border: 1px solid var(--border-default);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 12px 14px;
}

.builder-palette-item {
  text-align: left;
}

.builder-canvas-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
}

.builder-canvas-item.selected {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.builder-field-name,
.form-title-input {
  font-weight: 700;
}

.builder-field-meta,
.form-card-meta {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.builder-field-actions {
  display: flex;
  gap: 6px;
}

.builder-empty-state,
.builder-option-box {
  border: 1px dashed var(--border-default);
  border-radius: 10px;
  padding: 16px;
  background: var(--surface-3);
}

.form-fill-card {
  max-width: 840px;
}

.form-field-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.attachment-picker-input {
  display: none;
}

.attachment-picker-button {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px;
  text-align: center;
  border: 2px dashed var(--border-strong);
  border-radius: 10px;
  background: var(--bg-base);
  color: var(--text-secondary);
  cursor: pointer;
}

.attachment-picker-button:hover {
  border-color: var(--brand-primary);
  background: var(--surface-3);
}

.attachment-picker-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.attachment-picker-summary {
  font-size: 0.875rem;
}

.attachment-picker-hint {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.rfms-picker {
  display: flex;
  gap: 10px;
}

.rfms-picker-modal .modal-body {
  padding-top: 12px;
}

.rfms-table-wrap {
  position: relative;
  max-height: 60vh;
  overflow: auto;
  border: 1px solid var(--border-default);
  border-radius: 10px;
  background: var(--surface-1, #fff);
}

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

.rfms-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2, #f3f4f6);
  color: var(--text-primary);
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}

.rfms-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle, #eef0f3);
  color: var(--text-primary);
  vertical-align: middle;
}

.rfms-row {
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.rfms-row:hover,
.rfms-row:focus {
  background: var(--surface-2, #f3f4f6);
  outline: none;
}

.rfms-order-id {
  color: var(--brand-primary, #1976d2);
  font-weight: 500;
}

.rfms-status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2, #eef0f3);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border-default);
}

.rfms-table-message {
  padding: 24px;
  text-align: center;
  font-size: 14px;
}

.inline-form {
  margin: 0;
}

@media (max-width: 1200px) {
  .stats-grid,
  .content-grid,
  .builder-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .auth-card,
  .page-header.split {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar {
    padding: 10px 16px;
    align-items: center;
  }

  .topbar-left {
    width: auto;
    min-width: 0;
  }

  .topbar-actions {
    width: auto;
    min-width: 0;
    flex: 1 1 auto;
    gap: 8px;
    flex-wrap: nowrap;
    justify-content: flex-end;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .topbar-toggle {
    display: inline-flex;
  }

  .topbar-mode-badge {
    margin-left: auto;
  }

  .topbar-user-card {
    flex: 0 1 220px;
  }

  .topbar-user-role {
    display: none;
  }

  .app-sidebar-frame {
    position: fixed;
    inset: 56px auto 0 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.22s ease-out;
  }

  .sidebar-shell {
    height: calc(100vh - 56px);
  }

  .app-shell.sidebar-open .app-sidebar-frame {
    transform: translateX(0);
  }

  .app-shell.sidebar-open .sidebar-backdrop {
    display: block;
  }

  .detail-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-main {
    padding: 18px 14px;
  }

  .topbar-brand-subtitle,
  .topbar-control-label {
    display: none;
  }

  .topbar-actions {
    gap: 8px;
    justify-content: flex-end;
  }

  .topbar-control-group {
    width: auto;
    flex-shrink: 0;
    gap: 6px;
    padding: 4px 8px;
    justify-content: flex-start;
  }

  .topbar-control-group .inline-form {
    gap: 8px;
  }

  .topbar-user-card {
    width: auto;
    flex: 1 1 auto;
    min-width: 0;
    padding: 6px 8px;
  }

  .topbar-user-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-logout-button {
    width: auto;
    flex-shrink: 0;
    justify-content: center;
  }

  .topbar-control {
    min-width: 0;
    width: 100%;
  }
}
