:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --secondary: #0f766e;
  --success: #15803d;
  --danger: #dc2626;
  --warn: #d97706;
  --text: #0f172a;
  --muted: #64748b;
  --border: #cbd5e1;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.req { color: var(--danger); font-weight: 600; font-size: 12px; }

/* OVERLAY & TOAST */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: flex; align-items: center; justify-content: center; z-index: 9999; backdrop-filter: blur(2px); }
.loader-card { background: #fff; padding: 24px 32px; border-radius: 12px; text-align: center; min-width: 280px; box-shadow: 0 20px 40px rgba(0,0,0,.25); }
.spinner { width: 38px; height: 38px; border: 4px solid #e2e8f0; border-top-color: var(--primary); border-radius: 50%; animation: spin .75s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress-wrap { width: 100%; height: 8px; background: #e2e8f0; border-radius: 99px; margin-top: 10px; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: var(--primary); transition: width .2s; }

#toast-container { position: fixed; top: 16px; right: 16px; z-index: 10000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 360px; animation: fadeIn .2s ease; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warn); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* LOGIN */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a, #1d4ed8); padding: 20px; }
.login-card { background: #fff; width: 100%; max-width: 400px; padding: 32px; border-radius: 14px; box-shadow: 0 25px 50px rgba(0,0,0,.3); }
.login-brand { text-align: center; margin-bottom: 24px; }
.brand-badge { display: inline-block; background: var(--primary); color: #fff; font-weight: 800; padding: 6px 14px; border-radius: 8px; letter-spacing: 1px; margin-bottom: 10px; }
.login-brand h1 { font-size: 20px; margin-bottom: 4px; }
.login-brand p { font-size: 13px; color: var(--muted); }
.alert { padding: 10px 12px; border-radius: 8px; margin-top: 12px; font-size: 13px; }
.alert-danger { background: #fee2e2; color: #991b1b; }

/* SHELL */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 250px; background: var(--sidebar); color: #fff; display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 100; transition: transform .2s; }
.sidebar-header { display: flex; align-items: center; gap: 12px; padding: 18px 16px; border-bottom: 1px solid #1e293b; }
.brand-mini { width: 38px; height: 38px; border-radius: 10px; background: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 800; }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: #94a3b8; }
.nav-menu { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; background: transparent; border: none; color: #cbd5e1; padding: 11px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; text-align: left; transition: background .15s; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.sidebar-footer { padding: 14px; border-top: 1px solid #1e293b; }
.user-box { margin-bottom: 10px; }
.user-name { font-weight: 600; font-size: 13px; }
.user-unit { font-size: 12px; color: #94a3b8; margin-bottom: 6px; }
.idle-chip { font-size: 11px; background: #1e293b; color: #93c5fd; padding: 4px 8px; border-radius: 6px; display: inline-block; }

.main-content { flex: 1; margin-left: 250px; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: #fff; border-bottom: 1px solid #e2e8f0; padding: 12px 24px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; }
.topbar h2 { font-size: 18px; }
.view-section { display: none; padding: 20px 24px 60px; max-width: 1280px; width: 100%; margin: 0 auto; }
.view-section.active { display: block; }

/* CARDS & FORMS */
.card { background: var(--surface); border: 1px solid #e2e8f0; border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.card-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid #f1f5f9; }
.card-header h3 { font-size: 15px; font-weight: 700; }
.chip { font-size: 11.5px; background: #eff6ff; color: #1d4ed8; padding: 3px 9px; border-radius: 99px; font-weight: 500; }
.chip-warn { background: #fef3c7; color: #b45309; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }

.editor-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; background: #fff; border: 1px solid #e2e8f0; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; position: sticky; top: 56px; z-index: 40; box-shadow: 0 4px 12px rgba(0,0,0,.05); }
.editor-status { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toolbar-btns { display: flex; gap: 8px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.form-group { margin-bottom: 12px; }
.form-group label, .sub-header label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border); border-radius: 7px; font-size: 13.5px; font-family: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29,78,216,.12); }
.intro-input { margin-bottom: 8px; background: #f8fafc !important; }
.input-with-btn { display: flex; gap: 6px; }

.sub-block { margin-top: 14px; padding-top: 12px; border-top: 1px dashed #e2e8f0; }
.sub-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.inline-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dynamic-list { display: flex; flex-direction: column; gap: 8px; }

.dyn-row { display: flex; gap: 8px; align-items: flex-start; background: #f8fafc; padding: 10px; border-radius: 8px; border: 1px solid #e2e8f0; }
.dyn-row-col { flex-direction: column; }
.dyn-row-head { display: flex; width: 100%; gap: 8px; align-items: center; }
.dyn-num { font-weight: 700; color: var(--primary); min-width: 24px; padding-top: 6px; }
.sub-points-box { width: 100%; padding-left: 26px; display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }

/* BUTTONS */
.btn { border: none; border-radius: 7px; padding: 8px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: opacity .15s, background .15s; white-space: nowrap; }
.btn:hover { opacity: .92; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warn { background: var(--warn); color: #fff; }
.btn-outline { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 4px 7px; font-size: 11.5px; border-radius: 5px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { background: #f1f5f9; border: 1px solid #cbd5e1; border-radius: 6px; padding: 5px 9px; cursor: pointer; }
.btn-del { background: #fee2e2; color: #b91c1c; border: none; border-radius: 6px; padding: 6px 9px; cursor: pointer; font-weight: 700; }

/* UPLOAD & MEDIA */
.upload-zone { border: 2px dashed #94a3b8; border-radius: 10px; padding: 16px; text-align: center; background: #f8fafc; margin-bottom: 12px; }
.upload-zone p { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); gap: 12px; }
.media-card { border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.media-card img { width: 100%; height: 150px; object-fit: contain; background: #f1f5f9; }
.media-card-body { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.media-card-body input { font-size: 12px; padding: 5px 7px; }
.media-meta { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--muted); }

/* FLOWCHART PREVIEW */
.flowchart-preview { margin-top: 12px; background: #fff; border: 1px solid #cbd5e1; border-radius: 10px; padding: 16px; overflow-x: auto; text-align: center; }
.flowchart-preview svg { max-width: 100%; height: auto; }

/* TABLES */
.table-responsive { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { border: 1px solid #e2e8f0; padding: 8px 10px; text-align: left; vertical-align: middle; }
.data-table th { background: #f8fafc; font-weight: 700; }
.compact-table td { padding: 5px 6px; }
.action-stack { display: flex; flex-wrap: wrap; gap: 4px; }
.group-pay-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.group-pay-controls select { flex: 1; min-width: 240px; }
.form-footer-bar { display: flex; justify-content: flex-end; margin-top: 10px; }
.logo-admin-box { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; margin-top: 10px; }
.logo-admin-box img { max-height: 90px; border: 1px solid #e2e8f0; padding: 6px; border-radius: 8px; }

.mobile-only { display: none; }
@media (max-width: 900px) {
  .mobile-only { display: inline-flex; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
