/* DocFlow - clean, professional, minimal. Navy sidebar, white content, #2563eb accent. */
:root {
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --side-bg: #0f172a;
  --side-text: #cbd5e1;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 700; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
code { background: #f1f5f9; border-radius: 4px; padding: 1px 5px; font-size: 0.9em; }

/* Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--side-bg); color: var(--side-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.brand { font-weight: 800; font-size: 18px; color: #fff; padding: 20px 18px 14px; letter-spacing: 0.2px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  color: #fff; font-size: 15px; margin-right: 6px;
}
.sidebar nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; flex: 1; }
.sidebar nav a {
  color: var(--side-text); padding: 10px 12px; border-radius: 8px; font-weight: 500; font-size: 14px;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); text-decoration: none; color: #fff; }
.sidebar nav a.on { background: var(--accent); color: #fff; }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 13px; }
.sidebar-foot .who { color: #fff; font-weight: 600; }
.sidebar-foot .logout { color: var(--side-text); font-size: 12.5px; }
.nav-toggle { display: none; }

.content { flex: 1; padding: 26px 30px 60px; max-width: 1500px; min-width: 0; }

/* Cards / layout */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.split { display: flex; gap: 18px; align-items: flex-start; }
.split-left { flex: 1 1 480px; min-width: 0; }
.split-right { flex: 1 1 520px; min-width: 0; position: sticky; top: 20px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-n { font-size: 26px; font-weight: 800; color: var(--accent); }
.stat-l { color: var(--muted); font-size: 13px; }
.quick-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.quick {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 3px; color: var(--text);
}
.quick:hover { border-color: var(--accent); text-decoration: none; box-shadow: 0 2px 10px rgba(37,99,235,0.08); }
.quick span { color: var(--muted); font-size: 13px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.tpl-card {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 4px; color: var(--text); background: #fff;
}
.tpl-card:hover { border-color: var(--accent); text-decoration: none; box-shadow: 0 2px 10px rgba(37,99,235,0.1); }
.tpl-icon { font-size: 26px; }

/* Forms */
label { display: block; font-weight: 600; font-size: 13px; margin: 12px 0 4px; }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=number],
input[type=date], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37,99,235,0.35); border-color: var(--accent); }
textarea { resize: vertical; }
.search-row { display: flex; gap: 8px; margin-bottom: 14px; }
.search-row input[type=search] { max-width: 340px; }
.search-row select { width: auto; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent;
  border-radius: 8px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer;
  background: #e2e8f0; color: var(--text); white-space: nowrap;
}
.btn:hover { filter: brightness(0.97); text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.success { background: var(--success); color: #fff; }
.btn.danger { background: #fee2e2; color: var(--danger); }
.btn.ghost { background: #fff; border-color: var(--border); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.block { width: 100%; justify-content: center; margin-top: 16px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
form.inline { display: inline; }

/* Tables */
table.list { width: 100%; border-collapse: collapse; }
table.list th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--border);
}
table.list td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* Badges / flash */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;
  background: #e2e8f0;
}
.badge.draft { background: #fef3c7; color: #92400e; }
.badge.executed, .badge.final { background: #dcfce7; color: #166534; }
.flash { padding: 11px 15px; border-radius: 8px; margin-bottom: 16px; background: #dcfce7; color: #166534; font-weight: 500; }
.flash.error { background: #fee2e2; color: #991b1b; }
.flash.info { background: #dbeafe; color: #1e40af; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--side-bg); }
.login-card { background: #fff; border-radius: 14px; padding: 34px 34px 28px; width: 360px; max-width: 92vw; box-shadow: 0 20px 60px rgba(0,0,0,0.35); }
.login-card .brand { color: var(--text); padding: 0 0 4px; text-align: center; }

/* Avatars & media */
.avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; display: inline-flex; }
.avatar-blank { background: var(--accent); color: #fff; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.avatar-cell { width: 48px; }
.media-slot {
  border: 2px dashed var(--border); border-radius: 10px; min-height: 130px;
  display: flex; align-items: center; justify-content: center; overflow: hidden; background: #f8fafc;
}
.media-slot img { max-width: 100%; max-height: 220px; display: block; }
.media-slot.sig { min-height: 90px; background: #fff; }

/* Preview paper */
.preview-card { max-height: calc(100vh - 90px); display: flex; flex-direction: column; }
.paper {
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.07); padding: 12mm 14mm; overflow: auto; flex: 1; min-height: 300px;
}

/* Builder */
.editable-title input {
  font-size: 22px; font-weight: 700; border: 1px solid transparent; background: transparent;
  padding: 2px 6px; margin-left: -6px; width: min(560px, 90vw); border-radius: 6px;
}
.editable-title input:hover, .editable-title input:focus { border-color: var(--border); background: #fff; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; }
.field-grid .full { grid-column: 1 / -1; }
.save-state { font-size: 12.5px; min-width: 70px; text-align: right; }
.client-card { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; overflow: hidden; }
.client-card-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #f8fafc;
  cursor: pointer; border-bottom: 1px solid var(--border);
}
.client-card-head .num {
  background: var(--accent); color: #fff; width: 24px; height: 24px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 700; flex-shrink: 0;
}
.client-card-head .name { font-weight: 600; flex: 1; }
.client-card-body { padding: 12px 14px; }
.mini-media { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.mini-slot {
  width: 110px; height: 80px; border: 2px dashed var(--border); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; overflow: hidden; background: #f8fafc;
  font-size: 11px; color: var(--muted); text-align: center; cursor: pointer;
}
.mini-slot img { max-width: 100%; max-height: 100%; }
.mini-wrap { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.mini-wrap .lbl { font-size: 11.5px; color: var(--muted); font-weight: 600; }

/* Dropdown */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 4px); background: #fff;
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  min-width: 210px; z-index: 60; padding: 6px;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a { display: block; padding: 8px 12px; border-radius: 7px; color: var(--text); font-weight: 500; }
.dropdown-menu a:hover { background: #f1f5f9; text-decoration: none; }
.dropdown-sep { border-top: 1px solid var(--border); margin: 6px 0; }
.dropdown-label { font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 4px 12px; }

/* Modals */
.modal-back {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.55); z-index: 100;
  align-items: flex-start; justify-content: center; padding: 40px 14px; overflow: auto;
}
.modal-back.open { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 560px; max-width: 100%; padding: 20px 22px; }
.modal.wide { width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head .x { border: 0; background: none; font-size: 26px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.sig-canvas { border: 2px dashed var(--border); border-radius: 10px; width: 100%; height: 200px; touch-action: none; background: #fff; }
.crop-stage img { max-width: 100%; }

/* Template editor blocks */
.block-item { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; background: #fff; }
.block-item.dragging { opacity: 0.5; }
.block-item.client-on { border-left: 4px solid var(--accent); }
.block-head {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: #f8fafc;
  border-bottom: 1px solid var(--border); font-size: 12.5px;
}
.block-head .drag { cursor: grab; color: var(--muted); user-select: none; }
.block-head .type { font-weight: 700; text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.5px; color: var(--muted); }
.block-head .spacer { flex: 1; }
.block-head label.chk { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; margin: 0; font-weight: 500; }
.block-body { padding: 10px; }
.block-body textarea { min-height: 60px; font-family: Georgia, serif; }
.block-body .opts { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; align-items: center; }
.block-body .opts select, .block-body .opts input { width: auto; padding: 5px 8px; font-size: 12.5px; }
.field-row {
  display: grid; grid-template-columns: minmax(140px, 1.2fr) 1fr 110px 110px; gap: 8px;
  align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border);
}
.field-row:last-child { border-bottom: 0; }
.field-row code { font-size: 12px; overflow-wrap: anywhere; }
.field-row select, .field-row input { padding: 5px 8px; font-size: 12.5px; }
.drag-demo { color: var(--muted); }
.totp-secret { font-size: 16px; letter-spacing: 1px; }

/* Responsive */
@media (max-width: 1024px) {
  .split { flex-direction: column; }
  .split-right { position: static; width: 100%; }
}
@media (max-width: 760px) {
  .content { padding: 66px 14px 40px; }
  .sidebar {
    position: fixed; z-index: 90; left: -240px; transition: left 0.2s ease; height: 100vh;
  }
  .sidebar.open { left: 0; box-shadow: 0 0 0 100vmax rgba(0,0,0,0.4); }
  .nav-toggle {
    display: block; position: fixed; top: 12px; left: 12px; z-index: 95;
    background: var(--side-bg); color: #fff; border: 0; border-radius: 8px;
    width: 40px; height: 40px; font-size: 18px; cursor: pointer;
  }
  .row2, .row3, .field-grid { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr 1fr; }
  .page-head { flex-direction: column; }
}
@media print {
  .sidebar, .nav-toggle, .page-head .actions { display: none; }
}
