/* ═══════════════════════════════════════════════════════
   AI Prompt Dashboard — Buffini & Company
   ═══════════════════════════════════════════════════════ */
:root {
  --primary: #145CC7;
  --primary-dark: #0f3460;
  --primary-light: #1a7ae2;
  --primary-ghost: rgba(20,92,199,0.08);
  --primary-subtle: rgba(20,92,199,0.04);
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-amber: #f59e0b;
  --accent-purple: #8b5cf6;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --shadow-sm: 0 1px 2px rgba(15,52,96,0.05);
  --shadow: 0 1px 3px rgba(15,52,96,0.08), 0 1px 2px rgba(15,52,96,0.04);
  --shadow-md: 0 4px 6px rgba(15,52,96,0.07), 0 2px 4px rgba(15,52,96,0.04);
  --shadow-lg: 0 10px 15px rgba(15,52,96,0.08), 0 4px 6px rgba(15,52,96,0.04);
  --shadow-xl: 0 20px 25px rgba(15,52,96,0.1), 0 8px 10px rgba(15,52,96,0.04);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
}

*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html{font-size:16px;scroll-behavior:smooth}
body{
  font-family:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif;
  background:var(--gray-100);color:var(--gray-900);min-height:100vh;display:flex;flex-direction:column
}
a{color:var(--primary);text-decoration:none}
a:hover{text-decoration:underline}

/* Login */
#login-screen{display:flex;align-items:center;justify-content:center;min-height:100vh;background:linear-gradient(135deg,var(--primary-dark) 0%,var(--primary) 50%,var(--primary-light) 100%);padding:24px}
.login-card{background:#fff;border-radius:var(--radius-xl);padding:48px 40px;width:100%;max-width:420px;box-shadow:var(--shadow-xl);animation:fadeInUp .4s ease-out}
.login-card .logo{height:36px;margin-bottom:32px;display:block}
.login-card h2{font-size:22px;font-weight:700;color:var(--gray-900);margin-bottom:6px}
.login-card p{color:var(--gray-500);font-size:14px;margin-bottom:28px}
.form-group{margin-bottom:18px}
.form-group label{display:block;font-size:13px;font-weight:600;color:var(--gray-700);margin-bottom:5px}
.form-group input,.form-group select{width:100%;padding:10px 14px;border:1.5px solid var(--gray-200);border-radius:var(--radius-sm);font-size:14px;font-family:inherit;transition:all .2s;background:#fff;color:var(--gray-900)}
.form-group input:focus,.form-group select:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-ghost)}
.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;padding:10px 22px;border-radius:var(--radius-sm);font-size:14px;font-weight:600;font-family:inherit;cursor:pointer;border:1.5px solid transparent;transition:all .2s;white-space:nowrap}
.btn-primary{background:var(--primary);color:#fff;border-color:var(--primary)}
.btn-primary:hover{background:var(--primary-dark);border-color:var(--primary-dark);transform:translateY(-1px);box-shadow:var(--shadow-md)}
.btn-primary:active{transform:translateY(0)}
.btn-secondary{background:#fff;color:var(--gray-700);border-color:var(--gray-200)}
.btn-secondary:hover{background:var(--gray-50);border-color:var(--gray-300)}
.btn-danger{background:var(--accent-red);color:#fff;border-color:var(--accent-red)}
.btn-danger:hover{background:#dc2626;border-color:#dc2626}
.btn-success{background:var(--accent-green);color:#fff;border-color:var(--accent-green)}
.btn-success:hover{background:#059669;border-color:#059669}
.btn-ghost{background:transparent;color:var(--gray-600);border-color:transparent}
.btn-ghost:hover{background:var(--gray-100);color:var(--gray-800)}
.btn-sm{padding:6px 14px;font-size:12px}
.btn-block{width:100%;justify-content:center}
.btn:disabled{opacity:.5;cursor:not-allowed;transform:none!important}
.toggle-link{text-align:center;margin-top:16px;font-size:13px;color:var(--gray-500)}
.toggle-link a{cursor:pointer;color:var(--primary);font-weight:600}
.toggle-link a:hover{text-decoration:underline}

/* Dashboard layout */
#dashboard{display:none;flex-direction:column;flex:1}
.app-header{background:#fff;border-bottom:1px solid var(--gray-200);padding:0 32px;height:64px;display:flex;align-items:center;justify-content:space-between;position:sticky;top:0;z-index:100;box-shadow:var(--shadow-sm)}
.app-header .brand{display:flex;align-items:center;gap:14px}
.app-header .brand img{height:28px}
.app-header .brand h1{font-size:17px;font-weight:700;color:var(--primary-dark)}
.app-header .brand .badge{font-size:10px;font-weight:600;color:var(--primary);background:var(--primary-ghost);padding:2px 8px;border-radius:20px;margin-left:4px;margin-top:2px}
.header-right{display:flex;align-items:center;gap:16px}
.user-info{font-size:13px;color:var(--gray-600);display:flex;align-items:center;gap:8px}
.user-info .avatar{width:32px;height:32px;border-radius:50%;background:linear-gradient(135deg,var(--primary),var(--primary-light));color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;font-size:13px}
.role-badge{font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:.4px;padding:2px 8px;border-radius:20px}
.role-badge.admin{background:var(--primary-ghost);color:var(--primary)}
.role-badge.user{background:rgba(139,92,246,0.1);color:var(--accent-purple)}
.app-layout{display:flex;flex:1;min-height:calc(100vh - 64px)}

/* Sidebar */
.sidebar{width:240px;background:#fff;border-right:1px solid var(--gray-200);padding:20px 0;flex-shrink:0;overflow-y:auto}
.nav-item{display:flex;align-items:center;gap:12px;padding:10px 24px;font-size:14px;font-weight:500;color:var(--gray-600);cursor:pointer;transition:all .15s;border-right:3px solid transparent;margin:2px 0}
.nav-item:hover{background:var(--gray-50);color:var(--gray-800)}
.nav-item.active{background:var(--primary-subtle);color:var(--primary);font-weight:600;border-right-color:var(--primary)}
.nav-item .icon{width:20px;text-align:center;font-size:16px}
.nav-item .counter{margin-left:auto;background:var(--gray-100);color:var(--gray-600);font-size:11px;font-weight:600;padding:1px 8px;border-radius:20px}
.nav-item.active .counter{background:var(--primary-ghost);color:var(--primary)}

/* Main */
.main-content{flex:1;padding:28px 32px;overflow-y:auto}
.page{display:none;animation:fadeIn .25s ease}
.page.active{display:block}
.page-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:24px}
.page-header h2{font-size:22px;font-weight:700;color:var(--gray-900)}
.page-header p{font-size:14px;color:var(--gray-500);margin-top:2px}

/* Stats */
.stats-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:16px;margin-bottom:28px}
.stat-card{background:#fff;border-radius:var(--radius);padding:20px;box-shadow:var(--shadow);border:1px solid var(--gray-100);transition:all .2s}
.stat-card:hover{transform:translateY(-2px);box-shadow:var(--shadow-md)}
.stat-card .stat-icon{font-size:24px;margin-bottom:8px}
.stat-card .stat-value{font-size:28px;font-weight:700;color:var(--gray-900);line-height:1}
.stat-card .stat-label{font-size:12px;font-weight:500;color:var(--gray-500);margin-top:4px;text-transform:uppercase;letter-spacing:.3px}
.stat-card.primary .stat-value{color:var(--primary)}
.stat-card.green .stat-value{color:var(--accent-green)}
.stat-card.red .stat-value{color:var(--accent-red)}
.stat-card.amber .stat-value{color:var(--accent-amber)}
.stat-card.purple .stat-value{color:var(--accent-purple)}

/* Tables */
.docs-toolbar{display:flex;align-items:center;gap:12px;margin-bottom:16px;flex-wrap:wrap}
.docs-toolbar .search-box{flex:1;position:relative}
.docs-toolbar .search-box input{width:100%;padding:9px 14px 9px 36px;border:1.5px solid var(--gray-200);border-radius:var(--radius-sm);font-size:13px;font-family:inherit;background:#fff}
.docs-toolbar .search-box input:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-ghost)}
.docs-toolbar .search-box .search-icon{position:absolute;left:12px;top:50%;transform:translateY(-50%);color:var(--gray-400);font-size:14px}
.filter-select{padding:9px 14px;border:1.5px solid var(--gray-200);border-radius:var(--radius-sm);font-size:13px;font-family:inherit;background:#fff;color:var(--gray-700)}
.filter-select:focus{outline:none;border-color:var(--primary)}

.card{background:#fff;border-radius:var(--radius-lg);box-shadow:var(--shadow);border:1px solid var(--gray-100);overflow:hidden}
.card-header{padding:16px 20px;border-bottom:1px solid var(--gray-100);display:flex;align-items:center;justify-content:space-between}
.card-header h3{font-size:15px;font-weight:600;color:var(--gray-800)}
.card-body{padding:0}
.empty-state{padding:48px 24px;text-align:center;color:var(--gray-400)}
.empty-state .empty-icon{font-size:48px;margin-bottom:12px}
.empty-state p{font-size:14px;margin-bottom:4px}
.empty-state .sub{font-size:12px;color:var(--gray-400)}

.doc-table{width:100%;border-collapse:collapse}
.doc-table thead{background:var(--gray-50)}
.doc-table th{padding:10px 16px;text-align:left;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.4px;color:var(--gray-500)}
.doc-table td{padding:12px 16px;font-size:13px;border-bottom:1px solid var(--gray-100);vertical-align:middle}
.doc-table tbody tr:hover{background:var(--gray-50);cursor:pointer}
.doc-table tbody tr:last-child td{border-bottom:none}
.doc-name{font-weight:600;color:var(--gray-800)}
.doc-meta{font-size:11px;color:var(--gray-400);margin-top:2px}

/* Status badges */
.status-badge{display:inline-flex;align-items:center;gap:5px;font-size:11px;font-weight:600;padding:3px 10px;border-radius:20px;text-transform:capitalize}
.status-badge .dot{width:6px;height:6px;border-radius:50%;display:inline-block}
.status-badge.uploaded{background:var(--gray-100);color:var(--gray-600)}
.status-badge.uploaded .dot{background:var(--gray-400)}
.status-badge.editing{background:rgba(245,158,11,0.1);color:#b45309}
.status-badge.editing .dot{background:var(--accent-amber)}
.status-badge.submitted{background:rgba(139,92,246,0.1);color:var(--accent-purple)}
.status-badge.submitted .dot{background:var(--accent-purple)}
.status-badge.approved{background:rgba(16,185,129,0.1);color:#047857}
.status-badge.approved .dot{background:var(--accent-green)}
.status-badge.rejected{background:rgba(239,68,68,0.1);color:#b91c1c}
.status-badge.rejected .dot{background:var(--accent-red)}
.status-badge.exported{background:var(--primary-ghost);color:var(--primary)}
.status-badge.exported .dot{background:var(--primary)}

/* Detail Modal */
.detail-overlay{display:none;position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(15,23,42,0.5);backdrop-filter:blur(4px);z-index:200;animation:fadeIn .2s ease}
.detail-overlay.open{display:flex;align-items:center;justify-content:center;padding:24px}
.detail-panel{background:#fff;border-radius:var(--radius-xl);width:100%;max-width:800px;max-height:90vh;overflow-y:auto;box-shadow:var(--shadow-xl);animation:scaleIn .25s ease}
.detail-header{display:flex;align-items:center;justify-content:space-between;padding:20px 24px;border-bottom:1px solid var(--gray-200);position:sticky;top:0;background:#fff;z-index:5;border-radius:var(--radius-xl) var(--radius-xl) 0 0}
.detail-header h3{font-size:18px;font-weight:700;color:var(--gray-900)}
.detail-header .close-btn{width:32px;height:32px;border-radius:50%;border:none;background:var(--gray-100);color:var(--gray-500);font-size:18px;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all .15s}
.detail-header .close-btn:hover{background:var(--gray-200);color:var(--gray-700)}
.detail-body{padding:24px}
.detail-meta-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:20px}
.detail-meta-item label{display:block;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.4px;color:var(--gray-400);margin-bottom:2px}
.detail-meta-item span{font-size:14px;color:var(--gray-800)}

.editor-section{margin-bottom:20px}
.editor-section label{display:block;font-size:13px;font-weight:600;color:var(--gray-700);margin-bottom:6px}
.editor-section textarea{width:100%;min-height:200px;padding:14px;border:1.5px solid var(--gray-200);border-radius:var(--radius-sm);font-size:13px;font-family:'SF Mono','Fira Code','Consolas',monospace;line-height:1.6;resize:vertical;transition:border-color .2s}
.editor-section textarea:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-ghost)}

.admin-section{background:var(--gray-50);border-radius:var(--radius);padding:16px;margin-bottom:16px;border:1px solid var(--gray-200)}
.admin-section label{display:block;font-size:13px;font-weight:600;color:var(--gray-700);margin-bottom:6px}
.admin-section textarea{width:100%;padding:10px 14px;border:1.5px solid var(--gray-200);border-radius:var(--radius-sm);font-size:13px;font-family:inherit;resize:vertical;min-height:60px;background:#fff}
.admin-section textarea:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-ghost)}
.detail-actions{display:flex;gap:10px;flex-wrap:wrap;padding-top:16px;border-top:1px solid var(--gray-200)}

/* Users */
.user-list{display:grid;gap:10px;padding:16px}
.user-row{display:flex;align-items:center;justify-content:space-between;padding:12px 16px;background:var(--gray-50);border-radius:var(--radius-sm);transition:background .15s}
.user-row:hover{background:var(--gray-100)}
.user-row .user-info-row{display:flex;align-items:center;gap:12px}
.user-row .user-avatar{width:36px;height:36px;border-radius:50%;background:linear-gradient(135deg,var(--accent-purple),var(--primary-light));color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;font-size:14px}
.user-row .user-details .user-name{font-weight:600;color:var(--gray-800);font-size:14px}
.user-row .user-details .user-email{font-size:12px;color:var(--gray-500)}
.user-row .user-meta{font-size:12px;color:var(--gray-400)}

/* Upload */
.upload-zone{border:2px dashed var(--gray-300);border-radius:var(--radius-lg);padding:48px 24px;text-align:center;transition:all .2s;cursor:pointer;background:var(--gray-50);margin-bottom:20px}
.upload-zone:hover,.upload-zone.dragover{border-color:var(--primary);background:var(--primary-ghost)}
.upload-zone .upload-icon{font-size:48px;margin-bottom:12px;color:var(--primary-light)}
.upload-zone h4{font-size:16px;font-weight:600;color:var(--gray-700);margin-bottom:4px}
.upload-zone p{font-size:13px;color:var(--gray-500)}
.upload-zone input[type="file"]{display:none}

/* Toast */
.toast-container{position:fixed;bottom:24px;right:24px;z-index:999;display:flex;flex-direction:column;gap:8px}
.toast{padding:12px 20px;border-radius:var(--radius);font-size:13px;font-weight:500;box-shadow:var(--shadow-lg);animation:slideIn .3s ease;display:flex;align-items:center;gap:8px;max-width:400px}
.toast.success{background:#065f46;color:#fff}
.toast.error{background:#991b1b;color:#fff}
.toast.info{background:var(--primary-dark);color:#fff}
.toast.warning{background:#92400e;color:#fff}

/* Timeline */
.timeline{position:relative;padding-left:28px;margin:12px 0}
.timeline::before{content:'';position:absolute;left:8px;top:4px;bottom:4px;width:2px;background:var(--gray-200);border-radius:1px}
.timeline-item{position:relative;padding:0 0 16px 0}
.timeline-item::before{content:'';position:absolute;left:-24px;top:6px;width:10px;height:10px;border-radius:50%;background:var(--primary);border:2px solid #fff;box-shadow:var(--shadow-sm)}
.timeline-item .tl-title{font-size:13px;font-weight:600;color:var(--gray-800)}
.timeline-item .tl-desc{font-size:12px;color:var(--gray-500);margin-top:1px}
.timeline-item .tl-time{font-size:11px;color:var(--gray-400)}

/* Animations */
@keyframes fadeIn{from{opacity:0}to{opacity:1}}
@keyframes fadeInUp{from{opacity:0;transform:translateY(16px)}to{opacity:1;transform:translateY(0)}}
@keyframes scaleIn{from{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}
@keyframes slideIn{from{opacity:0;transform:translateX(24px)}to{opacity:1;transform:translateX(0)}}

/* Responsive */
@media(max-width:768px){
  .sidebar{display:none;position:fixed;top:0;left:0;width:280px;height:100vh;z-index:1000;background:#fff;box-shadow:2px 0 20px rgba(0,0,0,.15);padding:20px 0;transition:transform .25s ease}
  .sidebar.open{display:block}
  .sidebar-overlay{display:none}
  .sidebar-overlay.open{display:block;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.3);z-index:999}
  .app-header .hamburger{display:inline-flex;align-items:center;justify-content:center;width:36px;height:36px;border:none;background:none;font-size:22px;cursor:pointer;color:var(--gray-700);margin-right:8px;border-radius:var(--radius-sm)}
  .app-header .hamburger:hover{background:var(--gray-100)}
  .app-header{padding:0 16px}
  .main-content{padding:16px}
  .stats-grid{grid-template-columns:1fr 1fr}
  .detail-panel{margin:0;max-height:100vh;border-radius:0}
  .detail-overlay.open{padding:0}
}

/* Scrollbar */
::-webkit-scrollbar{width:6px}
::-webkit-scrollbar-track{background:transparent}
::-webkit-scrollbar-thumb{background:var(--gray-300);border-radius:3px}
::-webkit-scrollbar-thumb:hover{background:var(--gray-400)}

/* ═══ Split Pane Editor + Live Preview ═══ */
.split-pane{display:flex;gap:16px;margin-bottom:20px;min-height:350px}
.split-left,.split-right{flex:1;display:flex;flex-direction:column;min-width:0}
.split-header{font-size:12px;font-weight:600;color:var(--gray-500);text-transform:uppercase;letter-spacing:.3px;margin-bottom:6px;padding-bottom:6px;border-bottom:1px solid var(--gray-100)}
.live-editor{width:100%;flex:1;min-height:320px;padding:14px;border:1.5px solid var(--gray-200);border-radius:var(--radius-sm);font-size:13px;font-family:'SF Mono','Fira Code','Consolas',monospace;line-height:1.6;resize:vertical;transition:border-color .2s;background:#fafbfc}
.live-editor:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px var(--primary-ghost)}
.live-preview{flex:1;min-height:320px;padding:14px;border:1.5px solid var(--gray-200);border-radius:var(--radius-sm);background:#fff;overflow-y:auto;font-size:13px;line-height:1.7;color:var(--gray-800)}
.live-preview h1{font-size:20px;font-weight:700;color:var(--gray-900);margin:16px 0 8px;padding-bottom:6px;border-bottom:2px solid var(--primary)}
.live-preview h2{font-size:16px;font-weight:700;color:var(--primary-dark);margin:14px 0 6px}
.live-preview h3{font-size:14px;font-weight:600;color:var(--gray-800);margin:12px 0 4px}
.live-preview p{margin:0 0 8px;color:var(--gray-700)}
.live-preview ul,.live-preview ol{margin:4px 0 8px;padding-left:20px}
.live-preview li{margin-bottom:3px}
.live-preview hr{border:none;border-top:2px solid var(--gray-200);margin:16px 0}
.live-preview blockquote{border-left:3px solid var(--primary);margin:8px 0;padding:6px 14px;background:var(--primary-ghost);border-radius:0 var(--radius-sm) var(--radius-sm) 0;color:var(--gray-600);font-style:italic}
.live-preview strong{font-weight:700;color:var(--gray-900)}
.live-preview em{font-style:italic;color:var(--gray-700)}

/* Detail action bar */
.detail-action-bar{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:16px;padding-bottom:12px;border-bottom:1px solid var(--gray-100)}

/* ═══ PDF Viewer + Editor Layout ═══ */
.pdf-viewer-editor {
  display: flex;
  gap: 20px;
  margin: 16px 0;
  min-height: 500px;
}

.pdf-viewer-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pdf-frame-container {
  flex: 1;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #f5f5f5;
  min-height: 400px;
}

.pdf-frame {
  width: 100%;
  height: 100%;
  min-height: 400px;
  border: none;
}

.editor-pane {
  flex: 1.2;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--primary-ghost);
  color: var(--primary);
  text-transform: none;
  letter-spacing: normal;
  vertical-align: middle;
  margin-left: 6px;
}

@media (max-width: 900px) {
  .pdf-viewer-editor {
    flex-direction: column-reverse;
  }
}

/* ── wider detail panel for PDF viewer ── */
.detail-panel.detail-panel-wide {
  max-width: 1200px;
}

/* ── HTML Editor + Iframe Preview (new) ── */
.html-editor {
  width: 100%;
  flex: 1;
  min-height: 400px;
  height: 450px;
  padding: 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.6;
  overflow-y: auto;
  background: #fafbfc;
  font-family: 'Times New Roman', Times, serif;
  transition: border-color .2s;
  white-space: normal;
  word-wrap: break-word;
}
.html-editor:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ghost);
}
.html-editor[contenteditable="false"] {
  background: #f5f5f5;
  cursor: default;
}
.html-editor[contenteditable="true"]:empty:before {
  content: "Edit the HTML content here...";
  color: var(--gray-400);
}

.editor-pane-body {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.live-iframe-wrapper {
  flex: 1;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #e8e8e8;
  min-height: 450px;
  height: 450px;
}

.preview-iframe {
  width: 100%;
  height: 100%;
  min-height: 450px;
  border: none;
  background: white;
  transform-origin: top left;
}

/* ── fix PDF frame height (legacy) ── */
.pdf-viewer-pane {
  min-height: 500px;
}

.pdf-frame-container {
  min-height: 500px;
  height: 500px;
}

.pdf-frame {
  height: 500px;
  min-height: 500px;
}

.live-editor {
  min-height: 400px;
}

.live-preview {
  min-height: 400px;
}

/* ── Visual Editor + Source Toggle ── */
.split-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-weight: 600;
  font-size: 13px;
  color: var(--gray-700);
}

.html-source-wrap {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 400px;
}

.html-source {
  width: 100%;
  flex: 1;
  min-height: 400px;
  height: 450px;
  padding: 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 12px;
  line-height: 1.6;
  background: #1e1e2e;
  color: #cdd6f4;
  resize: vertical;
  tab-size: 2;
  overflow-y: auto;
}

.html-source:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ghost);
}

#toggle-source-btn {
  padding: 3px 10px;
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  color: var(--gray-700);
  cursor: pointer;
  font-size: 11px;
  transition: all .15s;
}

#toggle-source-btn:hover {
  background: var(--primary-ghost);
  border-color: var(--primary);
  color: var(--primary);
}

/* ── Source Toggle Button ── */
.btn-toggle-source {
  padding: 3px 10px;
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  color: var(--gray-700);
  cursor: pointer;
  font-size: 11px;
  transition: all .15s;
}
.btn-toggle-source:hover {
  background: var(--primary-ghost);
  border-color: var(--primary);
  color: var(--primary);
}

/* ── Source Code Editor (dark theme) ── */
.html-source-wrap {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 400px;
}
.html-source {
  width: 100%;
  flex: 1;
  min-height: 400px;
  height: 450px;
  padding: 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 12px;
  line-height: 1.6;
  background: #1e1e2e;
  color: #cdd6f4;
  resize: vertical;
  tab-size: 2;
  overflow-y: auto;
}
.html-source:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ghost);
}

/* ═══════════════════════════════════════════════════════════
   Block Editor Styles — AI Prompt Dashboard
   ═══════════════════════════════════════════════════════════ */

/* ── Editor Overlay (full-screen) ── */
.editor-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  z-index: 300;
  animation: fadeIn .15s ease;
}

.editor-panel {width:100%;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #fff;
}

.editor-body {
  flex: 1;
  overflow: hidden;
  display: flex;
}

/* ── Editor Toolbar ── */
.editor-toolbar-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
  min-height: 48px;
}

.editor-toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.editor-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.editor-toolbar-items {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  flex-wrap: wrap;
}

.ed-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--gray-700);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  line-height: 1;
}

.ed-btn:hover {
  background: var(--gray-50);
  border-color: var(--gray-300);
}

.ed-btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

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

.ed-btn-save {
  background: var(--accent-green);
  color: #fff;
  border-color: var(--accent-green);
}

.ed-btn-save:hover {
  background: #059669;
  border-color: #059669;
}

.ed-btn-submit {
  background: var(--accent-purple);
  color: #fff;
  border-color: var(--accent-purple);
}

.ed-btn-submit:hover {
  background: #7c3aed;
  border-color: #7c3aed;
}

.ed-btn-approve {
  background: var(--accent-green);
  color: #fff;
  border-color: var(--accent-green);
}

.ed-btn-reject {
  background: var(--accent-red);
  color: #fff;
  border-color: var(--accent-red);
}

.ed-btn-export {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.ed-sep {
  width: 1px;
  height: 20px;
  background: var(--gray-200);
  margin: 0 4px;
}

.close-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--gray-400);
  font-size: 18px;
  cursor: pointer;
  transition: all .15s;
  flex-shrink: 0;
}

.close-btn:hover {
  background: var(--gray-100);
  color: var(--gray-600);
}

/* ── Editor Canvas ── */
.editor-canvas {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  background: var(--gray-100);
}

/* ── Block Wrap (draggable content sections) ── */
.block-wrap {
  position: relative;
  cursor: grab;
  transition: opacity .2s, transform .2s;
  user-select: none;
}

.block-wrap:hover .drag-handle {
  opacity: 1;
}

.block-wrap.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.block-wrap [contenteditable="true"] {
  cursor: text;
  user-select: text;
}

.drag-handle {
  position: absolute;
  left: -28px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  font-size: 16px;
  cursor: grab;
  opacity: 0;
  transition: opacity .2s;
  border-radius: 4px;
  background: var(--gray-50);
  user-select: none;
}

.drag-handle:hover {
  background: var(--gray-100);
  color: var(--gray-600);
}

/* ── Drop Indicator ── */
.drop-indicator {
  height: 4px;
  margin: 4px 0;
  border-radius: 2px;
  background: transparent;
  transition: all .2s;
}

.drop-indicator.active {
  height: 8px;
  margin: 6px 0;
  background: var(--primary-light);
  box-shadow: 0 0 8px rgba(20,92,199,0.3);
}

/* ── Page Break ── */
.page-break {
  height: 4px;
  width: 100%;
  max-width: 816px;
  background: repeating-linear-gradient(
    90deg,
    var(--gray-200) 0px,
    var(--gray-200) 8px,
    transparent 8px,
    transparent 16px
  );
  margin: 4px 0;
  border-radius: 2px;
}

/* ── Page styles within editor ── */
.editor-canvas .page {display:block;
  background: #fff;
  box-shadow: var(--shadow-md);
  margin: 8px 0;
  border-radius: 2px;
  position: relative;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15,23,42,0.5);
  backdrop-filter: blur(4px);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn .15s ease;
}

.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-xl);
  animation: scaleIn .2s ease;
}

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

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--gray-900);
}

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

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

.form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--gray-900);
}

.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ghost);
}

/* ── Approval Cards ── */
.approval-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer;
  transition: background .15s;
}

.approval-card:hover {
  background: var(--gray-50);
}

.approval-card:last-child {
  border-bottom: none;
}

.approval-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.approval-info strong {
  font-size: 14px;
  color: var(--gray-800);
}

.approval-info .meta {
  font-size: 12px;
  color: var(--gray-400);
}

.approval-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Activity Items ── */
.activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer;
  transition: background .15s;
}

.activity-item:hover {
  background: var(--gray-50);
}

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

.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.activity-dot.status-submitted {
  background: var(--accent-purple);
}

.activity-dot.status-approved {
  background: var(--accent-green);
}

.activity-dot.status-rejected {
  background: var(--accent-red);
}

.activity-dot.status-exported {
  background: var(--primary);
}

.activity-dot.status-editing,
.activity-dot.status-draft {
  background: var(--accent-amber);
}

.activity-content {
  flex: 1;
}

.activity-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 1px;
}

.activity-meta {
  font-size: 11px;
  color: var(--gray-400);
}

/* ── Tables ── */
table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--gray-500);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-100);
}

tbody td {
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

tbody tr:hover {
  background: var(--gray-50);
  cursor: pointer;
}

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

.action-cell {
  width: 80px;
  text-align: right;
}

.meta-cell {
  color: var(--gray-400);
  font-size: 12px;
}

.btn-view {
  display: inline-flex;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  background: var(--primary-ghost);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}

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

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

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow-lg);
  animation: slideIn .2s ease;
  transition: opacity .3s;
  max-width: 360px;
}

.toast.success {
  background: var(--accent-green);
}

.toast.error {
  background: var(--accent-red);
}

.toast.info {
  background: var(--primary);
}

.toast.warning {
  background: var(--accent-amber);
}

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(60px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── Bulk Select ── */
.chk-cell { width: 36px; text-align: center; }
.chk-cell input { width: 16px; height: 16px; cursor: pointer; }
#bulk-bar { display: none; align-items: center; gap: 12px; padding: 8px 12px; background: #f1f5f9; border-radius: 8px; margin-bottom: 12px; }
.bulk-count { font-size: 13px; font-weight: 600; color: #1e293b; }

/* ── Document Action Buttons ── */
.action-cell { white-space: nowrap; }
.btn-view { cursor: pointer; color: var(--primary); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.btn-action { cursor: pointer; padding: 2px 6px; font-size: 14px; border-radius: 4px; transition: background 0.15s; }
.btn-action:hover { background: #f1f5f9; }

/* ── Templates Grid (stacked cards for wider preview) ── */
.tmpl-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 4px; }
.tmpl-header h2 { margin: 0; font-size: 22px; font-weight: 700; color: #0f172a; }
.tmpl-count { font-size: 13px; color: #64748b; font-weight: 500; }
.tmpl-grid { display: flex; flex-direction: column; gap: 20px; margin-top: 20px; }
.tmpl-card { background: #fff; border: 1px solid #e2e8f0; border-radius: 14px; overflow: hidden; transition: all 0.2s ease; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.tmpl-card:hover { box-shadow: 0 8px 25px rgba(0,0,0,0.08); border-color: #cbd5e1; }
.tmpl-preview { height: 420px; overflow: auto; border-bottom: 1px solid #f1f5f9; position: relative; background: #fafafa; }
.tmpl-preview iframe { width: 100%; height: 100%; border: none; min-height: 100%; }
.tmpl-info { padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; background: #fff; border-top: 1px solid #f8fafc; flex-shrink: 0; }
.tmpl-name { font-size: 15px; font-weight: 700; color: #145CC7; cursor: text; }
.tmpl-name::before { content: '📄 '; font-size: 14px; }
.tmpl-actions { display: flex; gap: 6px; }
.tmpl-actions .btn { font-size: 12px; padding: 5px 12px; border-radius: 8px; font-weight: 600; }
.section-actions { margin-top: 20px; }

/* ── Preview Mode ── */
#preview-indicator { position: fixed; top: 4px; left: 50%; transform: translateX(-50%); z-index: 9999; background: rgba(0,0,0,0.7); color: #fff; padding: 2px 14px; border-radius: 12px; font-size: 11px; letter-spacing: 0.5px; font-weight: 500; display: none; }
#preview-toggle { cursor: pointer; }
#save-as-tpl-btn { cursor: pointer; }

/* Editor select/color inputs */
.ed-select {
  height:28px;border:1px solid #dbe7f5;border-radius:4px;
  background:#fff;color:#1a1a1a;font-size:11px;font-family:Montserrat,sans-serif;
  padding:0 4px;cursor:pointer;outline:none;
}
.ed-select:focus { border-color:var(--primary); }
.ed-color {
  width:28px;height:28px;border:1px solid #dbe7f5;border-radius:4px;
  padding:2px;cursor:pointer;background:#fff;
}
.ed-color::-webkit-color-swatch-wrapper { padding:0; }
.ed-color::-webkit-color-swatch { border-radius:2px; border:none; }
.source-modal-backdrop {
  position:fixed;top:0;left:0;width:100%;height:100%;
  background:rgba(0,0,0,0.5);z-index:9999;
  display:flex;align-items:center;justify-content:center;
}

/* ── Profile Page ── */
#profile-content .card {
  max-width:600px;margin:0 auto 24px;
}
#profile-content .card-header h3 {
  font-size:16px;
}
#profile-content .card-body .form-group {
  margin-bottom:16px;
}
#profile-content .card-body label {
  font-size:12px;font-weight:600;color:var(--gray-600);display:block;margin-bottom:4px;text-transform:uppercase;letter-spacing:0.3px;
}

/* ── Template Permissions ── */
#template-permissions-content .section-header {
  margin-bottom:20px;
}
#template-permissions-content .section-header h2 {
  font-size:18px;font-weight:700;
}

/* ── Editable Name / Role Select ── */
.editable-name {
  cursor:text;padding:2px 4px;border-radius:3px;transition:background 0.15s;
}
.editable-name:hover {
  background:var(--primary-ghost);
}
.role-select {
  font-size:12px;padding:3px 6px;border:1px solid var(--gray-200);border-radius:4px;background:#fff;cursor:pointer;font-family:inherit;
}
.role-select:disabled {
  opacity:0.5;cursor:not-allowed;
}
.add-user-form {
  animation:fadeIn .2s ease-out;
}

/* ── Nav Divider ── */
.nav-divider {
  border:none;border-top:1px solid rgba(255,255,255,0.08);margin:4px 12px;
}

.app-header .hamburger{display:none}

/* ── Loading State ── */
.loading {
  text-align:center;padding:48px 24px;color:var(--gray-400);font-size:14px;
}

/* ── Assigned Templates (profile) ── */
#assigned-templates-section .status-badge.status-uploaded {
  background:var(--primary-subtle);color:var(--primary);border:1px solid rgba(20,92,199,0.15);
}

/* ── Permission user checkboxes ── */
.perm-user-cb {
  accent-color:var(--primary);
}

/* ── Profile Page ── */
.page-profile .card { border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden; }
.page-profile .card-header { padding: 16px 20px; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); font-weight: 600; }

/* ── Template Permissions ── */
.tp-ctn { display: flex; flex-direction: column; gap: 16px; }
.tp-card { border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden; }
.tp-card-header { padding: 14px 18px; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); display: flex; justify-content: space-between; align-items: center; }
.tp-card-body { padding: 14px 18px; }
.tp-user-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.tp-user-check { width: 18px; height: 18px; cursor: pointer; }
.tp-user-label { font-size: 14px; color: var(--gray-700); }

/* ── Users Table ── */
.user-table { width: 100%; border-collapse: collapse; }
.user-table th { text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: 1px; border-bottom: 2px solid var(--gray-200); }
.user-table td { padding: 10px 12px; border-bottom: 1px solid var(--gray-100); font-size: 14px; }
.user-table tr:hover td { background: var(--gray-50); }
.user-edit-inline { border: 1px solid var(--primary); border-radius: 4px; padding: 2px 6px; font-size: 14px; }
.role-badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.role-badge.admin { background: #E3F2FD; color: #1565C0; }
.role-badge.user { background: #F3E5F5; color: #7B1FA2; }

/* ── Template Preview Modal ── */
.tmpl-preview-full { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 10000; display: flex; align-items: center; justify-content: center; }
.tmpl-preview-full-content { width: 90%; height: 90%; background: #fff; border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; }
.tmpl-preview-full-toolbar { padding: 12px 16px; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); display: flex; justify-content: space-between; align-items: center; }
.tmpl-preview-full-frame { flex: 1; border: none; overflow: auto; }
