/* ============================================
   LegalStack - Complete Stylesheet
   ============================================ */

/* ----- CSS Custom Properties ----- */
:root {
  --primary: #F24E1E;
  --primary-hover: #d9441a;
  --primary-light: rgba(242, 78, 30, 0.12);
  --primary-glow: rgba(242, 78, 30, 0.25);
  --secondary: #34d399;
  --secondary-hover: #2bc48a;
  --secondary-light: rgba(52, 211, 153, 0.12);

  --bg: #f8f9fc;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-header: rgba(255, 255, 255, 0.85);
  --bg-hover: #f0f2f5;
  --bg-input: #f0f2f5;
  --bg-modal-overlay: rgba(0, 0, 0, 0.5);

  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --text-inverse: #ffffff;

  --border: #e5e7eb;
  --border-light: #f0f2f5;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.12);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --sidebar-width: 260px;
  --sidebar-collapsed: 72px;
  --header-height: 68px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  --bounce: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ----- Dark Mode ----- */
[data-theme="dark"] {
  --bg: #0f0f13;
  --bg-card: #1a1a24;
  --bg-sidebar: #14141e;
  --bg-header: rgba(15, 15, 19, 0.88);
  --bg-hover: #252535;
  --bg-input: #252535;
  --bg-modal-overlay: rgba(0, 0, 0, 0.7);

  --text: #e8e8ed;
  --text-secondary: #9ca3af;
  --text-tertiary: #6b7280;

  --border: #2a2a3a;
  --border-light: #1f1f2d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* ----- Reset & Base ----- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background var(--transition-slow), color var(--transition-slow);
  overflow-x: hidden;
  min-height: 100vh;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--primary-hover);
}

img {
  max-width: 100%;
  display: block;
}

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  transition: all var(--transition);
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ----- Scrollbar ----- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ----- Container ----- */
.app-container {
  width: 92%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ----- Layout ----- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ----- Sidebar ----- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: width var(--transition), transform var(--transition), background var(--transition-slow), border-color var(--transition-slow);
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  flex-shrink: 0;
}

.sidebar-logo {
  width: 180px;
  flex-shrink: 0;
}

.sidebar-brand {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.sidebar-toggle {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  margin-left: auto;
}

.sidebar-toggle:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.sidebar-nav {
  flex: 1;
  padding: 8px 12px;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section {
  margin-bottom: 24px;
}

.nav-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-tertiary);
  padding: 8px 12px 6px;
  font-weight: 600;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
}

.nav-item i {
  width: 20px;
  text-align: center;
  font-size: 16px;
  flex-shrink: 0;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-item .badge {
  margin-left: auto;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ----- Main Content ----- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  transition: margin-left var(--transition), background var(--transition-slow);
}

/* ----- Header ----- */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-header);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: background var(--transition-slow), border-color var(--transition-slow);
}

.header-greeting {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-tertiary);
}

.header-greeting span {
  color: var(--text-secondary);
}

.header-search {
  position: relative;
  flex: 1;
  max-width: 400px;
  margin: 0 16px;
}

.header-search i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-size: 14px;
}

.header-search input {
  width: 100%;
  padding: 9px 14px 9px 38px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-size: 14px;
  outline: none;
  transition: all var(--transition);
}

.header-search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.header-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 16px;
  position: relative;
}

.header-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.header-btn .tooltip {
  position: absolute;
  bottom: -32px;
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  background: var(--text);
  color: var(--text-inverse);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition);
}

.header-btn:hover .tooltip {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ----- Views ----- */
.view {
  display: none;
  padding: 24px;
  animation: fadeIn var(--transition-slow);
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ----- Bento Grid ----- */
.bento-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}

.bento-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}

.bento-card:hover {
  box-shadow: var(--shadow);
  border-color: transparent;
}

.bento-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.bento-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.bento-card-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 16px;
}

.bento-card-icon.primary { background: var(--primary-light); color: var(--primary); }
.bento-card-icon.secondary { background: var(--secondary-light); color: var(--secondary); }

/* ----- Dashboard Stats ----- */
.stat-card {
  text-align: center;
  padding: 24px 16px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  margin-top: 8px;
  padding: 2px 8px;
  border-radius: 20px;
}

.stat-trend.up { background: var(--secondary-light); color: var(--secondary); }
.stat-trend.down { background: var(--primary-light); color: var(--primary); }

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 16px;
}

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

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 16px var(--primary-glow);
  transform: translateY(-1px);
  color: white;
}

.btn-secondary {
  background: var(--secondary);
  color: #0f0f13;
}

.btn-secondary:hover {
  background: var(--secondary-hover);
  box-shadow: 0 4px 16px rgba(52, 211, 153, 0.3);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--text-tertiary);
}

.btn-danger {
  background: #ef4444;
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
  box-shadow: 0 4px 16px rgba(239, 68, 68, 0.3);
  transform: translateY(-1px);
  color: white;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
}

/* ----- Cards Grid ----- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.doc-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
  cursor: pointer;
  position: relative;
}

.doc-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  border-color: transparent;
}

.doc-card-type {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 12px;
}

.doc-card-type.proposal { background: #ede9fe; color: #8b5cf6; }
[data-theme="dark"] .doc-card-type.proposal { background: rgba(139,92,246,0.15); color: #a78bfa; }
.doc-card-type.contract { background: var(--primary-light); color: var(--primary); }
.doc-card-type.invoice { background: #fef3c7; color: #d97706; }
[data-theme="dark"] .doc-card-type.invoice { background: rgba(217,119,6,0.15); color: #fbbf24; }
.doc-card-type.terms { background: var(--secondary-light); color: var(--secondary); }
.doc-card-type.privacy { background: #e0e7ff; color: #4f46e5; }
[data-theme="dark"] .doc-card-type.privacy { background: rgba(79,70,229,0.15); color: #818cf8; }
.doc-card-type.cookies { background: #fce7f3; color: #db2777; }
[data-theme="dark"] .doc-card-type.cookies { background: rgba(219,39,119,0.15); color: #f472b6; }

.doc-card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  line-height: 1.3;
}

.doc-card-meta {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 12px;
}

.doc-card-actions {
  display: flex;
  gap: 4px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.doc-card-actions .btn {
  flex: 1;
}

/* ----- Document Editor ----- */
.doc-editor {
  max-width: 800px;
  margin: 0 auto;
}

/* ----- Multi-step Progress ----- */
.progress-container {
  margin-bottom: 32px;
}

.progress-steps {
  display: flex;
  justify-content: space-between;
  position: relative;
  margin-bottom: 8px;
}

.progress-steps::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--border);
  transform: translateY(-50%);
}

.progress-bar-fill {
  position: absolute;
  top: 50%;
  left: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary), var(--primary-hover));
  transform: translateY(-50%);
  transition: width var(--transition-slow);
}

.progress-step {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.progress-step-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  background: var(--bg-card);
  border: 2px solid var(--border);
  color: var(--text-tertiary);
  transition: all var(--transition);
}

.progress-step.active .progress-step-circle {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.progress-step.completed .progress-step-circle {
  border-color: var(--secondary);
  background: var(--secondary);
  color: #0f0f13;
}

.progress-step-label {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 500;
  text-align: center;
}

.progress-step.active .progress-step-label {
  color: var(--text);
  font-weight: 600;
}

/* ----- Form Styles ----- */
.form-group {
  margin-bottom: 20px;
}

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

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg-input);
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: all var(--transition);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-input.error,
.form-textarea.error {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

.form-error {
  font-size: 12px;
  color: #ef4444;
  margin-top: 4px;
  display: none;
}

.form-input.error + .form-error,
.form-textarea.error + .form-error {
  display: block;
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

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

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ----- Template Fields ----- */
.template-field {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  transition: all var(--transition);
}

.template-field:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.template-field .field-placeholder {
  color: var(--text-tertiary);
  font-style: italic;
  font-size: 12px;
}

/* ----- Table ----- */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border-light);
}

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

tr:hover td {
  background: var(--bg-hover);
}

.table-actions {
  display: flex;
  gap: 4px;
}

/* ----- Modal ----- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-modal-overlay);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn var(--transition);
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: modalIn var(--bounce);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.92) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

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

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-tertiary);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}

/* ----- Toast ----- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 500;
  animation: toastIn var(--bounce);
  max-width: 360px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(24px) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

.toast.removing {
  animation: toastOut 0.25s ease forwards;
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(24px) scale(0.95); }
}

.toast-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.toast.success .toast-icon { color: var(--secondary); }
.toast.error .toast-icon { color: #ef4444; }
.toast.info .toast-icon { color: var(--primary); }
.toast.warning .toast-icon { color: #f59e0b; }

/* ----- Empty State ----- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-state-icon {
  font-size: 48px;
  color: var(--text-tertiary);
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-state-text {
  color: var(--text-secondary);
  max-width: 400px;
  margin: 0 auto 20px;
}

/* ----- Settings ----- */
.settings-section {
  margin-bottom: 32px;
}

.settings-section-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.settings-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  margin-bottom: 12px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.settings-row:first-child {
  padding-top: 0;
}

.settings-label {
  font-size: 14px;
  font-weight: 500;
}

.settings-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ----- Toggle Switch ----- */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 12px;
  transition: all var(--transition);
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  transition: all var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle input:checked + .toggle-slider::after {
  transform: translateX(20px);
}

/* ----- Filter Bar ----- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.filter-bar .search-input {
  flex: 1;
  min-width: 200px;
}

.filter-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-hover);
  padding: 3px;
  border-radius: var(--radius-sm);
}

.filter-tab {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.filter-tab.active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.filter-tab:hover:not(.active) {
  color: var(--text);
}

/* ----- Page Header ----- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ----- Welcome Modal Specific ----- */
.welcome-steps {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 16px 0;
}

.welcome-step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.welcome-step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.welcome-step-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.welcome-step-text strong {
  color: var(--text);
}

/* ----- PDF Preview ----- */
.pdf-preview {
  background: white;
  color: #1a1a2e;
  padding: 40px;
  border-radius: var(--radius);
  font-size: 12px;
  line-height: 1.6;
}

.pdf-preview h1 { font-size: 22px; margin-bottom: 16px; }
.pdf-preview h2 { font-size: 16px; margin-bottom: 12px; border-bottom: 1px solid #ddd; padding-bottom: 6px; }
.pdf-preview p { margin-bottom: 8px; }
.pdf-preview table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.pdf-preview table th, .pdf-preview table td { border: 1px solid #ddd; padding: 6px 10px; text-align: left; font-size: 11px; }
.pdf-preview table th { background: #f5f5f5; font-weight: 600; }
.pdf-preview .header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; padding-bottom: 16px; border-bottom: 2px solid #F24E1E; }
.pdf-preview .footer { margin-top: 32px; padding-top: 12px; border-top: 1px solid #ddd; font-size: 10px; color: #666; text-align: center; }
.pdf-preview tr:hover td { background: transparent; }

/* ----- Footer ----- */
.app-footer {
  text-align: center;
  padding: 32px 24px 24px;
  font-size: 14px;
  color: var(--text-tertiary);
}

.app-footer a {
  font-weight: 600;
}

/* ----- Responsive ----- */
@media (max-width: 1024px) {
  .bento-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  .main-content {
    margin-left: 0;
  }

  .header {
    padding: 0 16px;
  }

  .header-greeting {
    font-size: 16px;
  }

  .header-search {
    max-width: 200px;
    margin: 0 8px;
  }

  .view {
    padding: 16px;
  }

  .bento-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .modal {
    max-width: 100%;
    margin: 8px;
    border-radius: var(--radius-lg);
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-tabs {
    overflow-x: auto;
  }

  .toast-container {
    left: 16px;
    right: 16px;
    bottom: 16px;
  }

  .toast {
    max-width: 100%;
  }

  .progress-step-label {
    display: none;
  }

  .progress-step-circle {
    width: 32px;
    height: 32px;
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .header-search {
    display: none;
  }

  .header-greeting {
    display: none;
  }

  .install-banner {
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
    bottom: 12px;
    left: 12px;
    right: 12px;
    transform: none;
  }

  .doc-card-actions {
    flex-direction: column;
  }

  .bento-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .bento-grid > .stat-card {
    grid-column: span 1 !important;
  }

  .bento-grid > .bento-card {
    grid-column: span 2 !important;
  }

  .progress-steps {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px 16px;
  }

  .progress-steps::before {
    display: none;
  }

  .progress-step {
    width: calc(50% - 8px);
    flex-direction: row;
    gap: 8px;
  }

  .filter-tabs {
    flex-wrap: wrap;
    gap: 4px;
    background: transparent;
    padding: 0;
  }

  .filter-tab {
    padding: 5px 10px;
    font-size: 12px;
    background: var(--bg-hover);
  }

  .draft-actions {
    flex-basis: 100%;
    justify-content: flex-end;
    gap: 6px;
  }

  .draft-actions .btn:first-child {
    flex: 4;
  }

  .draft-actions .btn:last-child {
    flex: 1;
  }

  #draftsContent .bento-card {
    flex-direction: column;
    align-items: stretch !important;
    gap: 6px !important;
    padding: 14px 16px;
  }

  #draftsContent .bento-card > div:first-child {
    align-self: flex-start;
  }

  #draftsContent .bento-card .doc-card-type {
    font-size: 11px;
    padding: 2px 8px;
  }

  #draftsContent .draft-checkbox {
    width: 20px !important;
    height: 20px !important;
  }

  .stat-value {
    font-size: 26px;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
  }
}

/* ----- Mobile sidebar overlay ----- */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  display: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.sidebar-overlay.open {
  display: block;
}

@media (min-width: 769px) {
  .sidebar-overlay {
    display: none !important;
  }
}

/* ----- Utilities ----- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-sm { font-size: 13px; }
.text-xs {   font-size: 12px;
}

/* ----- Notification Panel ----- */
.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  border: 2px solid var(--sidebar-bg);
}

.notif-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.notif-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.notif-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  max-width: 100vw;
  height: 100vh;
  background: var(--bg);
  border-left: 1px solid var(--border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-slow);
  box-shadow: -4px 0 24px rgba(0,0,0,0.12);
}

.notif-panel.open {
  transform: translateX(0);
}

.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.notif-panel-header h3 {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.notif-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.notif-panel-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.notif-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  color: var(--text-tertiary);
  gap: 12px;
}

.notif-empty i {
  font-size: 40px;
}

.notif-empty p {
  font-size: 14px;
}

.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.notif-item:hover {
  background: var(--bg-hover);
}

.notif-item-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  margin-top: 1px;
}

.notif-item-content {
  flex: 1;
  min-width: 0;
}

.notif-item-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
}

.notif-item-time {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 3px;
}

.notif-item-close {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-tertiary);
  font-size: 11px;
  opacity: 0;
  transition: all var(--transition);
  cursor: pointer;
}

.notif-item-close:hover {
  background: var(--bg-hover);
  color: #ef4444;
}

.notif-item:hover .notif-item-close {
  opacity: 1;
}
.text-secondary { color: var(--text-secondary); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- PWA Install Banner ----- */
.install-banner {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-xl);
  z-index: 150;
  display: none;
  align-items: center;
  gap: 16px;
  max-width: 400px;
  animation: toastIn var(--bounce);
}

.install-banner.show {
  display: flex;
}

.install-banner-info {
  flex: 1;
}

.install-banner-title {
  font-weight: 600;
  font-size: 14px;
}

.install-banner-text {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ----- Animations ----- */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.pulse { animation: pulse 2s ease-in-out infinite; }

/* ----- Loading Skeleton ----- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--border) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ----- Document type colors in select ----- */
.option-group-label {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
}
