*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:         #7c3aed;
  --primary-hover:   #6d28d9;
  --primary-light:   #ede9fe;
  --secondary:       #db2777;
  --secondary-light: #fce7f3;
  --bg:              #f8f7ff;
  --surface:         #ffffff;
  --border:          #e5e7eb;
  --text:            #1a1625;
  --text-muted:      #6b7280;
  --shadow-lg:       0 8px 32px rgba(124,58,237,0.12), 0 2px 8px rgba(0,0,0,0.06);
  --radius:          8px;
  --radius-lg:       14px;
  --t:               0.15s ease;
}

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Login ── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-icon {
  width: 52px;
  height: 52px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin: 0 auto 16px;
}

.login-card h1 { font-size: 20px; font-weight: 700; margin-bottom: 24px; }

#login-form { display: flex; flex-direction: column; gap: 10px; }

#login-form input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color var(--t), box-shadow var(--t);
}

#login-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.08);
}

#login-form button {
  padding: 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--t), transform var(--t);
}

#login-form button:hover  { background: var(--primary-hover); }
#login-form button:active { transform: scale(0.98); }

.error { color: var(--secondary); font-size: 13px; min-height: 18px; margin-top: 4px; }

/* ── App ── */
#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
}

.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  padding: 6px 11px;
  font-size: 14px;
  transition: background var(--t), color var(--t), border-color var(--t), transform var(--t);
}

.icon-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: #c4b5fd;
}

.icon-btn:active { transform: scale(0.94); }

/* ── Main / Matrix ── */
main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: hidden;
}

.matrix {
  width: 100%;
  max-width: 750px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 10px;
}

/* ── Block ── */
.block-field { position: relative; }

.block-input {
  width: 100%;
  padding: 16px 60px 16px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}

.block-input::placeholder { color: #d8b4fe; font-weight: 400; }

.block-input:hover {
  border-color: #a78bfa;
  background: #faf9ff;
}

.block-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.08);
  background: var(--surface);
}

.block-input.stale-1 { border-color: #f59e0b; }
.block-input.stale-1:hover { border-color: #d97706; }

.block-input.stale-2 { border-color: #dc2626; color: #dc2626; }
.block-input.stale-2:hover { border-color: #b91c1c; }
.block-input.stale-2:focus { color: var(--text); }

.block-check,
.block-detail {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: none;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  color: #a78bfa;
  transition: background var(--t), color var(--t);
}

.block-check  { right: 30px; }
.block-detail { right: 4px; }

.block-input:focus ~ .block-check,
.block-input:focus ~ .block-detail { display: flex; }

.block-check:hover  { background: #dcfce7; color: #16a34a; }
.block-detail:hover { background: var(--primary-light); color: var(--primary); }

/* ── Backdrop ── */
#panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(26,22,37,0.06);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  cursor: pointer;
}

/* ── History Panel ── */
#history-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 50;
  box-shadow: -4px 0 24px rgba(124,58,237,0.1);
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { transform: translateX(16px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Panel top bar (filter + close) ── */
.panel-top {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-filter { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }

.filter-btn {
  padding: 4px 10px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  transition: background var(--t), color var(--t), border-color var(--t);
}

.filter-btn:hover { border-color: #c4b5fd; color: var(--primary); }
.filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

#close-panel-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 15px;
  padding: 6px 8px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: color var(--t), background var(--t);
}

#close-panel-btn:hover { color: var(--primary); background: var(--primary-light); }

#history-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  scrollbar-width: thin;
  scrollbar-color: #c4b5fd transparent;
}

.panel-empty { color: var(--text-muted); font-size: 13px; padding: 12px 4px; }

/* ── History Entry ── */
.history-entry {
  border-radius: var(--radius);
  margin-bottom: 6px;
  border: 1.5px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--t), box-shadow var(--t);
}

.history-entry:hover {
  border-color: #c4b5fd;
  box-shadow: 0 2px 8px rgba(124,58,237,0.08);
}

.he-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  user-select: none;
}

.he-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.he-badge i { font-size: 8px; }

.he-badge.l1 { background: #fef9c3; color: #92640a; }
.he-badge.l2 { background: #f1f5f9; color: #64748b; }
.he-badge.l3 { background: #fdf0e7; color: #9a4e1c; }

.he-value {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.he-duration {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  font-weight: 600;
}

.he-details {
  border-top: 1.5px solid var(--border);
  padding: 10px 10px 12px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: expandIn 0.15s ease;
}

@keyframes expandIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.he-dates { color: var(--text-muted); font-size: 12px; display: flex; flex-direction: column; gap: 2px; line-height: 1.6; }
.he-dates span { color: var(--text); font-weight: 600; }

.he-notes {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 12px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

.he-ctx { border-top: 1px solid var(--border); padding-top: 7px; display: flex; flex-direction: column; gap: 4px; }

.he-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  margin-top: 2px;
}

.he-allinfo {
  padding: 4px 9px;
  border: 1.5px solid #c4b5fd;
  border-radius: 6px;
  background: transparent;
  color: var(--primary);
  font-size: 11px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background var(--t), border-color var(--t);
}

.he-allinfo:hover { background: var(--primary-light); }

.he-delete {
  padding: 4px 9px;
  border: 1.5px solid #fecdd3;
  border-radius: 6px;
  background: transparent;
  color: var(--secondary);
  font-size: 11px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background var(--t), border-color var(--t);
}

.he-delete:hover { background: #fff1f2; border-color: var(--secondary); }

.he-ctx-item { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 11px; }
.he-ctx-item span:first-child { color: var(--text-muted); flex-shrink: 0; }
.he-ctx-item span:last-child  { color: var(--text); font-weight: 600; text-align: right; overflow: hidden; text-overflow: ellipsis; }

/* ── Settings button ── */
#settings-btn {
  position: fixed;
  bottom: 18px;
  right: 18px;
  width: 30px;
  height: 30px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  opacity: 0.35;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  transition: opacity var(--t), color var(--t), background var(--t);
  z-index: 30;
}

#settings-btn:hover { opacity: 1; color: var(--primary); background: var(--primary-light); }

/* ── Settings panel ── */
#settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 50;
  box-shadow: -4px 0 24px rgba(124,58,237,0.1);
  animation: slideIn 0.2s ease;
}

#settings-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 15px;
  padding: 6px 8px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: color var(--t), background var(--t);
}

#settings-close-btn:hover { color: var(--primary); background: var(--primary-light); }

.settings-body { padding: 16px; flex: 1; display: flex; flex-direction: column; }
.settings-section { display: flex; flex-direction: column; gap: 10px; }
.settings-danger { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.settings-desc { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

/* ── Filter Panel ── */
#filter-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 60;
  box-shadow: -6px 0 32px rgba(124,58,237,0.18), -2px 0 8px rgba(0,0,0,0.08);
  animation: slideIn 0.2s ease;
}

.fp-title { flex: 1; font-size: 14px; font-weight: 700; color: var(--text); }

#filter-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 15px;
  padding: 6px 8px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: color var(--t), background var(--t);
}

#filter-close-btn:hover { color: var(--primary); background: var(--primary-light); }

#filter-panel-body {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #c4b5fd transparent;
}

.fp-section { padding: 14px; border-bottom: 1px solid var(--border); }

.fp-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.fp-group { display: flex; flex-wrap: wrap; gap: 6px; }

.fp-btn {
  padding: 5px 12px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  transition: background var(--t), color var(--t), border-color var(--t);
}

.fp-btn:hover { border-color: #c4b5fd; color: var(--primary); }
.fp-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.fp-search {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color var(--t), box-shadow var(--t);
}

.fp-search:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.08);
}

.fp-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-shrink: 0;
}

#filter-panel-btn.has-filters {
  background: var(--primary-light);
  color: var(--primary);
  border-color: #c4b5fd;
}

/* ── Info Panel ── */
#info-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 60;
  box-shadow: -6px 0 32px rgba(124,58,237,0.18), -2px 0 8px rgba(0,0,0,0.08);
  animation: slideIn 0.2s ease;
}

#history-panel.has-info-panel {
  transform: translateX(-16px);
  transition: transform 0.2s ease;
}

#info-panel .panel-top { justify-content: flex-end; }

#info-close-panel-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 15px;
  padding: 6px 8px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: color var(--t), background var(--t);
}

#info-close-panel-btn:hover { color: var(--primary); background: var(--primary-light); }

#info-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  scrollbar-width: thin;
  scrollbar-color: #c4b5fd transparent;
}

.info-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.info-title {
  font-size: 15px;
  font-weight: 700;
  flex: 1;
  line-height: 1.4;
  color: var(--text);
}

.info-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.info-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.info-subitem {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

.info-subitem:last-child { border-bottom: none; }

.info-subitem-icon { color: var(--text-muted); width: 14px; flex-shrink: 0; font-size: 10px; }
.info-subitem-value { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info-subitem-dur { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }

/* ── Notes Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,22,37,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--border);
  animation: modalIn 0.15s ease;
}

@keyframes modalIn {
  from { transform: scale(0.97) translateY(6px); opacity: 0; }
  to   { transform: scale(1)    translateY(0);   opacity: 1; }
}

.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-header span { font-size: 15px; font-weight: 700; }

.modal-header .icon-btn { border: none; color: var(--text-muted); }
.modal-header .icon-btn:hover { background: var(--primary-light); color: var(--primary); border: none; }

#modal-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  outline: none;
  resize: vertical;
  min-height: 140px;
  line-height: 1.7;
  transition: border-color var(--t), box-shadow var(--t);
}

#modal-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.08);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.modal-footer-right { display: flex; gap: 8px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--t), color var(--t), border-color var(--t), transform var(--t);
}

.btn:active { transform: scale(0.97); }

.btn--primary {
  background: var(--primary);
  color: #fff;
  border: none;
}

.btn--primary:hover { background: var(--primary-hover); }

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}

.btn--ghost:hover { background: var(--primary-light); color: var(--primary); border-color: #c4b5fd; }

.btn--danger {
  background: transparent;
  color: var(--secondary);
  border: 1.5px solid #fecdd3;
}

.btn--danger:hover { background: #fff1f2; border-color: var(--secondary); }

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Mobile ── */
@media (max-width: 540px) {
  main { padding: 16px 12px; }
  .matrix {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .matrix .block:nth-child(4),
  .matrix .block:nth-child(7) { margin-top: 14px; }
  .block-input { font-size: 13px; padding: 14px 30px 14px 10px; }
  #history-panel { width: 100vw; }
  #settings-panel { width: 100vw; }
  #filter-panel { width: 100vw; }
  #info-panel { width: 100vw; }
  .login-card { padding: 28px 20px; }
  .topbar { padding: 8px 14px; }
}
