@import url("tokens.css");

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

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

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-lg);
  z-index: 100;
  gap: var(--space-md);
}

.app-logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.logo-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #12D2AC 0%, #307AF2 50%, #0057FE 100%);
  flex-shrink: 0;
}

.header-spacer { flex: 1; }

.header-user {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 14px;
  color: var(--muted);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--fill-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}

.app-body {
  display: flex;
  padding-top: var(--header-h);
  min-height: 100vh;
}

.app-sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--header-h));
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--space-md) 0;
  overflow-y: auto;
  z-index: 90;
}

.nav-group-label {
  padding: var(--space-sm) var(--space-md);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px var(--space-md);
  font-size: 14px;
  color: var(--fg);
  letter-spacing: 0.02em;
  transition: background 0.15s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.nav-item:hover { background: var(--fill-2); }

.nav-item.active {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent);
  font-weight: 600;
  border-right: 2px solid var(--accent);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active .nav-icon { opacity: 1; }

.app-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: var(--space-lg);
  min-width: 0;
}

/* Page header */
.page-header {
  margin-bottom: var(--space-lg);
}

.page-title {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-xs);
}

.page-desc {
  font-size: 14px;
  color: var(--muted);
  max-width: 65ch;
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.card-body { padding: var(--space-lg); }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.search-input {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: var(--fill-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 var(--space-md);
  height: 36px;
  min-width: 220px;
}

.search-input input {
  border: none;
  background: none;
  outline: none;
  font: inherit;
  font-size: 14px;
  width: 100%;
  color: var(--fg);
}

.search-input input::placeholder { color: var(--muted); }

.select {
  height: 36px;
  padding: 0 var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  cursor: pointer;
  outline: none;
}

.select:focus { border-color: var(--accent); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 var(--space-md);
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

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

.btn-primary:hover:not(:disabled) { opacity: 0.88; }

.btn-secondary {
  background: var(--fill-2);
  color: var(--fg);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) { background: var(--border); }

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

.btn-ghost:hover:not(:disabled) { background: var(--fill-2); }

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 13px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--fg);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  padding: 0;
}

.btn-link:hover { color: var(--accent); }

/* Table */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  text-align: left;
  padding: 12px var(--space-md);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--muted);
  background: var(--fill-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 14px var(--space-md);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover { background: color-mix(in srgb, var(--fill-2) 60%, transparent); }

tbody tr:last-child td { border-bottom: none; }

.cell-actions {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

/* Tags */
.tag {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  letter-spacing: 0.01em;
  background: var(--fill-2);
  color: var(--fg);
  border: 1px solid var(--border);
}

.tag-accent {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 20%, transparent);
}

/* Switch */
.switch {
  position: relative;
  width: 40px;
  height: 22px;
  cursor: pointer;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 11px;
  transition: background 0.2s;
}

.switch-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 2px;
  background: var(--surface);
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px color-mix(in srgb, #1d2129 12%, transparent);
}

.switch input:checked + .switch-slider { background: var(--fg); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--muted);
}

.pagination-btns {
  display: flex;
  gap: var(--space-xs);
}

.page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  color: var(--fg);
}

.page-btn:hover:not(:disabled) { background: var(--fill-2); }
.page-btn.active {
  background: var(--accent);
  color: var(--surface);
  border-color: var(--accent);
}
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Drawer */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, #1d2129 40%, transparent);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(480px, 100vw);
  height: 100vh;
  background: var(--surface);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-float);
}

.drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border);
}

.drawer-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
}

.drawer-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
}

/* Form */
.form-group {
  margin-bottom: var(--space-md);
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.02em;
  margin-bottom: 6px;
}

.form-label .required { color: var(--muted); margin-left: 2px; }

.form-input,
.form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus,
.form-textarea:focus { border-color: var(--accent); }

.form-input.error,
.form-textarea.error { border-color: var(--fg); }

.form-error {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.form-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  letter-spacing: 0.01em;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

/* Toast */
.toast {
  position: fixed;
  top: calc(var(--header-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--fg);
  color: var(--surface);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Flag placeholder */
.flag-ph {
  width: 32px;
  height: 22px;
  border-radius: var(--radius-sm);
  background: var(--fill-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.country-cell {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-lg);
}

.tab {
  padding: 10px var(--space-md);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  font-family: inherit;
}

.tab:hover { color: var(--fg); }

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Stats row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.01em;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

/* Launcher cards */
.launcher-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
}

.launcher-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  transition: border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.launcher-card:hover {
  border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
  box-shadow: var(--shadow-float);
}

.launcher-card h3 {
  font-size: 16px;
  font-weight: 600;
}

.launcher-card p {
  font-size: 14px;
  color: var(--muted);
  flex: 1;
}

.launcher-card .btn { align-self: flex-start; margin-top: var(--space-sm); }

/* Responsive */
@media (max-width: 768px) {
  .app-sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s;
  }

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

  .app-main { margin-left: 0; padding: var(--space-md); }

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

  .toolbar { flex-direction: column; align-items: stretch; }

  .search-input { min-width: 0; width: 100%; }

  .card-header { flex-direction: column; align-items: stretch; }

  .pagination { flex-direction: column; gap: var(--space-sm); }
}

@media (max-width: 430px) {
  .page-title { font-size: 20px; }

  .drawer { width: 100vw; }

  table { font-size: 13px; }

  thead th, tbody td { padding: 10px 8px; }
}
