:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0ea5e9;
  --primary-700: #0369a1;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --error-bg: #fee2e2;
  --error-text: #991b1b;
  --border: #dbe3ee;
  --shadow: 0 16px 38px rgba(2, 132, 199, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  color: var(--text);
  background:
    radial-gradient(1200px 350px at 10% -5%, #d8effd 0%, transparent 60%),
    radial-gradient(900px 260px at 95% 0%, #e2f7f5 0%, transparent 55%),
    var(--bg);
  font-family: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow-x: hidden;
}

a { color: var(--primary-700); }

.skip-link {
  position: absolute;
  left: 8px;
  top: -9999px;
  background: #fff;
  border: 2px solid var(--primary);
  border-radius: 8px;
  padding: 8px 10px;
  z-index: 999;
}

.skip-link:focus {
  top: 8px;
}

.app-wrap {
  width: 100%;
  min-height: 100dvh;
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px;
  overflow-x: hidden;
}

.app-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px;
  min-height: calc(100dvh - 36px);
  overflow-x: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 38px;
  height: 38px;
}

.brand-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 1px;
}

.nav-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-tab {
  text-decoration: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
}

.nav-tab.active {
  border-color: var(--primary);
  color: var(--primary-700);
  box-shadow: inset 0 0 0 1px rgba(14, 165, 233, 0.2);
}

.page-title {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.03em;
}

.page-desc {
  color: var(--muted);
  margin: 8px 0 16px;
  font-size: 14px;
}

.flash {
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 14px;
  border: 1px solid transparent;
}

.flash.success {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: #86efac;
}

.flash.error {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: #fca5a5;
}

.card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  padding: 14px;
}

input, select, textarea, button {
  font: inherit;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="file"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13px;
  background: #fff;
}

textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.45;
}

button,
.btn {
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-700));
  color: white;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn.secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}

button:focus-visible,
.btn:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(14, 165, 233, 0.28);
  outline-offset: 2px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.expandable-table {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.table-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
}

.table-tools h3 {
  margin: 0;
}

.table-content {
  padding: 0 10px 10px;
}

body.fullscreen-table-open {
  overflow: hidden;
}

.expandable-table.is-fullscreen {
  position: fixed;
  inset: 14px;
  z-index: 1300;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
  display: flex;
  flex-direction: column;
}

.expandable-table.is-fullscreen .table-content {
  flex: 1;
  min-height: 0;
}

.expandable-table.is-fullscreen .table-wrap {
  height: 100%;
  max-height: calc(100vh - 120px);
}

table {
  width: 100%;
  min-width: 1020px;
  border-collapse: collapse;
}

th, td {
  border-bottom: 1px solid var(--border);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #334155;
  background: var(--surface-2);
}

caption {
  caption-side: top;
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  padding: 8px 0;
}

.num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
}

.badge.ok {
  background: #dcfce7;
  color: #166534;
}

.badge.off {
  background: #fee2e2;
  color: #991b1b;
}

.badge.media {
  background: #e0f2fe;
  color: #0369a1;
}

.badge.paidmedia {
  background: #fef3c7;
  color: #92400e;
}

.global-loading {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.28);
  z-index: 3000;
  backdrop-filter: blur(2px);
}

.global-loading.visible {
  display: flex;
}

.global-loading-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 16px 30px rgba(15, 23, 42, 0.16);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 700;
  color: #0f172a;
}

.global-loading-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #bae6fd;
  border-top-color: var(--primary);
  animation: loading-spin 0.8s linear infinite;
}

@keyframes loading-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 900px) {
  .app-wrap { padding: 10px; }
  .app-shell { padding: 14px; min-height: calc(100dvh - 20px); }
  .page-title { font-size: 22px; }
}
