:root {
  color-scheme: light;
  font-family: Inter, system-ui, "Segoe UI", sans-serif;

  --brand-primary: #2563EB;
  --brand-primary-hover: #1D4ED8;
  --brand-primary-light: #EFF6FF;
  --brand-text: #0F172A;
  --brand-muted: #64748B;
  --surface: #FFFFFF;
  --page-bg: #F8FAFC;
  --border: #E2E8F0;
  --border-light: #F1F5F9;
  --border-input: #CBD5E1;
  --danger: #DC2626;
  --danger-hover: #B91C1C;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page-bg);
  color: var(--brand-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Top bar (Document Scanner style) */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.02);
  flex-shrink: 0;
}

.top-bar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.top-bar-brand:hover {
  opacity: 0.9;
}

.top-bar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.top-bar-brand-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--brand-text);
}

.top-bar-brand-subtitle {
  font-size: 12px;
  color: var(--brand-muted);
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-bar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
}

.top-bar-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: #E2E8F0;
  font-size: 12px;
  font-weight: 500;
  color: #334155;
}

.top-bar-user-name {
  font-size: 14px;
  color: #334155;
}

.top-bar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.top-bar-link {
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #475569;
  text-decoration: none;
  transition: background 0.15s ease;
}

.top-bar-link:hover {
  background: #F1F5F9;
  color: var(--brand-text);
}

.logo {
  height: 40px;
  width: auto;
}

.logo--large {
  height: 48px;
}

/* Main layout */

.site-main {
  display: flex;
  justify-content: center;
  padding: 48px 16px;
}

.site-main--auth {
  align-items: center;
  min-height: calc(100vh - 56px);
  padding: 32px 16px;
}

.site-main--dashboard {
  justify-content: center;
  padding: 32px 24px 48px;
}

/* Hub layout */

.body--hub {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.hub-shell {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #475569;
  text-decoration: none;
  transition: all 0.15s ease;
  position: relative;
}

.sidebar-nav-item:hover {
  background: #F1F5F9;
  color: var(--brand-text);
}

.sidebar-nav-item--active {
  background: var(--brand-primary-light);
  color: var(--brand-primary);
  font-weight: 600;
}

.sidebar-nav-item--active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 15%;
  bottom: 15%;
  width: 4px;
  background: var(--brand-primary);
  border-radius: 0 4px 4px 0;
}

.sidebar-nav-item--external::after {
  content: "↗";
  margin-left: auto;
  font-size: 12px;
  opacity: 0.6;
}

.sidebar-nav-icon {
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  font-size: 14px;
}

.site-main--hub {
  flex: 1;
  justify-content: flex-start;
  align-items: stretch;
  padding: 32px 32px 48px;
  overflow-y: auto;
}

.hub-content {
  width: 100%;
  max-width: 960px;
}

.hub-content--narrow {
  max-width: 560px;
}

/* Settings */

.settings-section {
  margin-bottom: 32px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  box-shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.02);
}

.settings-section h2 {
  margin: 0 0 16px;
  font-size: 14px;
  font-weight: 600;
}

.settings-list {
  margin: 0;
}

.settings-row {
  display: flex;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row dt {
  width: 100px;
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--brand-muted);
}

.settings-row dd {
  margin: 0;
  font-size: 14px;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.auth-card--inline {
  border: none;
  box-shadow: none;
  padding: 0;
}

/* Data table */

.data-table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

.data-table th {
  font-weight: 600;
  color: var(--brand-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.status-badge--active {
  background: #DCFCE7;
  color: #166534;
}

.status-badge--suspended {
  background: #FEE2E2;
  color: #991B1B;
}

.form-panel {
  margin-bottom: 24px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  box-shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.02);
}

.form-panel h2 {
  margin: 0 0 16px;
  font-size: 14px;
  font-weight: 600;
}

.form-grid {
  display: grid;
  gap: 16px;
}

.form-grid label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: #475569;
}

.form-grid input,
.form-grid select {
  padding: 8px 12px;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
}

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}

.alert--success {
  background: #DCFCE7;
  color: #166534;
  border: 1px solid #BBF7D0;
}

.alert--error {
  background: #FEE2E2;
  color: #991B1B;
  border: 1px solid #FECACA;
}

.alert--info {
  background: var(--brand-primary-light);
  color: var(--brand-primary);
  border: 1px solid #BFDBFE;
}

.billing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.billing-card {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  box-shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.02);
}

.billing-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.billing-card p {
  margin: 0 0 16px;
  color: var(--brand-muted);
  font-size: 14px;
}

.billing-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  .hub-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
  }

  .sidebar-nav-item {
    padding: 8px 10px;
    font-size: 13px;
  }

  .sidebar-nav-icon {
    display: none;
  }

  .site-main--hub {
    padding: 24px 16px 32px;
  }
}

/* Auth shell */

.auth-shell {
  width: 100%;
  max-width: 420px;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  margin-bottom: 24px;
}

.auth-brand-tagline {
  margin: 0;
  font-size: 14px;
  color: var(--brand-muted);
}

.auth-card {
  width: 100%;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.05), 0 8px 10px -6px rgba(15, 23, 42, 0.01);
}

.auth-card h1 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 600;
  color: var(--brand-text);
}

.subtitle {
  margin: 0 0 24px;
  color: var(--brand-muted);
  font-size: 14px;
  line-height: 1.5;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: #475569;
}

.auth-form input[type="text"],
.auth-form input[type="email"],
.auth-form input[type="password"] {
  padding: 8px 12px;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  color: var(--brand-text);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.checkbox {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 14px !important;
  font-weight: 400 !important;
  color: var(--brand-text) !important;
}

.validation-summary {
  color: var(--danger);
  font-size: 14px;
}

.auth-footer {
  margin: 24px 0 0;
  text-align: center;
  font-size: 14px;
  color: var(--brand-muted);
}

.auth-footer a {
  color: var(--brand-primary);
  font-weight: 500;
  text-decoration: none;
}

.auth-footer a:hover {
  text-decoration: underline;
}

.auth-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.auth-actions .btn-primary,
.auth-actions .btn-secondary {
  flex: 1;
}

/* Google sign-in */

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  background: var(--surface);
  color: var(--brand-text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: default;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-google-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--brand-muted);
  font-size: 12px;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
}

.btn-primary {
  background: linear-gradient(180deg, var(--brand-primary) 0%, var(--brand-primary-hover) 100%);
  color: #fff;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.btn-primary:hover {
  background: linear-gradient(180deg, var(--brand-primary-hover) 0%, #1e40af 100%);
  box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.15), inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-secondary {
  background: var(--surface);
  color: var(--brand-text);
  border: 1px solid var(--border-input);
}

.btn-secondary:hover {
  background: var(--page-bg);
  border-color: var(--brand-muted);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.auth-form .btn-primary {
  margin-top: 4px;
  width: 100%;
}

/* Dashboard */

.apps-dashboard {
  width: 100%;
  max-width: 960px;
}

.page-header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.page-header-greeting h1 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 600;
}

.page-header-greeting .subtitle {
  margin: 0;
  font-size: 14px;
}

.apps-section + .apps-section {
  margin-top: 40px;
}

.apps-section h2 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--brand-text);
}

.section-hint {
  margin: 0 0 16px;
  color: var(--brand-muted);
  font-size: 14px;
}

.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.app-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.02), 0 2px 4px -2px rgba(15, 23, 42, 0.02);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-card:hover {
  border-color: #BFDBFE;
  transform: translateY(-2px);
  box-shadow: 0 12px 20px -5px rgba(37, 99, 235, 0.08), 0 8px 10px -6px rgba(37, 99, 235, 0.04);
}

.app-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  object-fit: cover;
}

.app-card-body {
  flex: 1;
}

.app-name {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.app-description {
  margin: 4px 0 0;
  color: var(--brand-muted);
  font-size: 14px;
  line-height: 1.4;
}

.app-launch {
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--brand-primary-light);
  color: var(--brand-primary);
  font-size: 12px;
  font-weight: 600;
}

.explore-list {
  display: grid;
  gap: 12px;
}

.explore-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px dashed var(--border-input);
  border-radius: 12px;
}

.explore-badge {
  margin-left: auto;
  padding: 4px 10px;
  border-radius: 999px;
  background: #F1F5F9;
  color: #475569;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.empty-state {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.empty-state p {
  margin: 0;
}

.empty-state-hint {
  margin-top: 8px !important;
  color: var(--brand-muted);
  font-size: 14px;
}

@media (max-width: 640px) {
  .top-bar-user-name {
    display: none;
  }

  .top-bar-nav {
    gap: 0;
  }

  .top-bar-link {
    font-size: 13px;
    padding: 6px;
  }

  .auth-actions {
    flex-direction: column;
  }
}

/* LOMA loading indicator */

@keyframes loma-loading {
  0% {
    transform: rotate(0deg) scale(1);
  }

  50% {
    transform: rotate(180deg) scale(1.12);
  }

  100% {
    transform: rotate(360deg) scale(1);
  }
}

.loma-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.loma-loading__icon {
  width: 40px;
  height: 40px;
  animation: loma-loading 1.4s ease-in-out infinite;
}

.loma-loading--sm .loma-loading__icon {
  width: 24px;
  height: 24px;
}

.loma-loading--lg .loma-loading__icon {
  width: 56px;
  height: 56px;
}

.loma-loading__message {
  margin: 0;
  font-size: 14px;
  color: var(--brand-muted);
}

.loma-page-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(248 250 252 / 0.92);
}

.loma-page-loader--hidden {
  display: none;
}
