:root {
  --bg: #f8f9fb;
  --card: #fff;
  --primary: #3182f6;
  --primary-light: #eaf2fe;
  --primary-hover: #1b6ef0;
  --green: #16b979;
  --green-light: #e6faf0;
  --red: #f04452;
  --red-light: #fde8ea;
  --orange: #ff9f43;
  --orange-light: #fff4e6;
  --purple: #6c5ce7;
  --purple-light: #eeecfb;
  --txt: #1b1d1f;
  --txt2: #6b7684;
  --txt3: #adb5bd;
  --line: #f1f3f5;
  --sidebar-bg: #111827;
  --sidebar-hover: #1f2937;
  --sidebar-active: #252d3a;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-hover: 0 6px 16px rgba(0,0,0,.1), 0 2px 4px rgba(0,0,0,.05);
  --shadow-dropdown: 0 8px 24px rgba(0,0,0,.12);
  --transition-fast: 150ms cubic-bezier(.4,0,.2,1);
  --transition-base: 200ms cubic-bezier(.4,0,.2,1);
  --transition-slow: 300ms cubic-bezier(.4,0,.2,1);
}

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

body {
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: var(--bg);
  color: var(--txt);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Loading Screen ── */
.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: var(--sidebar-bg);
}
.loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid #333;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login ── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: var(--sidebar-bg);
}
.login-box {
  width: 360px;
  padding: 0 20px;
  text-align: center;
}
.login-title {
  font-size: 28px;
  font-weight: 900;
  color: #fff;
  letter-spacing: -1px;
}
.login-sub {
  font-size: 13px;
  color: #666;
  margin: 6px 0 36px;
}
.login-input {
  display: block;
  width: 100%;
  padding: 14px 16px;
  margin-bottom: 10px;
  border: 1.5px solid #333;
  border-radius: 10px;
  background: #1f2937;
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition-fast);
}
.login-input::placeholder { color: #555; }
.login-input:focus { border-color: var(--primary); }
.login-btn {
  display: block;
  width: 100%;
  padding: 15px;
  margin-top: 8px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.login-btn:hover { background: var(--primary-hover); }
.login-btn:active { transform: scale(.98); }
.login-btn:disabled { opacity: .6; cursor: not-allowed; }
.login-error {
  margin-top: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--red);
  min-height: 18px;
}

/* ── Layout ── */
.app {
  display: flex;
  min-height: 100dvh;
}

/* ── Sidebar ── */
.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition-slow);
  border-right: 1px solid #1f2937;
}
.sidebar-brand {
  padding: 24px 20px 8px;
  font-size: 18px;
  font-weight: 900;
  color: #fff;
  letter-spacing: -.5px;
}
.sidebar-section {
  padding: 16px 12px 4px 20px;
  font-size: 11px;
  font-weight: 700;
  color: #4b5563;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 8px 8px;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: #9ca3af;
  text-decoration: none;
  transition: all var(--transition-fast);
  position: relative;
}
.nav-item:hover { background: var(--sidebar-hover); color: #d1d5db; }
.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px;
  background: var(--primary);
  border-radius: 2px;
}
.nav-icon { font-size: 16px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-icon-img { width: 22px; height: 22px; border-radius: 6px; object-fit: contain; flex-shrink: 0; }
.sidebar-footer {
  padding: 12px 20px 16px;
  border-top: 1px solid #1f2937;
}
.sidebar-user {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logout-btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #4b5563;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: color var(--transition-fast);
}
.logout-btn:hover { color: #9ca3af; }

/* ── Main ── */
.main {
  flex: 1;
  margin-left: 240px;
  min-height: 100dvh;
}
.header {
  position: sticky;
  top: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  padding: 16px 32px;
  gap: 12px;
  background: rgba(248,249,251,.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.header-title {
  font-size: 18px;
  font-weight: 800;
  flex: 1;
  letter-spacing: -.3px;
}
.header-user {
  font-size: 12px;
  color: var(--txt3);
  font-weight: 500;
}
.header-refresh {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.header-refresh:hover { background: #d4e4fd; }
.header-refresh:active { transform: scale(.96); }
.menu-toggle {
  display: none;
  font-size: 20px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--txt);
  padding: 4px;
}
.content {
  padding: 4px 32px 48px;
}

/* ── Page transition ── */
.page-enter {
  animation: pageIn var(--transition-slow) ease-out;
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── KPI Cards ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}
.kpi-card:hover { box-shadow: var(--shadow-hover); }
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 3px;
}
.kpi-card.accent-blue::before { background: var(--primary); }
.kpi-card.accent-purple::before { background: var(--purple); }
.kpi-card.accent-green::before { background: var(--green); }
.kpi-card.accent-orange::before { background: var(--orange); }
.kpi-card.accent-red::before { background: var(--red); }

.kpi-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--txt3);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.kpi-value {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
  color: var(--txt);
}
.kpi-sub {
  font-size: 12px;
  font-weight: 600;
  color: var(--txt3);
  margin-top: 6px;
}

/* ── Section ── */
.section-title {
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 12px;
  color: var(--txt);
  letter-spacing: -.2px;
}
.section-divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 8px 0 20px;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

/* ── Table ── */
.table-wrap {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  margin-bottom: 24px;
}
.table-empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--txt3);
}
.table-empty-icon { font-size: 32px; display: block; margin-bottom: 8px; }
.table-empty p { font-size: 14px; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  padding: 12px 16px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--txt3);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  background: #fafbfc;
}
tbody td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition-fast); }
tbody tr:nth-child(even) { background: #fafbfc; }
tbody tr:hover { background: var(--primary-light); }
td.num { text-align: right; font-weight: 600; }

/* ── Table cell styles ── */
.th-group-start,
.td-group-start {
  border-left: 2px solid var(--line) !important;
}
.td-pill {
  display: inline-block;
  padding: 4px 12px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07), 0 0.5px 1px rgba(0,0,0,.04);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--txt);
}
.td-pill-blue { color: var(--primary); }
.td-pill-green { color: var(--green); }
.td-pill-purple { color: var(--purple); }
.td-pill-orange { color: var(--orange); }
.td-date {
  font-weight: 600;
  color: var(--txt);
}
.td-date.td-today {
  color: var(--primary);
  font-weight: 800;
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 16px 0 24px;
}
.page-btn {
  min-width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--txt2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow);
}
.page-btn:hover { background: var(--primary-light); color: var(--primary); }
.page-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(49,130,246,.3);
}
.page-btn.disabled { opacity: .3; pointer-events: none; }
.page-dots {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: var(--txt3);
}

/* ── Date filter ── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-bar input[type="date"] {
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--txt);
  outline: none;
  background: var(--card);
  transition: border-color var(--transition-fast);
}
.filter-bar input[type="date"]:focus { border-color: var(--primary); }
.filter-sep { color: var(--txt3); font-size: 13px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--line); color: var(--txt2); }
.btn-secondary:hover { background: #e5e7eb; }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { height: 30px; padding: 0 12px; font-size: 12px; }

/* ── Date Presets ── */
.date-presets {
  display: flex;
  gap: 4px;
}
.date-preset {
  padding: 6px 12px;
  border: 1.5px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--txt2);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.date-preset:hover { border-color: var(--primary); color: var(--primary); }
.date-preset.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── Click breakdown ── */
.click-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}
.click-card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
  transition: all var(--transition-fast);
}
.click-card:hover { box-shadow: var(--shadow-hover); }
.click-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--txt3);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.click-count {
  font-size: 24px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.click-sub {
  font-size: 11px;
  font-weight: 600;
  color: var(--txt3);
  margin-top: 4px;
}

/* ── Color utilities ── */
.c-blue { color: var(--primary); }
.c-green { color: var(--green); }
.c-red { color: var(--red); }
.c-purple { color: var(--purple); }
.c-orange { color: var(--orange); }

/* ── Loading ── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px;
  gap: 12px;
  color: var(--txt3);
  font-size: 14px;
}
.loading::before {
  content: '';
  width: 28px; height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ── Project card (dashboard) ── */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}
.project-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all var(--transition-base);
  text-decoration: none;
  color: inherit;
  display: block;
  position: relative;
  overflow: hidden;
}
.project-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--purple));
}
.project-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}
.project-name {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 2px;
  letter-spacing: -.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.project-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: contain;
}
.project-url {
  font-size: 12px;
  color: var(--txt3);
  margin-bottom: 16px;
}
.project-stats {
  display: flex;
  gap: 24px;
}
.project-stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--txt3);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.project-stat-value {
  font-size: 22px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.5px;
}

/* ── Badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
}
.badge-blue { background: var(--primary-light); color: var(--primary); }
.badge-green { background: var(--green-light); color: var(--green); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-orange { background: var(--orange-light); color: var(--orange); }
.badge-purple { background: var(--purple-light); color: var(--purple); }

/* ── Two column layout ── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 24px;
}

/* ── Click section ── */
.click-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-bottom: 24px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.click-panel {
  padding: 20px;
}
.click-panel:first-child {
  border-right: 2px solid var(--line);
}
.click-panel-header {
  font-size: 14px;
  font-weight: 800;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.click-panel:first-child .click-panel-header {
  color: var(--primary);
}
.click-panel:last-child .click-panel-header {
  color: var(--txt2);
}
.click-panel .click-grid {
  margin-bottom: 0;
}
.click-panel .click-card {
  background: #fff;
  padding: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  border-radius: 12px;
}

/* ── CSV Export ── */
.export-btn {
  font-size: 12px;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
  }
  .sidebar.open ~ .sidebar-overlay { display: block; }
  .main { margin-left: 0; }
  .menu-toggle { display: block; }
  .content { padding: 4px 16px 40px; }
  .header { padding: 12px 16px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi-value { font-size: 22px; }
  .click-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 400px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .date-presets { flex-wrap: wrap; }
}
