:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-border-hover: #cbd5e1;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-text-subtle: #94a3b8;
  
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #eff6ff;
  --color-primary-text: #1e40af;

  --color-success: #059669;
  --color-success-light: #ecfdf5;
  --color-success-text: #065f46;

  --color-warning: #d97706;
  --color-warning-light: #fffbeb;
  --color-warning-text: #92400e;

  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-danger-light: #fef2f2;
  --color-danger-text: #991b1b;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --shadow-modal: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header & Nav */
.app-header {
  background-color: #0f172a;
  color: #ffffff;
  border-bottom: 1px solid #1e293b;
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: #ffffff;
}

.brand-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  border-radius: var(--radius-md);
  font-weight: 800;
  font-size: 18px;
  color: #ffffff;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.brand-domain {
  font-size: 12px;
  color: #94a3b8;
  margin-left: 4px;
  font-weight: 400;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-badge {
  font-size: 13px;
  color: #cbd5e1;
  background-color: #1e293b;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  border: 1px solid #334155;
  display: flex;
  align-items: center;
  gap: 6px;
}

.logout-link {
  color: #94a3b8;
  font-size: 13px;
  text-decoration: none;
  transition: color 0.15s ease;
}

.logout-link:hover {
  color: #f87171;
}

/* Main Container */
.main-wrapper {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 60px;
}

/* Alerts / Flash messages */
.alert-box {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-success {
  background-color: var(--color-success-light);
  color: var(--color-success-text);
  border: 1px solid #a7f3d0;
}

.alert-error {
  background-color: var(--color-danger-light);
  color: var(--color-danger-text);
  border: 1px solid #fecaca;
}

.alert-info {
  background-color: var(--color-primary-light);
  color: var(--color-primary-text);
  border: 1px solid #bfdbfe;
}

/* Stat Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 30px;
  font-weight: 700;
  color: var(--color-text);
  margin-top: 6px;
  line-height: 1.1;
}

/* Toolbar & Filter Bar */
.toolbar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
}

.toolbar-title-group h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
}

.toolbar-title-group p {
  font-size: 14px;
  color: var(--color-text-muted);
}

.search-input-group {
  position: relative;
  min-width: 260px;
}

.search-input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  font-size: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-subtle);
  pointer-events: none;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

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

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

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

.btn-secondary:hover {
  background-color: #f1f5f9;
  border-color: var(--color-border-hover);
}

.btn-danger {
  background-color: var(--color-danger-light);
  color: var(--color-danger-text);
  border-color: #fecaca;
}

.btn-danger:hover {
  background-color: #fee2e2;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.btn-icon {
  padding: 6px;
  line-height: 1;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background-color: #f1f5f9;
  color: var(--color-text);
}

/* Data Table */
.table-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.data-table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 14px;
}

.data-table th {
  background-color: #f8fafc;
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background-color: #fbfcfe;
}

/* Link Row Elements */
.slug-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 600;
  color: var(--color-primary);
  background-color: var(--color-primary-light);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: 13px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slug-pill:hover {
  background-color: #dbeafe;
}

.dest-url {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text-muted);
  font-size: 13px;
  display: block;
}

.dest-url a {
  color: inherit;
  text-decoration: none;
}

.dest-url a:hover {
  color: var(--color-text);
  text-decoration: underline;
}

.link-title {
  font-weight: 600;
  color: var(--color-text);
  font-size: 14px;
  margin-bottom: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius-full);
}

.badge-active {
  background-color: var(--color-success-light);
  color: var(--color-success-text);
}

.badge-inactive {
  background-color: #f1f5f9;
  color: #64748b;
}

.clicks-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: 13px;
  color: var(--color-text);
}

.actions-group {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 16px;
}

.modal-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-width: 520px;
  overflow: hidden;
  transform: scale(0.96);
  transition: transform 0.2s ease;
}

.modal-backdrop.is-open .modal-card {
  transform: scale(1);
}

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

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--color-border);
  background-color: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* Form inputs */
.form-group {
  margin-bottom: 18px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 6px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-hint {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 5px;
}

.input-prefix-group {
  display: flex;
  align-items: stretch;
}

.input-prefix {
  background-color: #f1f5f9;
  border: 1px solid var(--color-border);
  border-right: none;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  padding: 0 12px;
  font-size: 13px;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  font-family: monospace;
}

.input-prefix-group .form-input {
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

/* QR Code Display */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.qr-box {
  padding: 16px;
  background-color: #ffffff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  display: inline-block;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.qr-box canvas, .qr-box img {
  display: block;
}

.qr-url-text {
  font-family: monospace;
  font-size: 13px;
  color: var(--color-text-muted);
  word-break: break-all;
  text-align: center;
  margin-bottom: 16px;
  max-width: 400px;
}

.qr-actions {
  display: flex;
  gap: 12px;
}

/* Analytics & Stats Details */
.analytics-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-top: 24px;
}

@media (max-width: 860px) {
  .analytics-grid {
    grid-template-columns: 1fr;
  }
}

.panel-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  margin-bottom: 18px;
}

.panel-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.timeline-bar-container {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 160px;
  padding-top: 20px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 12px;
}

.timeline-bar-wrapper {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  position: relative;
}

.timeline-bar {
  width: 100%;
  background: var(--color-primary);
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  transition: background-color 0.15s ease;
}

.timeline-bar:hover {
  background: var(--color-primary-hover);
}

.timeline-bar-wrapper:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 4px);
  background: #0f172a;
  color: #fff;
  font-size: 11px;
  padding: 3px 6px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}

.breakdown-list {
  list-style: none;
}

.breakdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13px;
}

.breakdown-item:last-child {
  border-bottom: none;
}

.breakdown-label {
  font-weight: 500;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.breakdown-count {
  font-weight: 700;
  color: var(--color-text-muted);
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #ffffff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}
