:root {
  --bg: #111317;
  --card: #1a1e25;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #0f766e;
  --border: #2b3340;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle at 18% 20%, rgba(15, 118, 110, 0.22), transparent 35%),
    radial-gradient(circle at 82% 30%, rgba(15, 118, 110, 0.16), transparent 38%),
    linear-gradient(rgba(15, 118, 110, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 118, 110, 0.08) 1px, transparent 1px);
  background-size: auto, auto, 34px 34px, 34px 34px;
  mask-image: radial-gradient(circle at 50% 35%, black 30%, transparent 88%);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(circle at 50% 0%, rgba(15, 118, 110, 0.08), transparent 55%);
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

h1 span { color: var(--accent); }
h2 { margin-top: 0; }
h1 {
  margin: 0;
  line-height: 1.2;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.lang-switch {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.lang-btn {
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1;
}

.user-label {
  color: var(--muted);
  font-size: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.muted {
  color: var(--muted);
  margin-top: -4px;
}

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 16px;
}

.sidebar {
  height: fit-content;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

button, input, textarea {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f1319;
  color: var(--text);
  padding: 10px 12px;
  min-height: 44px;
  font: inherit;
}

button {
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button.active {
  background: var(--accent);
  border-color: var(--accent);
}

.ghost {
  background: transparent;
}

.inline {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.inline input {
  flex: 1;
  min-width: 0;
}

.login-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 10px;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 10px;
}

.auth-split > div {
  background: #141923;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.auth-panel {
  max-width: min(460px, 100%);
  margin: 0 auto;
  background: #141923;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 0 0 1px rgba(15, 118, 110, 0.15), 0 18px 50px rgba(0, 0, 0, 0.32);
}

.h3 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tiny { font-size: 12px; }

.signup button { width: 100%; }

.oauth {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.oauth-row {
  grid-template-columns: 1fr 1fr;
}

.oauth-btn {
  width: 100%;
  background: transparent;
}

.auth-secondary {
  width: 100%;
  margin-top: 6px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  overflow-y: auto;
}

.auth-modal-card {
  width: min(560px, 100%);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.auth-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

select {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f1319;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}

.role-btn {
  text-align: left;
  padding: 14px;
}

label {
  display: block;
  margin-bottom: 10px;
}

label input, label textarea {
  margin-top: 6px;
  width: 100%;
}

.result {
  min-height: 120px;
  background: #0f1319;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 10px;
  white-space: pre-wrap;
}

.chat-placeholder {
  background: #0f1319;
  border: 1px dashed var(--border);
  padding: 18px;
  border-radius: 10px;
  color: var(--muted);
}

.welcome-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.quick-card {
  text-align: left;
  padding: 14px;
  background: #0f1319;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.quick-card strong {
  display: block;
  margin-bottom: 6px;
}

.quick-card span {
  color: var(--muted);
  font-size: 13px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.kpi {
  background: #0f1319;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.kpi h3 {
  margin: 0;
  color: var(--accent);
  font-size: 28px;
}

.kpi p { margin: 4px 0 0; color: var(--muted); }

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th, td {
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 8px;
  font-size: 14px;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.hidden { display: none !important; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .login-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr; }
  .welcome-grid { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .oauth-row { grid-template-columns: 1fr; }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .sidebar .nav-btn {
    flex: 1 1 180px;
  }
}

@media (max-width: 640px) {
  .app {
    padding:
      max(12px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(14px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
  }

  .topbar-actions {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .lang-switch {
    justify-content: flex-start;
    gap: 8px;
  }

  .lang-btn {
    min-height: 40px;
    min-width: 40px;
    padding: 8px 10px;
  }

  .user-label {
    font-size: 13px;
    line-height: 1.4;
    word-break: break-word;
  }

  .card {
    padding: 14px;
  }

  .auth-panel {
    padding: 14px;
    border-radius: 10px;
  }

  .auth-modal-card {
    border-radius: 12px;
    padding: 14px;
    max-height: calc(100dvh - 20px);
  }

  .auth-modal-head h3 {
    font-size: 18px;
    line-height: 1.25;
  }

  .muted {
    color: #a9b7cc;
  }

  .tiny {
    font-size: 13px;
    line-height: 1.45;
  }

  .inline {
    flex-direction: column;
  }

  .inline button,
  .inline input {
    width: 100%;
  }

  .sidebar {
    gap: 6px;
  }

  .sidebar .nav-btn {
    flex: 1 1 calc(50% - 6px);
  }

  .quick-card span {
    font-size: 14px;
    line-height: 1.45;
    color: #b3c1d4;
  }

  th,
  td {
    font-size: 13px;
    padding: 10px 8px;
  }

  .table-wrap {
    margin-inline: -2px;
  }
}

@media (max-width: 430px) {
  h1 {
    font-size: clamp(1.3rem, 6vw, 1.6rem);
  }

  h2 {
    font-size: clamp(1.1rem, 4.8vw, 1.35rem);
    line-height: 1.3;
  }

  .card {
    padding: 12px;
    border-radius: 12px;
  }

  label {
    font-size: 14px;
    line-height: 1.35;
  }

  input,
  textarea,
  button,
  select {
    font-size: 16px;
    line-height: 1.3;
  }

  .oauth {
    margin-top: 12px;
  }

  .oauth-row {
    grid-template-columns: 1fr;
  }

  .auth-modal {
    align-items: flex-start;
  }

  .auth-modal-card {
    width: 100%;
    margin-top: 4px;
    max-height: calc(100dvh - 8px);
  }

  .sidebar .nav-btn {
    flex: 1 1 100%;
  }

  .result {
    font-size: 14px;
    line-height: 1.45;
  }

  .chat-placeholder {
    font-size: 14px;
    line-height: 1.5;
  }
}
