/* =========================================================================
   HABITS — modal + manage-overlay styles.

   Since the Journal & Habits merge, habits no longer own a panel: the day-by-day
   timeline (date rows + emoji buttons) lives in the Journals panel and is styled
   in journals.css (.jr-habit). What remains here is the shared chrome the habit
   logic still opens from the Journals subnav:
     • the Add / Edit / Import / Export modal (#modalContent)
     • the emoji + colour picker inside it
     • the body-level "Manage habits" overlay
   ========================================================================= */

/* =========================================================================
   HABITS PANEL (standalone tab)
   ========================================================================= */
.habits-panel{
  grid-column:1;
  grid-row:3;
  display:none;
  flex-direction:column;
  min-height:0;
  overflow:hidden;
  background:var(--bg);
}
.habits-panel.visible{
  display:flex;
}

.journal-habits-divider{display:none;}
.jr-scroll .journal-habits-divider{
  display:flex;align-items:center;gap:16px;margin:30px 0 18px;
  color:var(--text);font-size:12px;font-weight:800;
  letter-spacing:1.8px;text-transform:uppercase;
}
.jr-scroll .journal-habits-divider span{
  height:2px;flex:1;background:linear-gradient(90deg,transparent,var(--line-bright),transparent);
}
.jr-scroll .journal-habits-divider strong{
  padding:8px 14px;border:1px solid var(--line-bright);
  background:rgba(var(--text-rgb),.055);font:inherit;color:inherit;
}
.jr-scroll .habits-panel.journal-habits-section{
  grid-column:auto;grid-row:auto;display:flex;
  overflow:visible;min-height:auto;background:transparent;
}
.jr-scroll .journal-habits-section .habits-panel-header{
  background:var(--card);border:1px solid var(--line);
  border-radius:var(--r-lg);margin-bottom:12px;
}
.jr-scroll .journal-habits-section .habits-panel-body{
  overflow:visible;padding:0;gap:18px;
}

.habits-panel-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:16px 24px;
  border-bottom:1px solid var(--line);
  flex:0 0 auto;
  background:var(--panel);
}
.habits-panel-label{
  font-size:16px;
  font-weight:var(--fw-b);
  color:var(--text);
  letter-spacing:.2px;
}
.habits-panel-actions{
  display:flex;
  gap:8px;
  align-items:center;
}

.habits-panel-body{
  flex:1;
  min-height:0;
  overflow-y:auto;
  padding:24px;
  display:flex;
  flex-direction:column;
  gap:24px;
}

/* ---- Empty state ---- */
.hp-empty{
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:8px;
  flex:1;
  min-height:200px;
  color:var(--faint);
  font-size:14px;
  text-align:center;
}
.hp-empty p{ margin:0; }
.hp-empty strong{ color:var(--muted); }

/* ---- Section ---- */
.hp-section{
  display:flex;
  flex-direction:column;
  gap:10px;
}
.hp-section-head{
  display:flex;
  align-items:center;
  gap:8px;
  padding-bottom:8px;
  border-bottom:1px solid var(--line);
}
.hp-section-icon{
  font-size:16px;
  line-height:1;
}
.hp-section-label{
  font-size:var(--fs-label,11px);
  font-weight:var(--fw-b);
  text-transform:uppercase;
  letter-spacing:.8px;
  color:var(--muted);
  flex:1;
}
.hp-section-count{
  font-size:12px;
  color:var(--faint);
  font-variant-numeric:tabular-nums;
}

/* ---- Habit rows ---- */
.hp-habits-list{
  display:flex;
  flex-direction:column;
  gap:8px;
}
.hp-habit-row{
  display:flex;
  align-items:center;
  gap:12px;
  padding:12px 14px;
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--r-md);
  transition:border-color var(--t-base) var(--ease),background var(--t-base) var(--ease);
}
.hp-habit-row:hover{
  border-color:var(--line-bright);
  background:var(--card-hover);
}
.hp-habit-row.hp-done{
  opacity:1;
  box-shadow:inset 2px 0 0 var(--accent);
}
.hp-habit-row.hp-done .hp-habit-name{
  color:var(--muted);
  text-decoration:line-through;
  text-decoration-color:rgba(var(--accent-rgb),.5);
}
.hp-habit-row.hp-done .hp-streak{
  color:var(--faint);
}
.hp-habit-emoji{
  width:40px;
  height:40px;
  border-radius:var(--r-md);
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:20px;
  flex:0 0 auto;
  border:1px solid rgba(255,255,255,.1);
}
.hp-habit-info{
  flex:1;
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:2px;
}
.hp-habit-name{
  font-size:14px;
  font-weight:var(--fw-sb);
  color:var(--text);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.hp-streak{
  font-size:12px;
  color:var(--muted);
}

/* ---- Per-row actions (edit / delete / done), optimised for quick editing ---- */
.hp-habit-actions{
  display:flex;
  align-items:center;
  gap:8px;
  flex:0 0 auto;
}
.hp-icon-btn{
  width:32px;
  height:32px;
  border-radius:50%;
  border:1px solid var(--line);
  background:transparent;
  color:var(--muted);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  transition:border-color var(--t-base) var(--ease),color var(--t-base) var(--ease),background var(--t-base) var(--ease);
}
.hp-icon-btn svg{ width:15px; height:15px; }
.hp-icon-btn:hover{
  border-color:var(--line-bright);
  color:var(--text);
  background:var(--card-hover);
}
.hp-icon-danger:hover{
  border-color:var(--danger);
  color:var(--danger);
  background:rgba(var(--danger-rgb),.1);
}

/* ---- Done button ---- */
.hp-done-btn{
  width:36px;
  height:36px;
  border-radius:50%;
  border:2px solid var(--line);
  background:transparent;
  color:var(--faint);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  flex:0 0 auto;
  transition:all var(--t-snap) var(--ease);
}
.hp-done-btn svg{
  width:18px;
  height:18px;
}
.hp-done-btn:hover{
  border-color:var(--line-bright);
  color:var(--text);
  transform:scale(1.08);
}
.hp-done-btn-checked{
  border-color:var(--accent);
  background:var(--accent);
  color:#fff;
  box-shadow:var(--glow-accent);
}
.hp-done-btn-checked:hover{
  opacity:.85;
  transform:scale(1.05);
}

/* ---- Category type picker (Add / Edit modal) ---- */
.hb-type-row{
  display:flex;
  gap:8px;
}
.hb-type-btn{
  flex:1;
  padding:9px 6px;
  font-size:13px;
  font-weight:var(--fw-sb);
  border-radius:var(--r-md);
  border:1px solid var(--line);
  background:var(--card);
  color:var(--muted);
  cursor:pointer;
  transition:all var(--t-base) var(--ease);
  text-align:center;
}
.hb-type-btn:hover{
  border-color:var(--line-bright);
  color:var(--text);
}
.hb-type-btn.active{
  border-color:var(--accent);
  background:rgba(var(--accent-rgb),.14);
  color:var(--accent-soft,var(--accent));
}

/* ---------- Buttons (modal footers + manage list) ---------- */
.habits-btn{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:10px 16px;
  font-size:13px;
  font-weight:var(--fw-sb);
  border-radius:var(--r-md);
  cursor:pointer;
  transition:transform var(--t-snap) var(--ease),background var(--t-base) var(--ease),box-shadow var(--t-base) var(--ease);
  background:var(--card);
  color:var(--muted);
  border:1px solid var(--line);
}

.habits-btn:active{
  transform:scale(.97);
}

.habits-btn svg{
  width:16px;
  height:16px;
}

.habits-btn-primary{
  background:var(--accent);
  color:#fff;
  box-shadow:var(--glow-accent);
  border:none;
}

.habits-btn-primary:hover{
  box-shadow:var(--glow-accent);
  transform:translateY(-1px);
}

.habits-empty{
  padding:40px 20px;
  text-align:center;
  color:var(--faint);
  font-size:14px;
}

/* ============ Modal Styles ============ */
.habit-modal{
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:var(--r-lg);
  width:420px;
  max-width:90vw;
  box-shadow:var(--sh-3);
  display:flex;
  flex-direction:column;
  overflow:hidden;
}

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

.habit-modal-header h3{
  margin:0;
  font-size:18px;
  font-weight:var(--fw-b);
  color:var(--text);
  letter-spacing:.2px;
}

.modal-close{
  width:32px;
  height:32px;
  border-radius:var(--r-md);
  border:1px solid var(--line);
  background:var(--card);
  color:var(--muted);
  cursor:pointer;
  font-size:24px;
  display:flex;
  align-items:center;
  justify-content:center;
  transition:all var(--t-base) var(--ease);
}

.modal-close:hover{
  border-color:var(--line-bright);
  color:var(--text);
  background:var(--card-hover);
}

.habit-modal-body{
  padding:24px;
  display:flex;
  flex-direction:column;
  gap:18px;
}

.habit-form-group{
  display:flex;
  flex-direction:column;
  gap:6px;
}

.habit-form-group label{
  font-size:var(--fs-label);
  color:var(--muted);
  font-weight:var(--fw-sb);
  text-transform:uppercase;
  letter-spacing:.6px;
}

.habit-form-group input,
.habit-form-group textarea,
.habit-form-group select{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:var(--r-md);
  color:var(--text);
  padding:12px 14px;
  font-size:14px;
  transition:all var(--t-base) var(--ease);
}

.habit-form-group input:focus,
.habit-form-group textarea:focus,
.habit-form-group select:focus{
  border-color:var(--accent);
  outline:none;
  box-shadow:0 0 0 3px rgba(var(--accent-rgb),.16);
}

.habit-form-group input::placeholder,
.habit-form-group textarea::placeholder{
  color:var(--faint);
}

.habit-form-group textarea{
  resize:vertical;
  min-height:80px;
}

.habit-form-group select{
  cursor:pointer;
}

.import-note{
  font-size:12px;
  color:var(--faint);
  line-height:1.5;
}

.import-note p{
  margin:0;
}

.habit-modal-footer{
  display:flex;
  justify-content:flex-end;
  gap:12px;
  padding:20px 24px;
  border-top:1px solid var(--line);
  background:var(--panel-2);
}

.habit-modal-footer .habits-btn{
  padding:10px 16px;
  font-size:13px;
}

.habit-modal-footer .habits-btn:first-child{
  background:var(--card);
  color:var(--muted);
  border:1px solid var(--line);
}

.habit-modal-footer .habits-btn:first-child:hover{
  border-color:var(--line-bright);
  color:var(--text);
  background:var(--card-hover);
}

/* The shared #modalContent .modal has its own 26px padding for simple text
   modals. The habit modal ships its own header/body/footer chrome, so strip
   the shared padding whenever a habit modal is the active content. */
.modal:has(> .habit-modal){padding:0;background:transparent;border:none;box-shadow:none;max-width:none;width:auto;}
.modal:has(> .habit-modal) .habit-modal{max-width:460px;}

/* =========================================================================
   EMOJI + COLOUR PICKER (Add/Edit modal)
   ========================================================================= */
.hb-picker-group{margin-bottom:2px;}
.hb-picker{
  display:flex;align-items:flex-start;gap:12px;
  background:var(--bg);border:1px solid var(--line);border-radius:var(--r-md);padding:12px;
}
.hb-preview{
  flex:0 0 auto;width:46px;height:46px;border-radius:var(--r-md);
  display:flex;align-items:center;justify-content:center;font-size:24px;
  color:#fff;border:1px solid rgba(255,255,255,.14);
}
.hb-picker-right{flex:1;min-width:0;display:flex;flex-direction:column;gap:10px;}

.hb-emoji-row{display:flex;align-items:center;gap:5px;flex-wrap:wrap;}
.hb-emoji-pick{
  width:30px;height:30px;border-radius:var(--r-sm);border:1px solid var(--line);
  background:var(--card);font-size:15px;line-height:1;cursor:pointer;display:flex;align-items:center;justify-content:center;
  padding:0;transition:border-color var(--t-base) var(--ease),background var(--t-base) var(--ease);
}
.hb-emoji-pick:hover{border-color:var(--line-bright);background:var(--card-hover);}
.hb-emoji-pick.on{border-color:var(--accent);background:rgba(var(--accent-rgb),.16);}
.hb-emoji-input{
  width:42px;height:30px;text-align:center;font-size:15px;
  background:var(--card);border:1px solid var(--line);border-radius:var(--r-sm);color:var(--text);
  padding:0;outline:none;
}
.hb-emoji-input:focus{border-color:var(--accent);}

.hb-color-row{display:flex;align-items:center;gap:6px;flex-wrap:wrap;}
.hb-swatch{
  width:22px;height:22px;border-radius:50%;border:2px solid transparent;cursor:pointer;padding:0;
  background-clip:padding-box;transition:transform var(--t-snap) var(--ease);
}
.hb-swatch:hover{transform:scale(1.15);}
.hb-swatch.on{border-color:#fff;box-shadow:0 0 0 2px rgba(0,0,0,.25);}
.hb-color-custom{
  width:24px;height:24px;border-radius:50%;border:1px dashed var(--line);
  display:inline-flex;align-items:center;justify-content:center;cursor:pointer;overflow:hidden;
}
.hb-color-custom input{width:24px;height:24px;border:none;padding:0;cursor:pointer;background:transparent;}

@media (max-width:768px){
  .habit-modal{
    width:90vw;
    max-width:420px;
  }
}

/* =========================================================================
   HABITS MANAGEMENT MENU (body-level overlay)
   ========================================================================= */
.habits-management-menu {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-3);
  width: 500px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 1001;
  display: flex;
  flex-direction: column;
}

.habits-management-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.habits-management-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: var(--fw-b);
  color: var(--text);
}

.habits-management-list {
  padding: 16px;
  overflow-y: auto;
}

.habits-management-items {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.habits-management-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  transition: all var(--t-base) var(--ease);
}

.habits-management-item:hover {
  background: var(--card-hover);
  border-color: var(--line-bright);
}

.habits-management-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.habits-management-emoji {
  font-size: 18px;
}

.habits-management-name {
  font-weight: var(--fw-sb);
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habits-management-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.habits-btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

.habits-btn-danger {
  border-color: var(--danger);
  color: var(--danger);
}

.habits-btn-danger:hover {
  background: rgba(var(--danger-rgb), 0.1);
  color: var(--danger);
  border-color: var(--danger);
}
