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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  min-height: 100vh;
}

.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 240px;
  background: #1e293b;
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-logo {
  padding: 24px 20px;
  font-size: 15px;
  font-weight: 700;
  color: #f8fafc;
  border-bottom: 1px solid #334155;
}
.sidebar-logo span { color: #6366f1; }
.sidebar-nav { padding: 12px 0; flex: 1; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: #94a3b8;
  text-decoration: none; font-size: 14px;
  transition: background .15s, color .15s;
  border-radius: 0;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
  background: #334155; color: #f8fafc;
}
.sidebar-nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-status {
  padding: 16px 20px;
  border-top: 1px solid #334155;
  font-size: 12px;
}
.sidebar-status .dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; background: #ef4444; margin-right: 6px;
}
.sidebar-status .dot.connected { background: #22c55e; }

/* Main */
.main { flex: 1; overflow-y: auto; }
.main-header {
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  padding: 20px 32px;
  display: flex; align-items: center; justify-content: space-between;
}
.main-header h1 { font-size: 20px; font-weight: 700; }
.main-content { padding: 32px; }

/* Cards */
.card {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  overflow: hidden;
}
.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid #e2e8f0;
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h2 { font-size: 15px; font-weight: 600; }
.card-body { padding: 0; }

/* Table */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; padding: 12px 20px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: #64748b;
  background: #f8fafc; border-bottom: 1px solid #e2e8f0;
}
td { padding: 14px 20px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.badge-draft     { background: #f1f5f9; color: #64748b; }
.badge-active    { background: #dcfce7; color: #15803d; }
.badge-paused    { background: #fef3c7; color: #92400e; }
.badge-expired   { background: #fee2e2; color: #991b1b; }
.badge-code      { background: #ede9fe; color: #6d28d9; }
.badge-automatic { background: #dbeafe; color: #1d4ed8; }
.badge-link      { background: #fce7f3; color: #be185d; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; font-size: 14px;
  font-weight: 500; cursor: pointer; border: none;
  transition: opacity .15s, background .15s;
  text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: #6366f1; color: #fff; }
.btn-primary:hover { background: #4f46e5; }
.btn-success { background: #22c55e; color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-danger  { background: #ef4444; color: #fff; }
.btn-danger:hover  { background: #dc2626; }
.btn-ghost   { background: transparent; color: #475569; border: 1px solid #e2e8f0; }
.btn-ghost:hover { background: #f8fafc; }
.btn-sm { padding: 5px 12px; font-size: 13px; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.form-grid.full { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.span2 { grid-column: span 2; }
label { font-size: 13px; font-weight: 500; color: #374151; }
input[type=text], input[type=date], input[type=datetime-local],
input[type=number], select, textarea {
  padding: 9px 12px; border: 1px solid #d1d5db; border-radius: 8px;
  font-size: 14px; color: #111827; background: #fff;
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}
.toggle-group {
  display: flex; border: 1px solid #d1d5db; border-radius: 8px;
  overflow: hidden;
}
.toggle-group input { display: none; }
.toggle-group label {
  flex: 1; padding: 8px; text-align: center; cursor: pointer;
  font-size: 13px; background: #fff; color: #64748b;
  transition: background .15s, color .15s;
  border-right: 1px solid #d1d5db;
}
.toggle-group label:last-child { border-right: none; }
.toggle-group input:checked + label { background: #6366f1; color: #fff; }

/* Multi-select tags */
.tag-select {
  border: 1px solid #d1d5db; border-radius: 8px;
  min-height: 80px; padding: 8px; display: flex;
  flex-wrap: wrap; gap: 6px; align-content: flex-start;
  background: #fff; cursor: text;
  transition: border-color .15s;
}
.tag-select:focus-within { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  background: #ede9fe; color: #6d28d9;
  padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 500;
}
.tag button {
  background: none; border: none; cursor: pointer;
  color: #6d28d9; padding: 0; line-height: 1; font-size: 14px;
}
.search-dropdown {
  position: relative;
}
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 100;
  max-height: 200px; overflow-y: auto;
}
.search-results .result-item {
  padding: 10px 14px; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.search-results .result-item:hover { background: #f8fafc; }
.search-results .result-item img { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; }

/* Checkbox */
.checkbox-row {
  display: flex; align-items: flex-start; gap: 10px; padding: 14px;
  border: 1px solid #e2e8f0; border-radius: 8px;
}
.checkbox-row input[type=checkbox] { width: 16px; height: 16px; margin-top: 2px; accent-color: #6366f1; flex-shrink: 0; }
.checkbox-row .checkbox-text label { font-size: 14px; font-weight: 500; }
.checkbox-row .checkbox-text p { font-size: 12px; color: #64748b; margin-top: 2px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 760px;
  max-height: 90vh; overflow-y: auto;
  transform: translateY(16px); transition: transform .2s;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  padding: 24px 28px 0;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: #fff;
  border-bottom: 1px solid #e2e8f0; padding-bottom: 16px;
}
.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-header button {
  background: none; border: none; cursor: pointer;
  color: #64748b; padding: 4px; font-size: 20px; line-height: 1;
}
.modal-body { padding: 28px; display: flex; flex-direction: column; gap: 24px; }
.modal-footer {
  padding: 20px 28px; border-top: 1px solid #e2e8f0;
  display: flex; justify-content: flex-end; gap: 10px;
  position: sticky; bottom: 0; background: #fff;
}

/* Section divider */
.section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: #94a3b8; padding-bottom: 8px;
  border-bottom: 1px solid #f1f5f9; margin-bottom: 16px;
}

/* Link copy */
.link-copy {
  display: flex; gap: 8px; align-items: center;
  background: #f8fafc; border: 1px solid #e2e8f0;
  border-radius: 8px; padding: 8px 12px;
  font-size: 13px; color: #475569; word-break: break-all;
}
.link-copy button {
  background: none; border: none; cursor: pointer;
  color: #6366f1; font-size: 12px; font-weight: 600;
  white-space: nowrap;
}

/* Empty state */
.empty-state {
  text-align: center; padding: 60px 24px; color: #94a3b8;
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 16px; }
.empty-state p { font-size: 14px; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-info    { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* Toast */
.toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: #1e293b; color: #f8fafc;
  padding: 12px 18px; border-radius: 10px;
  font-size: 14px; min-width: 240px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  transform: translateX(100%); opacity: 0;
  transition: transform .25s, opacity .25s;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast.error { background: #ef4444; }
.toast.success { background: #22c55e; }

/* Responsive */
@media (max-width: 768px) {
  .form-grid { grid-template-columns: 1fr; }
  .field.span2 { grid-column: span 1; }
  .sidebar { display: none; }
}
