/* ===========================
   Mested Forms — style.css
   Global Design Tokens & Base
   =========================== */

/* CSS Custom Properties */
:root {
  --accent: #4F46E5;
  --accent-hover: #4338CA;
  --accent-light: rgba(79, 70, 229, 0.1);
  --accent-rgb: 79, 70, 229;

  /* Neutrals */
  --gray-50:  #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;

  /* Semantic */
  --bg: #FFFFFF;
  --bg-secondary: var(--gray-50);
  --bg-tertiary: var(--gray-100);
  --border: var(--gray-200);
  --border-focus: var(--accent);
  --text: var(--gray-900);
  --text-secondary: var(--gray-500);
  --text-tertiary: var(--gray-400);

  /* Status */
  --green: #10B981;
  --green-light: #D1FAE5;
  --red: #EF4444;
  --red-light: #FEE2E2;
  --orange: #F59E0B;
  --orange-light: #FEF3C7;
  --blue: #3B82F6;
  --blue-light: #DBEAFE;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Radius */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
  --shadow-md: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.05);
  --shadow-lg: 0 20px 25px -5px rgba(0,0,0,.1), 0 8px 10px -6px rgba(0,0,0,.05);
  --shadow-xl: 0 25px 50px -12px rgba(0,0,0,.18);

  /* Typography */
  --font-sans: 'DM Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Sora', 'DM Sans', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Transitions */
  --transition: 150ms cubic-bezier(0.4,0,0.2,1);
  --transition-md: 250ms cubic-bezier(0.4,0,0.2,1);
  --transition-slow: 400ms cubic-bezier(0.4,0,0.2,1);

  /* Layout */
  --sidebar-width: 220px;
  --nav-height: 58px;
  --content-max: 1200px;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font-sans); color: var(--text); background: var(--bg); line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }
img, svg { display: block; max-width: 100%; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---- Buttons ---- */
.btn-primary {
  display: inline-flex; align-items: center; gap: var(--space-2);
  background: var(--accent); color: #fff; border-radius: var(--radius);
  padding: 9px 18px; font-size: 14px; font-weight: 600;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-hover); color: #fff; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: translateY(0); }
.btn-primary.btn-sm { padding: 6px 14px; font-size: 13px; }

.btn-ghost {
  display: inline-flex; align-items: center; gap: var(--space-2);
  background: transparent; color: var(--text); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 8px 18px; font-size: 14px; font-weight: 500;
  transition: all var(--transition);
}
.btn-ghost:hover { background: var(--bg-secondary); border-color: var(--gray-300); color: var(--text); }

.btn-danger {
  display: inline-flex; align-items: center; gap: var(--space-2);
  background: var(--red); color: #fff; border-radius: var(--radius);
  padding: 9px 18px; font-size: 14px; font-weight: 600;
  transition: all var(--transition);
}
.btn-danger:hover { background: #DC2626; color: #fff; }

.btn-mini {
  padding: 4px 10px; font-size: 12px; font-weight: 500;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); transition: all var(--transition);
}
.btn-mini:hover { background: var(--bg-secondary); }

/* ---- Alerts ---- */
.alert {
  padding: var(--space-3) var(--space-4); border-radius: var(--radius); font-size: 14px;
  margin-bottom: var(--space-4); border: 1px solid transparent;
}
.alert-success { background: var(--green-light); color: #065F46; border-color: #6EE7B7; }
.alert-error   { background: var(--red-light);   color: #991B1B; border-color: #FCA5A5; }
.alert-warning { background: var(--orange-light); color: #92400E; border-color: #FDE68A; }
.alert-info    { background: var(--blue-light);  color: #1E40AF; border-color: #93C5FD; }

/* ---- Status badges ---- */
.status-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: var(--radius-full);
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em;
}
.status-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.status-active { background: var(--green-light); color: #065F46; }
.status-active::before { background: var(--green); }
.status-draft  { background: var(--gray-100); color: var(--gray-600); }
.status-draft::before { background: var(--gray-400); }
.status-closed { background: var(--red-light); color: #991B1B; }
.status-closed::before { background: var(--red); }

/* ---- Form inputs ---- */
.form-group { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-5); }
.form-group label { font-size: 14px; font-weight: 600; color: var(--gray-700); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius); font-size: 15px; color: var(--text);
  background: var(--bg); transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light);
}
.form-group input::placeholder, .form-group textarea::placeholder { color: var(--text-tertiary); }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--gray-900); color: #fff; padding: 10px 20px;
  border-radius: var(--radius); font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: all 0.25s; z-index: 9999; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; backdrop-filter: blur(4px);
}
.modal {
  background: var(--bg); border-radius: var(--radius-lg); padding: var(--space-8);
  width: 90%; max-width: 440px; box-shadow: var(--shadow-xl);
  animation: modal-in 0.2s ease;
}
.modal-large { max-width: 720px; max-height: 80vh; overflow-y: auto; }
@keyframes modal-in { from { opacity:0; transform:scale(.95) translateY(8px); } to { opacity:1; transform:none; } }
.modal-icon { width: 48px; height: 48px; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; margin-bottom: var(--space-4); }
.danger-icon { background: var(--red-light); color: var(--red); }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: var(--space-2); }
.modal-body { color: var(--text-secondary); font-size: 14px; margin-bottom: var(--space-6); line-height: 1.6; }
.modal-actions { display: flex; gap: var(--space-3); justify-content: flex-end; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-6); }
.modal-close { width: 32px; height: 32px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; color: var(--text-secondary); transition: all var(--transition); }
.modal-close:hover { background: var(--gray-100); color: var(--text); }

/* ---- App layout ---- */
.app-page { background: var(--bg-secondary); min-height: 100vh; }

.app-nav {
  position: sticky; top: 0; z-index: 100; height: var(--nav-height);
  background: var(--bg); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-6);
}
.nav-logo { display: flex; align-items: center; gap: var(--space-3); color: var(--text); font-size: 16px; font-weight: 700; }
.nav-right { display: flex; align-items: center; gap: var(--space-3); }

.app-layout { display: flex; min-height: calc(100vh - var(--nav-height)); }

.app-sidebar {
  width: var(--sidebar-width); background: var(--bg); border-right: 1px solid var(--border);
  padding: var(--space-6) var(--space-4); flex-shrink: 0;
  position: sticky; top: var(--nav-height); height: calc(100vh - var(--nav-height)); overflow-y: auto;
}
.sidebar-nav { display: flex; flex-direction: column; gap: var(--space-1); }
.sidebar-link {
  display: flex; align-items: center; gap: var(--space-3); padding: 9px 12px;
  border-radius: var(--radius); color: var(--text-secondary); font-size: 14px; font-weight: 500;
  transition: all var(--transition);
}
.sidebar-link:hover { background: var(--bg-secondary); color: var(--text); }
.sidebar-link.active { background: var(--accent-light); color: var(--accent); }
.sidebar-link svg { flex-shrink: 0; }
.sidebar-divider { height: 1px; background: var(--border); margin: var(--space-4) 0; }
.sidebar-link-danger { color: var(--red); }
.sidebar-link-danger:hover { background: var(--red-light); color: var(--red); }

.app-main {
  flex: 1; padding: var(--space-8);
  max-width: calc(100% - var(--sidebar-width));
}

/* ---- Page header ---- */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: var(--space-8); gap: var(--space-4);
}
.page-title { font-size: 26px; font-weight: 800; font-family: var(--font-display); }
.page-sub { color: var(--text-secondary); font-size: 14px; margin-top: 2px; }
.breadcrumb { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 13px; margin-bottom: 4px; }

/* ---- Stats grid ---- */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); margin-bottom: var(--space-8); }
.stat-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-5); display: flex; align-items: center; gap: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.stat-icon { width: 44px; height: 44px; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.stat-icon-blue   { background: var(--blue-light); color: var(--blue); }
.stat-icon-green  { background: var(--green-light); color: var(--green); }
.stat-icon-purple { background: #EDE9FE; color: #7C3AED; }
.stat-icon-orange { background: var(--orange-light); color: var(--orange); }
.stat-value { font-size: 28px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 13px; color: var(--text-secondary); margin-top: 3px; }

/* ---- Forms grid ---- */
.forms-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--space-4); }
.form-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden; transition: all var(--transition-md); box-shadow: var(--shadow-sm);
}
.form-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.form-card-header { height: 6px; position: relative; }
.form-card-accent { height: 100%; }
.form-card-meta { position: absolute; top: 10px; right: 12px; display: flex; gap: 6px; }
.template-badge { display: inline-flex; padding: 2px 8px; border-radius: var(--radius-full); font-size: 11px; font-weight: 500; background: var(--gray-100); color: var(--gray-600); }
.form-card-body { padding: var(--space-5); }
.form-card-title { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.form-card-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: var(--space-4); }
.form-card-stats { display: flex; gap: var(--space-4); }
.fcs { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text-secondary); }
.form-card-actions {
  display: flex; align-items: center; gap: 2px;
  border-top: 1px solid var(--border); padding: var(--space-3) var(--space-4); background: var(--bg-secondary);
}
.card-action-btn {
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); color: var(--text-secondary);
  transition: all var(--transition);
}
.card-action-btn:hover { background: var(--bg-tertiary); color: var(--text); }
.card-action-btn.danger:hover { background: var(--red-light); color: var(--red); }

/* ---- Section header row ---- */
.section-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.section-title { font-size: 18px; font-weight: 700; }
.section-actions { display: flex; align-items: center; gap: var(--space-3); }

/* ---- Search & filter ---- */
.search-box { display: flex; align-items: center; gap: var(--space-2); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 7px 12px; background: var(--bg); }
.search-box svg { color: var(--text-tertiary); flex-shrink: 0; }
.search-box input { border: none; outline: none; background: transparent; font-size: 14px; width: 180px; }
.filter-select { border: 1.5px solid var(--border); border-radius: var(--radius); padding: 7px 12px; font-size: 14px; background: var(--bg); outline: none; }

/* ---- Empty state ---- */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--space-16); text-align: center; }
.empty-icon { font-size: 48px; margin-bottom: var(--space-4); }
.empty-state h3 { font-size: 20px; font-weight: 700; margin-bottom: var(--space-2); }
.empty-state p { color: var(--text-secondary); margin-bottom: var(--space-6); }

/* ---- User dropdown ---- */
.nav-user { display: flex; align-items: center; gap: var(--space-2); cursor: pointer; position: relative; padding: 6px 10px; border-radius: var(--radius); transition: background var(--transition); }
.nav-user:hover { background: var(--bg-secondary); }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.user-name { font-size: 14px; font-weight: 600; }
.user-dropdown { position: absolute; top: calc(100% + 8px); right: 0; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); min-width: 160px; padding: var(--space-2); display: none; z-index: 200; }
.user-dropdown.open { display: block; animation: modal-in 0.15s ease; }
.dropdown-item { display: block; padding: 8px 12px; font-size: 14px; color: var(--text); border-radius: var(--radius-sm); transition: background var(--transition); }
.dropdown-item:hover { background: var(--bg-secondary); color: var(--text); }
.dropdown-danger { color: var(--red); }
.dropdown-danger:hover { background: var(--red-light); }
.dropdown-divider { height: 1px; background: var(--border); margin: var(--space-2) 0; }

/* ---- Pagination ---- */
.pagination { display: flex; gap: var(--space-1); justify-content: center; margin-top: var(--space-6); }
.page-btn { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; color: var(--text); transition: all var(--transition); }
.page-btn:hover, .page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .app-sidebar { display: none; }
  .app-main { max-width: 100%; padding: var(--space-4); }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-header { flex-direction: column; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .forms-grid { grid-template-columns: 1fr; }
}
