:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  padding-top: max(1.25rem, env(safe-area-inset-top));
}

.login-card {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.login-card h1 {
  margin: 0;
  font-size: 1.4rem;
}

.login-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.login-card input {
  width: 100%;
  min-height: 44px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
}

.login-error {
  margin: 0;
  color: #fecaca;
  background: rgba(127, 29, 29, 0.35);
  border: 1px solid #991b1b;
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  min-height: 36px;
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-2);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header h1 {
  margin: 0;
  font-size: clamp(1.1rem, 4vw, 1.35rem);
  line-height: 1.3;
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  word-break: break-all;
}

.status {
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status.ok { color: var(--success); border-color: #166534; }
.status.err { color: var(--danger); border-color: #991b1b; }

.content {
  padding: 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  max-width: 1400px;
  margin: 0 auto;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  cursor: pointer;
  white-space: nowrap;
  font-size: 0.9rem;
}

.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

.panel { display: none; }
.panel.active { display: block; }

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.filters input,
.filters select {
  width: 100%;
  min-height: 44px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  -webkit-appearance: none;
  appearance: none;
}

.filters select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% + 2px),
    calc(100% - 12px) calc(50% + 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

.btn {
  border: none;
  border-radius: 8px;
  min-height: 44px;
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
  width: 100%;
}

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

.btn.primary:hover { background: var(--primary-hover); }
.btn.primary:active { transform: scale(0.98); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: #2d3a50; }
.btn-secondary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  grid-column: 1 / -1;
}

.form-actions .btn {
  flex: 1 1 160px;
}

.meta {
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
  word-break: break-word;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.table-scroll-hint {
  display: none;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

@media (min-width: 600px) and (max-width: 899px) {
  .table-scroll-hint {
    display: block;
  }
}

table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}

td {
  word-break: break-word;
}

tr:hover td { background: rgba(59, 130, 246, 0.06); }

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: max(1rem, env(safe-area-inset-bottom));
  background: #7f1d1d;
  color: #fecaca;
  border: 1px solid #991b1b;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  z-index: 100;
}

code {
  background: var(--surface-2);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

/* Tablet */
@media (min-width: 600px) {
  .header {
    align-items: center;
    padding: 1.25rem 1.5rem;
  }

  .status {
    flex-shrink: 0;
    max-width: none;
  }

  .content {
    padding: 1.25rem 1.5rem 2rem;
  }

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

  .btn {
    width: auto;
    justify-self: start;
  }

  .toast {
    left: auto;
    right: 1rem;
    max-width: 420px;
  }
}

/* Desktop */
@media (min-width: 900px) {
  .filters {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}

/* Mobile card layout for table */
@media (max-width: 599px) {
  .table-wrap--cards table {
    min-width: 0;
  }

  .table-wrap--cards thead {
    display: none;
  }

  .table-wrap--cards tbody,
  .table-wrap--cards tr,
  .table-wrap--cards td {
    display: block;
    width: 100%;
  }

  .table-wrap--cards tr {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
  }

  .table-wrap--cards tr:last-child {
    border-bottom: none;
  }

  .table-wrap--cards td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.4rem 0;
    border: none;
    text-align: right;
  }

  .table-wrap--cards td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    text-align: left;
    flex: 0 0 40%;
    font-size: 0.8rem;
  }

  .table-wrap--cards tr:hover td {
    background: transparent;
  }
}
