/* ============================================================
   Grubtech brand tokens
   ============================================================ */
:root {
  /* Grubtech blue scale */
  --grubtech-50:  #f0f7fd;
  --grubtech-100: #dbeafa;
  --grubtech-200: #bed9f5;
  --grubtech-300: #91c0ec;
  --grubtech-400: #5da0de;
  --grubtech-500: #3988d0;
  --grubtech-600: #2b7ebc;
  --grubtech-700: #245f93;
  --grubtech-800: #1e4f7a;
  --grubtech-900: #1b4366;
  --grubtech-950: #122b44;

  /* Neutrals (Tailwind gray) */
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Semantic */
  --info-bg:    #eff6ff; --info-bd:    #bfdbfe; --info-tx:    #1e40af;
  --warn-bg:    #fffbeb; --warn-bd:    #fde68a; --warn-tx:    #92400e;
  --success-bg: #f0fdf4; --success-bd: #bbf7d0; --success-tx: #166534;
  --danger-bg:  #fef2f2; --danger-bd:  #fecaca; --danger-tx:  #991b1b;

  /* Brand gradient */
  --brand-gradient: linear-gradient(to right, #126EBB, #083255);
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
  min-height: 100vh;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--grubtech-600); text-decoration: none; }
a:hover { color: var(--grubtech-700); }

.muted { color: var(--gray-500); }
.muted-link { color: var(--gray-400); }
.muted-link:hover { color: var(--grubtech-600); }
.small { font-size: 12px; }
.empty {
  padding: 2rem;
  text-align: center;
  color: var(--gray-400);
  font-size: 13px;
}
.error {
  padding: 0.75rem 1rem;
  background: var(--danger-bg);
  border: 1px solid var(--danger-bd);
  color: var(--danger-tx);
  border-radius: 12px;
  font-size: 13px;
}

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--gray-100);
  height: 56px;
  display: flex;
  align-items: center;
}
.nav-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}
@media (min-width: 640px) { .nav-content { padding: 0 1.5rem; } }
@media (min-width: 1024px) { .nav-content { padding: 0 2rem; } }

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}
.brand img { height: 20px; width: auto; display: block; }
.brand-divider {
  width: 1px;
  height: 18px;
  background: var(--gray-200);
}
.brand-app {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-900);
  letter-spacing: -0.01em;
}

.nav-links {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}
.nav-links a {
  color: var(--gray-600);
  font-weight: 500;
  font-size: 13px;
  padding: 0.5rem 0.875rem;
  border-radius: 8px;
  transition: all 0.15s;
}
.nav-links a:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}
.nav-links a.active {
  background: var(--grubtech-50);
  color: var(--grubtech-700);
}

.link-btn {
  background: none;
  border: none;
  color: var(--gray-600);
  cursor: pointer;
  font: inherit;
  padding: 0.5rem 0.875rem;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  margin-left: 0.5rem;
}
.link-btn:hover {
  background: var(--gray-100);
  color: var(--gray-900);
}

/* ============================================================
   Container
   ============================================================ */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1rem;
}
@media (min-width: 640px) { .container { padding: 2rem 1.5rem; } }
@media (min-width: 1024px) { .container { padding: 2rem; } }

.container > h2 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 1.5rem 0;
  color: var(--gray-900);
}
.container > p { color: var(--gray-600); margin: -0.75rem 0 1.5rem; }

/* ============================================================
   Stats grid
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: all 0.15s;
}
.stat-card:hover {
  border-color: var(--grubtech-300);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
}
.stat-icon {
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--grubtech-50);
  border-radius: 10px;
  flex-shrink: 0;
}
.stat-content h3 {
  color: var(--gray-500);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 0.25rem 0;
}
.stat-number {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.stat-sub {
  font-size: 11px;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

/* ============================================================
   Layout
   ============================================================ */
.layout-2col {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.5rem;
}
@media (max-width: 1024px) {
  .layout-2col { grid-template-columns: 1fr; }
}

/* ============================================================
   Sections
   ============================================================ */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--gray-200);
}
.section-head h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-700);
  margin: 0;
}

.data-table,
.activity-feed,
.export-form {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  overflow: hidden;
}
.export-form { padding: 1.5rem; }

/* ============================================================
   Table controls
   ============================================================ */
.table-controls {
  padding: 1rem 1.25rem;
  display: flex;
  gap: 0.75rem;
  border-bottom: 1px solid var(--gray-200);
  flex-wrap: wrap;
}
input[type=text],
input[type=email],
input[type=password],
select {
  background: #fff;
  border: 1px solid var(--gray-300);
  color: var(--gray-900);
  padding: 0.625rem 0.875rem;
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type=text]::placeholder,
input[type=email]::placeholder,
input[type=password]::placeholder { color: var(--gray-400); }
input:focus,
select:focus {
  outline: none;
  border-color: var(--grubtech-500);
  box-shadow: 0 0 0 3px rgba(56, 136, 208, 0.2);
}

.table-controls input { flex: 1; min-width: 200px; }

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
  padding-right: 2.25rem;
}

/* ============================================================
   Table
   ============================================================ */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  background: var(--gray-50);
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--gray-700);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  border-bottom: 2px solid var(--gray-200);
}
td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: top;
  color: var(--gray-900);
}
tr:hover td { background: var(--gray-50); }
tr:last-child td { border-bottom: none; }

/* ============================================================
   Status badges
   ============================================================ */
.status-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 500;
  text-transform: capitalize;
}
.status-badge.completed {
  background: var(--success-bg);
  color: var(--success-tx);
}
.status-badge.pending {
  background: var(--warn-bg);
  color: var(--warn-tx);
}
.status-badge.in_progress {
  background: var(--grubtech-50);
  color: var(--grubtech-700);
}
.status-badge.failed {
  background: var(--danger-bg);
  color: var(--danger-tx);
}

/* ============================================================
   Pagination
   ============================================================ */
.pagination {
  padding: 0.875rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  border-top: 1px solid var(--gray-200);
}

/* ============================================================
   Activity feed
   ============================================================ */
.activity-feed { display: flex; flex-direction: column; max-height: 700px; }
#activity-log {
  overflow-y: auto;
  padding: 0.25rem 0;
}
.event {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--gray-100);
}
.event:last-child { border-bottom: none; }
.event-icon { font-size: 14px; flex-shrink: 0; line-height: 1.4; }
.event-body { flex: 1; min-width: 0; font-size: 13px; color: var(--gray-700); }

/* ============================================================
   Buttons
   ============================================================ */
button {
  background: var(--grubtech-600);
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}
button:hover:not(:disabled) { background: var(--grubtech-700); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary {
  background: var(--gray-100);
  color: var(--gray-700);
}
button.secondary:hover:not(:disabled) {
  background: var(--gray-200);
  color: var(--gray-900);
}

/* ============================================================
   Auth page
   ============================================================ */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  background:
    radial-gradient(ellipse at top left, rgba(43, 126, 188, 0.08), transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(43, 126, 188, 0.06), transparent 50%),
    var(--gray-50);
}
.auth-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 50px -10px rgba(18, 110, 187, 0.15);
}
.auth-brand {
  display: flex;
  justify-content: center;
  margin-bottom: 1.5rem;
}
.auth-brand img { height: 24px; }
.auth-card h1 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 0.25rem 0;
  text-align: center;
  color: var(--gray-900);
  letter-spacing: -0.01em;
}
.auth-card p { margin: 0 0 1.75rem 0; text-align: center; }
.auth-card form { display: flex; flex-direction: column; gap: 1rem; }
.auth-card label {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
}
.auth-card button { padding: 0.75rem; font-size: 14px; }
.auth-card .error,
.auth-card .info {
  margin-top: 0.5rem;
  text-align: center;
}
.auth-card .info {
  padding: 0.75rem 1rem;
  background: var(--info-bg);
  border: 1px solid var(--info-bd);
  color: var(--info-tx);
  border-radius: 12px;
  font-size: 13px;
}

/* ============================================================
   Export
   ============================================================ */
.form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.form-row label {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
}
#status-msg { margin-top: 1rem; font-size: 13px; }
