/* Shiluvim Sign - interface styles (RTL) */
@font-face {
  font-family: "David Libre";
  src: url("../fonts/DavidLibre-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
:root {
  --ink: #16283b;
  --muted: #6b7c8f;
  --line: #e2e8f0;
  --bg: #f4f6fa;
  --card: #ffffff;
  --brand: #12324f;
  --brand-soft: #1d4666;
  --accent: #1f6feb;
  --accent-dark: #1558c0;
  --ok: #0f8a52;
  --ok-soft: #e6f5ee;
  --warn: #a86400;
  --warn-soft: #fdf3e2;
  --err: #b8342a;
  --err-soft: #fdeceb;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(16, 42, 67, 0.09);
  --shadow-sm: 0 2px 8px rgba(16, 42, 67, 0.07);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, "Noto Sans Hebrew", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.3; font-weight: 700; }
h1 { font-size: 25px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0 0 12px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; word-break: break-all; unicode-bidi: plaintext; }

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

.sidebar {
  width: 246px;
  flex: 0 0 246px;
  background: linear-gradient(180deg, #12324f 0%, #0d2438 100%);
  color: #dce6f0;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, #2f7cf6, #4fb3ff);
  display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 17px;
}
.brand-name { font-weight: 700; font-size: 15px; color: #fff; line-height: 1.2; }
.brand-sub { font-size: 11px; color: #8fa7bd; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  color: #c9d8e6; padding: 10px 12px; border-radius: 10px; font-size: 14px;
  display: flex; align-items: center; gap: 9px; text-decoration: none;
}
.nav a:hover { background: rgba(255, 255, 255, 0.08); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(47, 124, 246, 0.22); color: #fff; font-weight: 600; }
.nav-icon { width: 18px; text-align: center; opacity: 0.9; }

.sidebar-footer { margin-top: auto; font-size: 12px; color: #7f97ad; border-top: 1px solid rgba(255,255,255,.1); padding-top: 12px; }

.main { flex: 1; min-width: 0; padding: 24px 30px 60px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.page-title { display: flex; flex-direction: column; gap: 2px; }
.page-title h1 { margin: 0; }
.page-title .crumb { font-size: 12.5px; color: var(--muted); }
.title-heading { display: flex; align-items: center; gap: 8px; direction: rtl; }
.title-heading[hidden], .title-edit-form[hidden] { display: none; }
.title-pencil { flex: 0 0 30px; width: 30px; height: 30px; display: grid; place-items: center;
  border: 1px solid var(--line); background: #fff; border-radius: 7px; color: var(--muted);
  cursor: pointer; padding: 0; font-size: 21px; line-height: 1; }
.title-pencil:hover { color: var(--accent); border-color: #b6cdec; background: #eef4ff; }
.title-pencil:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.title-edit-form { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; width: 100%; }
.title-edit-form .input { flex: 1 1 220px; min-width: 160px; padding: 7px 10px; }
.title-editor [data-title-status][data-state="error"] { color: var(--err); }
.title-editor [data-title-status][data-state="saved"] { color: var(--ok); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------------- cards ---------------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 20px; margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-flat { box-shadow: none; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1080px) { .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 18px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 27px; font-weight: 800; margin-top: 4px; letter-spacing: -0.5px; }
.stat .hint { font-size: 12px; color: var(--muted); }
.stat.accent { border-color: #cfe0fd; background: linear-gradient(180deg, #f3f8ff, #fff); }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 16px; border-radius: 10px; font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, transform .05s;
  font-family: inherit;
}
.btn:hover { background: #f6f8fc; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-dark { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-dark:hover { background: var(--brand-soft); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { filter: brightness(0.94); }
.btn-danger { color: var(--err); border-color: #f5cdc9; background: #fff; }
.btn-danger:hover { color: #96261d; background: var(--err-soft); border-color: #e8aaa4; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #eef2f8; color: var(--ink); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------------- forms ---------------- */
.field { margin-bottom: 14px; }
.field label, .label-text { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #cfd9e4; border-radius: 10px;
  font-size: 14.5px; font-family: inherit; background: #fff; color: var(--ink);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.14);
}
.textarea { min-height: 82px; resize: vertical; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.checkline { display: flex; align-items: flex-start; gap: 9px; font-size: 14px; }
.checkline input { margin-top: 4px; }

/* ---------------- tables ---------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 11px 10px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: #fafcff; }
table.data tbody tr:hover { background: #f9fbff; }
table.data td.actions { text-align: left; white-space: nowrap; }
table.data td.actions form { display: inline-block; margin: 0; }

/* ---------------- badges ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; background: #eef2f8; color: #43566b;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.draft { background: var(--warn-soft); color: var(--warn); }
.badge.archived { background: #eef0f3; color: #6b7c8f; }
.badge.err { background: var(--err-soft); color: var(--err); }

/* ---------------- alerts ---------------- */
.flash-stack { display: flex; flex-direction: column; gap: 9px; margin-bottom: 16px; }
.alert { padding: 11px 14px; border-radius: 11px; font-size: 14px; border: 1px solid transparent; }
.alert-success { background: var(--ok-soft); border-color: #bfe6d4; color: #0b6b40; }
.alert-error { background: var(--err-soft); border-color: #f5cdc9; color: #96261d; }
.alert-info { background: #eef4ff; border-color: #cfe0fd; color: #17457e; }

/* ---------------- empty state ---------------- */
.empty { text-align: center; padding: 46px 16px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 8px; opacity: .5; }

/* ---------------- login ---------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 80% -10%, #dbe9fb 0%, #f4f6fa 55%); }
.login-card { width: 100%; max-width: 396px; background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 30px 28px; }
.login-card .brand { justify-content: center; margin-bottom: 18px; }
.login-card .brand-name { color: var(--ink); }
.login-card .brand-sub { color: var(--muted); }

/* ---------------- form builder / editor ---------------- */
.builder { display: grid; grid-template-columns: 300px 1fr; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .builder { grid-template-columns: 1fr; } }

.toolbox { position: sticky; top: 16px; }
.kind-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kind-btn {
  display: flex; align-items: center; gap: 7px; justify-content: center;
  padding: 9px 8px; border: 1px solid var(--line); background: #fff; border-radius: 10px;
  font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; color: var(--ink);
}
.kind-btn:hover { background: #f5f9ff; border-color: #c9dcf7; }
.kind-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.field-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow: auto; }
.field-row { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fbfdff; }
.field-row.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(31,111,235,.14); }
.field-row .row-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field-row .kind-name { font-size: 12.5px; font-weight: 700; color: var(--brand); }
.field-row .row-body { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-top: 6px; align-items: center; }
.field-row input[type=text] { padding: 5px 8px; font-size: 12.5px; border: 1px solid #d7e0ea; border-radius: 7px; width: 100%; font-family: inherit; }
.alignment-controls { display: flex; justify-content: flex-end; gap: 5px; margin-top: 8px; direction: ltr; }
.alignment-btn { display: grid; place-items: center; width: 32px; height: 30px; padding: 5px;
  background: #fff; border: 1px solid #d7e0ea; border-radius: 6px; color: #536476; cursor: pointer; }
.alignment-btn:hover { background: #eef4ff; border-color: #b6cdec; }
.alignment-btn.active { color: var(--accent); background: #eef4ff; border-color: var(--accent); }
.alignment-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.alignment-icon { display: flex; flex-direction: column; justify-content: center; gap: 3px; width: 18px; height: 18px; }
.alignment-icon span { display: block; width: 100%; height: 2px; background: currentColor; border-radius: 1px; }
.alignment-icon span:nth-child(even) { width: 65%; }
.alignment-icon.right { align-items: flex-end; }
.alignment-icon.center { align-items: center; }
.alignment-icon.left { align-items: flex-start; }
.icon-btn { border: none; background: transparent; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; padding: 2px 4px; border-radius: 6px; }
.icon-btn:hover { background: #f0f3f8; color: var(--err); }

.page-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.page-tab { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 13px; font-family: inherit; }
.page-tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.page-stage { background: #e9eef5; border-radius: 12px; padding: 14px; }
.page-box { position: relative; margin: 0 auto; max-width: 860px; background: #fff; box-shadow: 0 4px 16px rgba(16,42,67,.12); }
.page-box img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.page-layer { position: absolute; inset: 0; }
.page-layer.drawing { cursor: crosshair; }

.field-box {
  position: absolute; border: 2px solid rgba(31, 111, 235, 0.75);
  background: rgba(31, 111, 235, 0.10); border-radius: 4px; cursor: move;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  font-size: 11px; color: #0f3e80; font-weight: 600;
}
.field-box.signature { border-color: rgba(15, 138, 82, .8); background: rgba(15, 138, 82, .10); color: #0b6b40; }
.field-box.checkbox { border-color: rgba(168, 100, 0, .85); background: rgba(253, 243, 226, .8); color: #8a5300; }
.field-box.selected { box-shadow: 0 0 0 3px rgba(31, 111, 235, .28); border-color: var(--accent); }
.field-box .box-label { padding: 0 4px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; pointer-events: none; }
.field-box .handle {
  position: absolute; left: -6px; bottom: -6px; width: 12px; height: 12px;
  background: var(--accent); border: 2px solid #fff; border-radius: 3px; cursor: nwse-resize;
}
.field-box .remove {
  position: absolute; right: -9px; top: -9px; width: 19px; height: 19px; border-radius: 50%;
  background: #fff; border: 1px solid #d5dee8; color: var(--err); font-size: 12px;
  display: none; align-items: center; justify-content: center; cursor: pointer; line-height: 1;
}
.field-box.selected .remove { display: flex; }

/* ---------------- signing view ---------------- */
.sign-shell { max-width: 900px; margin: 0 auto; padding: 22px 16px 90px; }
.sign-header { background: linear-gradient(135deg, #12324f, #1d4e77); color: #fff; border-radius: 16px; padding: 24px 26px; margin-bottom: 18px; }
.sign-header h1 { margin: 0 0 6px; font-size: 22px; }
.sign-header p { margin: 0; color: #c8d9e8; font-size: 14px; }

.sign-page-box { position: relative; background: #fff; margin: 0 auto 18px; box-shadow: var(--shadow); border-radius: 6px; overflow: hidden; }
.sign-page-box img { display: block; width: 100%; }
.sign-layer { position: absolute; inset: 0; }

.sign-field { position: absolute; }
.sign-field textarea, .sign-field input[type=date] {
  width: 100%; height: 100%; border: 1.5px solid #9fb6cd; border-radius: 4px;
  background: rgba(255, 255, 255, .92); padding: 1px 3px;
  font-family: "David Libre", "David", serif;
  font-size: 12pt; line-height: 1.15; color: #10263b;
  direction: rtl; text-align: right;
}
.sign-field textarea { display: block; resize: none; overflow: auto; margin: 0; }
.sign-field input:focus, .sign-field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,111,235,.16); background: #fff; }
.sign-field.checkbox { display: flex; align-items: center; justify-content: center; }
.sign-field.checkbox input { width: 100%; height: 100%; margin: 0; accent-color: var(--accent); }
.sign-field .sig-btn {
  width: 100%; height: 100%; border: 1.5px dashed #1f8a5b; border-radius: 4px;
  background: rgba(230, 245, 238, .9); color: #0b6b40; font-size: 11px; font-family: inherit;
  cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0;
}
.sign-field .sig-btn:hover { background: #d8f0e4; }
.sign-field .sig-btn.done { border-style: solid; background: #fff; padding: 0; }
.sign-field .sig-btn img { max-width: 100%; max-height: 100%; object-fit: contain; }
.field-required-mark { color: var(--err); font-weight: 700; }

/* mobile helper list: same values as the overlays, easier to type on phones */
.mobile-fields { display: none; background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow-sm); }
.mobile-fields h2 { font-size: 16px; margin-bottom: 10px; }
.mobile-fields .mf-row { margin-bottom: 12px; }
.mobile-fields label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.mobile-fields .mf-sig { display: flex; align-items: center; gap: 10px; }
.mobile-fields .mf-sig img { max-height: 44px; border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; background: #fff; }
@media (max-width: 720px) {
  .mobile-fields { display: block; }
  .sign-shell { padding: 14px 10px 70px; }
  .sign-header { padding: 18px 16px; }
  .sign-header h1 { font-size: 18px; }
}

.sign-id-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 20px; box-shadow: var(--shadow-sm); }
.sign-actions { position: sticky; bottom: 0; background: rgba(255, 255, 255, .96); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; margin-top: 12px;
  display: flex; gap: 12px; justify-content: space-between; align-items: center;
  box-shadow: 0 -4px 18px rgba(16, 42, 67, .08); }

/* ---------------- signature modal ---------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(11, 27, 43, .55); display: none; align-items: center; justify-content: center; padding: 18px; z-index: 60; }
.modal-backdrop.open { display: flex; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 620px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.28); }
.modal h3 { margin-top: 0; }
.pad-wrap { border: 2px dashed #b9c9d9; border-radius: 12px; background: #fcfdff; }
#sig-canvas { width: 100%; height: 190px; display: block; touch-action: none; border-radius: 10px; }
.modal-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }

/* ---------------- misc ---------------- */
.link-box { display: flex; gap: 8px; align-items: center; background: #f7f9fd; border: 1px dashed #c6d5e5; border-radius: 10px; padding: 9px 11px; }
.link-box input { flex: 1; border: none; background: transparent; font-size: 13px; font-family: monospace; direction: ltr; color: #17457e; min-width: 0; }
.link-box input:focus { outline: none; }

.doc-preview { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #eef2f7; padding: 10px; }
.doc-preview img { display: block; width: 100%; border-radius: 6px; background: #fff; }

.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; unicode-bidi: plaintext; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-right: 2px solid #dbe5f0; padding: 0 14px 13px 0; position: relative; font-size: 13.5px; }
.timeline li::before { content: ""; position: absolute; right: -5px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: #9db4cc; }
.timeline li strong { font-weight: 700; }
.timeline .when { color: var(--muted); font-size: 12px; unicode-bidi: plaintext; }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 110px; padding-top: 8px; }
.chart .bar { flex: 1; background: linear-gradient(180deg, #4f9bff, #1f6feb); border-radius: 5px 5px 2px 2px; min-height: 3px; position: relative; }
.chart .bar span { position: absolute; bottom: -19px; right: 0; left: 0; text-align: center; font-size: 10px; color: var(--muted); }

.footer-note { text-align: center; color: var(--muted); font-size: 12px; margin-top: 26px; }

.success-mark { width: 62px; height: 62px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; font-size: 30px; margin: 0 auto 12px; }

@media print {
  .sidebar, .topbar-actions, .flash-stack { display: none !important; }
}
