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

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  transition: all 0.15s;
}
.btn:hover { background: #f1f5f9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-block { width: 100%; justify-content: center; }
.btn-small { padding: 4px 10px; font-size: 12px; }

/* --- Screens --- */
.screen { min-height: 100vh; }

/* --- Profiles Screen --- */
#profiles-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  padding: 40px 20px;
}
.profiles-card {
  background: var(--surface);
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 560px;
}
.profiles-card h1 { font-size: 22px; margin-bottom: 4px; }
.profiles-card .subtitle { color: var(--text-muted); margin-bottom: 24px; font-size: 14px; }

.profiles-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.profile-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
  gap: 12px;
}
.profile-info { flex: 1; min-width: 0; }
.profile-name { font-weight: 600; font-size: 15px; }
.profile-meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.profile-actions { display: flex; gap: 6px; flex-shrink: 0; }

.profiles-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 24px 0;
  margin-bottom: 16px;
}
.profiles-footer { margin-top: 8px; }
.profiles-shared-divider {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  padding: 8px 0 4px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.profile-card-shared { background: #f0f9ff; border-color: #bae6fd; }
.badge-shared {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  background: #dbeafe;
  color: var(--primary);
  vertical-align: middle;
}

/* --- Shared form styles (used in modals) --- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.form-group input, .form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: border 0.15s;
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); }
.optional { color: var(--text-muted); font-weight: 400; }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 12px; }

/* --- Header --- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.header-left { display: flex; align-items: center; gap: 16px; }
header h1 { font-size: 18px; }
.user-badge {
  background: #dbeafe;
  color: var(--primary);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 0;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: 12px 24px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; padding: 24px; }
.tab-content.active { display: block; }

/* --- Toolbar --- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 16px;
  flex-wrap: wrap;
}
.toolbar-left { display: flex; gap: 8px; flex: 1; }
.toolbar-right { display: flex; gap: 8px; }
.search-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  width: 100%;
  max-width: 360px;
  outline: none;
}
.search-input:focus { border-color: var(--primary); }

/* --- Table --- */
.table-container {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 10px 14px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
tr:hover td { background: #f8fafc; }
tr:last-child td { border-bottom: none; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.badge-yes { background: #dcfce7; color: #16a34a; }
.badge-no { background: #fee2e2; color: #dc2626; }
.action-btns { display: flex; gap: 4px; }

/* --- Loading / Empty --- */
.loading, .empty-state {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-small { max-width: 440px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 18px; }
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}
.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}
.editor-toolbar { margin-bottom: 8px; }
.file-upload-label { cursor: pointer; }

/* --- Script editor textarea --- */
#code-editor {
  width: 100%;
  min-height: 260px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  background: #f8fafc;
  color: var(--text);
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  transition: border 0.15s;
}
#code-editor:focus {
  border-color: var(--primary);
  background: #fff;
}

/* --- Filter row --- */
.filter-row th {
  padding: 4px 6px;
  background: #f1f5f9;
}
.filter-row select {
  width: 100%;
  padding: 3px 6px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}
.filter-row select:focus { outline: none; border-color: var(--primary); }
.filter-input {
  width: 100%;
  padding: 3px 6px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.filter-input:focus { border-color: var(--primary); }

/* --- Responsive --- */
@media (max-width: 768px) {
  .toolbar { flex-direction: column; }
  .toolbar-left, .toolbar-right { width: 100%; }
  .search-input { max-width: 100%; }
  td, th { padding: 8px 10px; font-size: 13px; }
}
