:root{
  --bg1:#fff7e6;
  --bg2:#fff0f6;
  --panel:#fffdf8;
  --ink:#3e2723;
  --muted:#6d4c41;
  --accent:#ff9800;
  --accent-2:#8d6e63;
  --fact-bg:#e8f5e9;
  --law-bg:#fff3e0;
  --fixed-bg:#ffecb3;
  --fixed-border:#ffca28;
  --danger:#c62828;
  --shadow:0 10px 24px rgba(0,0,0,0.08);
  --radius:16px;
}

*{box-sizing:border-box;font-family:system-ui,-apple-system,"Segoe UI",sans-serif;}
body{
  margin:0;
  background:linear-gradient(135deg,var(--bg1),var(--bg2));
  color:var(--ink);
}

.app{
  max-width:1200px;
  margin:0 auto;
  padding:1.2rem 1.2rem 2rem;
}

.header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:1rem;
  flex-wrap:wrap;
  padding:0.6rem 0.2rem 1rem;
}

.brand{
  display:flex;
  align-items:center;
  gap:0.8rem;
}

.badge{
  width:48px;
  height:48px;
  border-radius:14px;
  background:var(--accent);
  color:white;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:700;
  box-shadow:var(--shadow);
}

h1{
  margin:0;
  font-size:1.7rem;
}
.subtitle{
  font-size:0.92rem;
  color:var(--muted);
  margin-top:0.15rem;
}

.top-actions{
  display:flex;
  gap:0.5rem;
  align-items:center;
  flex-wrap:wrap;
}

.file-btn{
  display:inline-flex;
  align-items:center;
  gap:0.35rem;
  background:var(--panel);
  border:1px solid #e0e0e0;
  padding:0.35rem 0.85rem;
  border-radius:999px;
  cursor:pointer;
  box-shadow:0 2px 6px rgba(0,0,0,0.05);
  color:var(--ink);
  font-size:0.9rem;
}
.file-btn input{display:none;}

.grid{
  display:grid;
  gap:1rem;
  grid-template-columns:1fr;
}
@media (min-width:1050px){
  .grid{grid-template-columns:1.05fr 1.35fr 1.1fr;}
}

.panel{
  background:var(--panel);
  border-radius:var(--radius);
  padding:1rem 1.05rem;
  box-shadow:var(--shadow);
}

.panel-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:0.7rem;
  flex-wrap:wrap;
}

h2{
  margin:0 0 0.6rem 0;
  font-size:1.15rem;
  color:#5d4037;
}

.field{
  display:flex;
  flex-direction:column;
  gap:0.25rem;
  margin-bottom:0.65rem;
}
label{
  font-size:0.88rem;
  color:var(--muted);
}
input[type="text"]{
  border-radius:12px;
  border:1px solid #d7ccc8;
  padding:0.55rem 0.65rem;
  font-size:0.95rem;
  background:white;
}

.hint{
  font-size:0.85rem;
  color:var(--muted);
  margin:0.35rem 0 0.7rem;
}
.hint.small{font-size:0.78rem;}

.actions-row{
  display:flex;
  gap:0.5rem;
  flex-wrap:wrap;
  margin-top:0.35rem;
}

button{
  border:none;
  border-radius:999px;
  padding:0.45rem 0.95rem;
  font-size:0.9rem;
  cursor:pointer;
  background:var(--accent-2);
  color:white;
}
button:hover{filter:brightness(0.95);}
button.primary{background:var(--accent);}
button.ghost{
  background:transparent;
  color:var(--ink);
  border:1px solid #e0e0e0;
}
button.danger{
  background:var(--danger);
}
button.wide{flex:1 1 170px;}
button.small-btn{
  padding:0.32rem 0.7rem;
  font-size:0.82rem;
}

.divider{
  height:1px;
  background:rgba(0,0,0,0.06);
  margin:0.9rem 0;
}

.kind-box{
  background:#fff8e1;
  border:1px solid #ffe0b2;
  border-radius:12px;
  padding:0.55rem 0.6rem 0.7rem;
  margin:0.6rem 0 0.2rem;
}
.kind-title{
  font-size:0.85rem;
  color:var(--muted);
  margin-bottom:0.35rem;
}
.kind-toggle{
  display:flex;
  gap:0.4rem;
  flex-wrap:wrap;
}
.kind-btn{
  background:white;
  color:var(--ink);
  border:1px solid #e0e0e0;
  flex:1 1 150px;
}
.kind-btn.active.fact{
  background:var(--fact-bg);
  border-color:#c8e6c9;
}
.kind-btn.active.law{
  background:var(--law-bg);
  border-color:#ffe0b2;
}

.law-sub-box{
  margin-top:0.5rem;
  background:#fdf5ff;
  border-radius:10px;
  border:1px dashed #e1bee7;
  padding:0.45rem 0.55rem 0.55rem;
}
.law-sub-title{
  font-size:0.82rem;
  color:var(--muted);
  margin-bottom:0.3rem;
}
.law-sub-toggle{
  display:flex;
  gap:0.35rem;
  flex-wrap:wrap;
}
.law-sub-btn{
  background:white;
  color:var(--ink);
  border:1px solid #e0e0e0;
  font-size:0.8rem;
}
.law-sub-btn.active{
  background:#f3e5f5;
  border-color:#ce93d8;
}

.relation-box{
  background:#f7f3ff;
  border:1px solid #e6ddff;
  border-radius:12px;
  padding:0.55rem 0.6rem 0.7rem;
  margin:0.4rem 0 0.5rem;
}
.relation-title{
  font-size:0.85rem;
  color:var(--muted);
  margin-bottom:0.35rem;
}
.relation-buttons{
  display:flex;
  gap:0.4rem;
  flex-wrap:wrap;
}

.pill{
  background:white;
  color:var(--ink);
  border:1px solid #e0e0e0;
  padding:0.28rem 0.75rem;
  font-size:0.83rem;
}
.pill.active{
  background:#fff3e0;
  border-color:#ffe0b2;
}

.view-switch{
  display:flex;
  gap:0.35rem;
}

.hidden{display:none !important;}

/* Fixed values */
.fixed-list{
  margin-top:0.4rem;
  display:flex;
  flex-wrap:wrap;
  gap:0.35rem;
  min-height:1.5rem;
}
.fixed-list-empty{
  font-size:0.78rem;
  color:var(--muted);
}
.fixed-pill{
  display:inline-flex;
  align-items:center;
  gap:0.3rem;
  padding:0.2rem 0.65rem;
  border-radius:999px;
  background:var(--fixed-bg);
  border:1px solid var(--fixed-border);
  font-size:0.8rem;
  cursor:pointer;
  box-shadow:0 2px 4px rgba(0,0,0,0.08);
}
.fixed-pill span{
  pointer-events:none;
}
.fixed-remove{
  border:none;
  background:transparent;
  color:#bf360c;
  font-size:0.85rem;
  padding:0;
  cursor:pointer;
}

/* Timeline */
.timeline{
  display:flex;
  flex-direction:column;
  gap:0.55rem;
  min-height:120px;
}
.node{
  position:relative;
  border-radius:12px;
  padding:0.55rem 0.7rem;
  border:1px solid #e0e0e0;
  background:white;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:0.6rem;
}
.node.fact{background:var(--fact-bg); border-color:#c8e6c9;}
.node.law{background:var(--law-bg); border-color:#ffe0b2;}
.node.fixed-use{
  box-shadow:0 0 0 2px rgba(255,202,40,0.9);
}
.node-left{
  display:flex;
  align-items:center;
  gap:0.5rem;
}
.node-id{
  width:28px;
  height:28px;
  border-radius:8px;
  background:rgba(0,0,0,0.06);
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:0.8rem;
  font-weight:600;
}
.node-text{
  font-size:1rem;
  font-weight:600;
}
.node-meta{
  font-size:0.78rem;
  color:var(--muted);
  white-space:nowrap;
}
.node-lawtag{
  font-size:0.74rem;
  color:#6a1b9a;
  margin-right:0.5rem;
}

.arrow{
  text-align:center;
  color:#8d6e63;
  font-size:1.1rem;
  margin:-0.15rem 0;
}

/* Columns */
.columns{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:0.8rem;
}
.col{
  background:white;
  border:1px solid #eee;
  border-radius:12px;
  padding:0.6rem;
}
.col-title{
  font-size:0.95rem;
  font-weight:700;
  padding:0.25rem 0.5rem;
  border-radius:10px;
  display:inline-block;
}
.col-title.law{background:var(--law-bg);}
.col-title.fact{background:var(--fact-bg);}
.col-body{
  margin-top:0.5rem;
  display:flex;
  flex-direction:column;
  gap:0.45rem;
}
.col-item{
  border-radius:10px;
  padding:0.45rem 0.55rem;
  border:1px solid #e0e0e0;
  background:#fafafa;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:0.4rem;
}
.col-item.fixed-use{
  border-color:var(--fixed-border);
  background:#fffde7;
}
.col-item small{color:var(--muted);}

/* Table */
.table-wrap{
  max-height:420px;
  overflow:auto;
  border-radius:12px;
  border:1px solid #eee;
  background:white;
}
table{
  width:100%;
  border-collapse:collapse;
}
thead th{
  position:sticky;
  top:0;
  background:#faf7f2;
  font-size:0.82rem;
  text-align:right;
  padding:0.5rem 0.45rem;
  border-bottom:1px solid #eee;
}
tbody td{
  font-size:0.9rem;
  padding:0.48rem 0.45rem;
  border-bottom:1px solid #f1f1f1;
  vertical-align:top;
}
tbody tr:hover{background:#fff8e1;}
tbody tr.fixed-use-row{
  background:#fffde7;
}
.tag{
  display:inline-flex;
  align-items:center;
  gap:0.25rem;
  padding:0.12rem 0.5rem;
  border-radius:999px;
  font-size:0.74rem;
  border:1px solid #e0e0e0;
}
.tag.fact{background:var(--fact-bg);}
.tag.law{background:var(--law-bg);}

.clickable{
  cursor:pointer;
  text-decoration:underline dotted rgba(0,0,0,0.25);
  text-underline-offset:3px;
}

.highlight{
  outline:2px solid rgba(255,152,0,0.6);
  outline-offset:2px;
}

/* Footer */
.footer{
  margin-top:1rem;
  text-align:center;
  font-size:0.78rem;
  color:var(--muted);
}


.direction-switch{
  margin-top:0.2rem;
  display:flex;
  gap:0.35rem;
  flex-wrap:wrap;
}

.retro-box{
  background:#f3e5f5;
  border-radius:12px;
  border:1px dashed #ce93d8;
  padding:0.5rem 0.6rem 0.6rem;
  margin:0.5rem 0 0.5rem;
}
.retro-title{
  font-size:0.85rem;
  color:var(--muted);
  margin-bottom:0.3rem;
}
.retro-row{
  display:flex;
  gap:0.35rem;
  flex-wrap:wrap;
  margin-bottom:0.3rem;
}

/* הדגשת "עוגן" במצב עבודה רטרואקטיבית */
.node.anchor,
.col-item.anchor{
  box-shadow:0 0 0 2px rgba(103,58,183,0.7);
}
tbody tr.anchor-row{
  background:#ede7f6;
}

/* Help overlay */
.help-btn{
  margin-inline-start:0.5rem;
}

.help-overlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,0.35);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:1000;
}

.help-overlay.hidden{
  display:none;
}

.help-modal{
  max-width:720px;
  max-height:80vh;
  overflow:auto;
  background:#fffdf8;
  border-radius:20px;
  box-shadow:0 18px 40px rgba(0,0,0,0.25);
  padding:1.4rem 1.6rem 1.6rem;
  border:1px solid #ffe0b2;
}

.help-modal h2{
  margin-top:0;
  margin-bottom:0.6rem;
  font-size:1.4rem;
}

.help-intro,
.help-outro{
  font-size:0.9rem;
  color:var(--muted);
  margin-bottom:0.8rem;
}

.help-steps{
  margin:0;
  padding-inline-start:1.2rem;
  list-style:decimal;
}

.help-steps li{
  margin-bottom:0.7rem;
}

.help-steps h3{
  margin:0 0 0.25rem 0;
  font-size:1rem;
  color:var(--ink);
}

.help-steps p{
  margin:0;
  font-size:0.9rem;
  line-height:1.5;
}

.help-close{
  position:absolute;
  top:0.4rem;
  inset-inline-start:0.7rem;
  width:28px;
  height:28px;
  border-radius:999px;
  border:none;
  background:#ffe0b2;
  color:var(--ink);
  font-size:1.2rem;
  line-height:1;
  cursor:pointer;
}
.help-close:hover{
  filter:brightness(0.95);
}

/* Interactive help steps */
.help-steps{
  margin:0;
  padding-inline-start:0;
  list-style:none;
}
.help-steps li{
  display:none;
}
.help-steps li.active{
  display:block;
}
.help-nav{
  margin-top:0.8rem;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:0.5rem;
}
.help-progress{
  font-size:0.85rem;
  color:var(--muted);
}
.help-nav button{
  min-width:80px;
}

/* Practice box */
.practice-box{
  margin-top:1.2rem;
  padding:0.9rem 1rem;
  border-radius:14px;
  background:#fffaf2;
  border:1px solid #ffe0b2;
}
.practice-intro{
  margin:0 0 0.6rem 0;
  font-size:0.9rem;
  color:var(--muted);
}
.practice-card{
  border-radius:12px;
  padding:0.8rem 0.9rem;
  background:#ffffff;
  box-shadow:0 4px 12px rgba(0,0,0,0.06);
}
.practice-row{
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-bottom:0.4rem;
  gap:0.5rem;
}
.practice-label{
  font-weight:600;
  font-size:0.9rem;
}
.practice-value{
  font-size:0.95rem;
}
.practice-buttons{
  display:flex;
  gap:0.6rem;
  margin:0.6rem 0;
}
.practice-feedback{
  min-height:1.4rem;
}
.practice-nav{
  margin-top:0.4rem;
  display:flex;
  align-items:center;
  justify-content:space-between;
}
.practice-index{
  font-size:0.85rem;
  color:var(--muted);
}

/* Live coach panel */
.coach-panel{
  margin-bottom:0.8rem;
  padding:0.7rem 0.9rem;
  border-radius:14px;
  background:#f3f7ff;
  border:1px solid #c7d7ff;
}
.coach-header{
  display:flex;
  align-items:center;
  gap:0.4rem;
  margin-bottom:0.4rem;
}
.coach-dot{
  width:10px;
  height:10px;
  border-radius:999px;
  background:#4a6bff;
  box-shadow:0 0 0 4px rgba(74,107,255,0.25);
}
.coach-title{
  font-weight:600;
  font-size:0.95rem;
}
.coach-body{
  font-size:0.9rem;
  line-height:1.5;
}
.coach-toggle{
  border-radius:999px;
}
.coach-toggle.active{
  background:#4a6bff;
  color:#fff;
}


/* ---- Clean Mode UI (v8.7-clean) ---- */
.hidden{ display:none !important; }

.clean-app{
  min-height:100vh;
  background: radial-gradient(1200px 600px at 20% 10%, rgba(255,200,120,0.25), transparent 55%),
              radial-gradient(900px 500px at 80% 0%, rgba(255,130,170,0.22), transparent 60%),
              linear-gradient(180deg, var(--bg1), var(--bg2));
  padding: 18px;
}

.clean-top{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  max-width: 980px;
  margin: 0 auto 14px auto;
}

.clean-title{
  display:flex;
  align-items:center;
  gap:12px;
}

.clean-badge{
  width:54px;
  height:54px;
  border-radius:16px;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(0,0,0,0.06);
  box-shadow: 0 10px 24px rgba(0,0,0,0.06);
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 26px;
}

.clean-h1{
  font-weight:800;
  letter-spacing: -0.2px;
  font-size: 20px;
}

.clean-sub{
  font-size: 13px;
  opacity: 0.75;
  margin-top: 2px;
}

.clean-ghost{
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 14px;
  padding: 10px 12px;
  cursor:pointer;
  font-weight:700;
  color: rgba(0,0,0,0.85);
}

.clean-main{
  max-width: 980px;
  margin: 0 auto;
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 18px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.08);
  padding: 14px;
}

.clean-chat{
  min-height: 52vh;
  max-height: 62vh;
  overflow:auto;
  padding: 8px;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.bubble{
  max-width: 86%;
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.bubble.coach{
  align-self:flex-start;
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(0,0,0,0.08);
}

.bubble.user{
  align-self:flex-end;
  background: rgba(255,245,220,0.95);
  border: 1px solid rgba(0,0,0,0.08);
}

.clean-quick{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  padding: 8px;
  border-top: 1px dashed rgba(0,0,0,0.12);
  margin-top: 6px;
}

.quick-btn{
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 999px;
  padding: 10px 12px;
  cursor:pointer;
  font-weight:700;
  color: rgba(0,0,0,0.85);
}

.quick-btn.primary{
  background: rgba(240,255,240,0.95);
}

.clean-inputbar{
  display:flex;
  gap:10px;
  padding: 8px;
  border-top: 1px solid rgba(0,0,0,0.08);
  margin-top: 6px;
  align-items:flex-end;
}

#clean-input{
  flex:1;
  color:#111;
  resize:none;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,0.12);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  background: rgba(255,255,255,0.9);
}

.clean-send{
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,0.12);
  padding: 12px 14px;
  cursor:pointer;
  font-weight:800;
  background: rgba(220,245,255,0.95);
  color: rgba(0,0,0,0.85);
}

.clean-hint{
  margin-top: 10px;
  font-size: 12px;
  opacity: 0.65;
  text-align: center;
}

.legacy-app{
  max-width: 1100px;
  margin: 0 auto;
}


/* Fix: readable button text in clean mode */
.clean-app button{ color:#111; }
.quick-btn{ color:#111; }
.clean-ghost{ color:#111; }
.clean-send{ color:#111; }

.clean-mini{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  padding: 10px 8px 2px 8px;
  opacity: 0.9;
}
.mini-pill{
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 800;
  font-size: 12px;
  color: rgba(0,0,0,0.82);
}
.mini-arrow{
  opacity:0.55;
  font-weight:900;
}

/* Clean Minimal: editable mini chain */
.clean-mini{ display:flex; flex-direction:column; gap:6px; padding: 8px 8px 2px 8px; }
.mini-hint{ font-size:12px; opacity:.75; }
.mini-row{ display:flex; flex-wrap:wrap; gap:6px; align-items:center; }
.mini-pill{
  cursor:pointer;
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 800;
  font-size: 12px;
  color: rgba(0,0,0,0.82);
}
.mini-arrow{ opacity:0.55; font-weight:900; }

.clean-ghost, .quick-btn, .clean-send { color: rgba(0,0,0,0.85) !important; }

/* Edit modal */
.edit-modal{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 16px;
  z-index: 9999;
}
.edit-card{
  width: min(520px, 96vw);
  background: rgba(255,255,255,0.95);
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 18px;
  box-shadow: 0 18px 42px rgba(0,0,0,0.18);
  padding: 14px;
}
.edit-title{ font-weight: 900; font-size: 16px; }
.edit-sub{ opacity: .75; font-size: 12px; margin-top: 4px; }
.edit-input{
  width: 100%;
  margin-top: 10px;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,0.16);
  padding: 10px 12px;
  font-size: 14px;
}
.edit-actions{
  margin-top: 12px;
  display:flex;
  justify-content:flex-end;
  gap: 10px;
}
.edit-btn{
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,0.14);
  padding: 10px 12px;
  cursor:pointer;
  font-weight: 900;
  background: rgba(220,245,255,0.95);
  color: rgba(0,0,0,0.86);
}
.edit-btn.ghost{
  background: rgba(255,255,255,0.85);
}

.edit-row-btn{
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.14);
  padding: 6px 10px;
  cursor:pointer;
  font-weight: 800;
  background: rgba(255,255,255,0.85);
  color: rgba(0,0,0,0.85);
}
