/* ============================================================
   Sổ Thời Gian — giao diện "dụng cụ đo"
   Bảng màu: giấy kỹ thuật xám lạnh + mực than + kim đỏ chronograph
   ============================================================ */

:root {
  --paper:    #EEF0EC;  /* nền — giấy kỹ thuật xám xanh nhạt */
  --surface:  #FBFCF9;  /* mặt thẻ */
  --ink:      #1B201E;  /* mực chính */
  --ink-2:    #5C645F;  /* mực phụ / nhãn */
  --hairline: #C7CCC4;  /* đường kẻ mảnh */
  --needle:   #C2371F;  /* kim đỏ — đang chạy / vượt giờ */
  --gauge:    #23615A;  /* xanh thạch — phần đã hoàn thành */
  --gauge-soft:#DDE6E1;
  --mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- chữ số & nhãn ---------- */
.readout, .digits, input[type=number] {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.label {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin: 0;
}
.wordmark {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.32em;
  color: var(--ink);
}

/* ---------- màn đăng nhập / thiết lập ---------- */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-top: 3px solid var(--ink);
  padding: 28px 24px 24px;
}
.gate-card h1 { font-size: 20px; margin: 18px 0 6px; }
.gate-card p { color: var(--ink-2); font-size: 14px; margin: 0 0 18px; }
.gate-card label { display: block; font-size: 13px; color: var(--ink-2); margin: 14px 0 4px; }
.gate-card input {
  width: 100%;
  font-size: 17px;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: #fff;
}
.gate-card button { width: 100%; margin-top: 20px; }
.form-error { color: var(--needle); font-size: 14px; margin-top: 12px; }

/* ---------- thanh trên & thống kê ngày ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) 20px 12px;
}
.daily {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  align-items: stretch;
  margin: 4px 16px 20px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-top: 3px solid var(--ink);
}
.daily-cell {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.daily-rule { background: var(--hairline); }
.daily .readout { font-size: 30px; font-weight: 500; line-height: 1; }

/* ---------- danh sách công việc ---------- */
.tasks { padding: 0 16px; display: grid; gap: 16px; }

.task {
  background: var(--surface);
  border: 1px solid var(--hairline);
  padding: 16px 16px 18px;
}
.task.running { border-left: 3px solid var(--needle); }
.task.closed { opacity: 0.62; }

.task-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.task-name { font-size: 16px; font-weight: 600; margin: 0; overflow-wrap: anywhere; }
.task-meta { font-size: 12px; color: var(--ink-2); white-space: nowrap; }

.task-main {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.remaining {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 42px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.01em;
}
.remaining.over { color: var(--needle); }
.remaining-label { font-size: 12px; color: var(--ink-2); }

/* thước đo tiến độ: vạch chia như thước kẻ */
.ruler {
  position: relative;
  height: 22px;
  margin-top: 12px;
  border: 1px solid var(--hairline);
  background:
    repeating-linear-gradient(to right,
      var(--hairline) 0, var(--hairline) 1px, transparent 1px, transparent 10%),
    var(--gauge-soft);
}
.ruler-fill {
  position: absolute; inset: 0 auto 0 0;
  background: var(--gauge);
  max-width: 100%;
}
.ruler-fill.over { background: var(--needle); }
.ruler-pct {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  font-family: var(--mono); font-size: 11px; color: var(--ink-2);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  padding: 0 3px;
}

.task-sub {
  display: flex; gap: 16px; flex-wrap: wrap;
  margin-top: 10px;
  font-size: 13px; color: var(--ink-2);
}
.task-sub .digits { color: var(--ink); }

/* phiên đang chạy */
.session {
  margin-top: 14px;
  border-top: 1px dashed var(--hairline);
  padding-top: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.session-clock { font-size: 30px; }
.session-clock .digits { font-size: inherit; }
.pulse {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--needle);
  animation: pulse 1.6s ease-in-out infinite;
  flex: none;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

.mode-tag {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: 1px solid var(--hairline);
  padding: 3px 7px;
  color: var(--ink-2);
}
.mode-tag.deep { border-color: var(--ink); color: var(--ink); font-weight: 700; }
.mode-tag.pomo-break { border-color: var(--gauge); color: var(--gauge); }

.session-phase { font-size: 13px; color: var(--ink-2); }

/* nút */
.btn {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 4px;
  border: 1px solid var(--ink);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-stop { border-color: var(--needle); color: var(--needle); }
.btn-ghost { border-color: transparent; color: var(--ink-2); background: transparent; }
.btn-small { font-size: 13px; padding: 6px 10px; }
.btn:focus-visible { outline: 2px solid var(--gauge); outline-offset: 2px; }
.btn[disabled] { opacity: 0.5; cursor: default; }

.task-actions {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* bảng chọn chế độ trước khi bắt đầu */
.modepick {
  margin-top: 14px;
  border-top: 1px dashed var(--hairline);
  padding-top: 12px;
}
.modepick-row { display: flex; gap: 8px; flex-wrap: wrap; }
.modebtn {
  flex: 1 1 90px;
  border: 1px solid var(--hairline);
  background: #fff;
  padding: 10px 8px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.modebtn small { display: block; font-weight: 400; font-size: 11px; color: var(--ink-2); margin-top: 2px; }
.modebtn.selected { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.modebtn.selected small { color: var(--hairline); }

.pomo-config {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.pomo-config label { font-size: 11px; color: var(--ink-2); display: block; }
.pomo-config input {
  width: 100%;
  font-size: 16px;
  padding: 6px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  text-align: center;
}
.modepick-actions { display: flex; gap: 10px; margin-top: 12px; }

/* lịch sử */
.history-toggle { margin-top: 10px; font-size: 13px; color: var(--ink-2); background: none; border: none; padding: 0; text-decoration: underline; cursor: pointer; }
.history { margin: 8px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--ink-2); }
.history li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-top: 1px dotted var(--hairline); }

/* công việc mới */
.newtask { margin: 24px 16px 40px; }
.newtask form { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.newtask input {
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: var(--surface);
}
#ntName { flex: 2 1 180px; }
#ntHours { flex: 1 1 90px; }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(27, 32, 30, 0.45);
  display: grid; place-items: center;
  padding: 24px;
  z-index: 50;
}
.modal {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-top: 3px solid var(--ink);
  padding: 20px;
}
.modal h3 { margin: 0 0 12px; font-size: 17px; }
.modal .summary-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 8px 0; border-top: 1px dotted var(--hairline);
  font-size: 14px; color: var(--ink-2);
}
.modal .summary-row .digits { font-size: 20px; color: var(--ink); }
.modal .summary-row .digits.over { color: var(--needle); }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; }
.modal input[type=number] {
  width: 100%; font-size: 18px; padding: 10px;
  border: 1px solid var(--hairline); border-radius: 4px;
  font-family: var(--mono); text-align: center;
}
.modal p { font-size: 14px; color: var(--ink-2); }

.offline-note {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--ink); color: var(--paper);
  font-size: 13px; text-align: center;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  z-index: 40;
}

.empty {
  text-align: center; color: var(--ink-2); font-size: 14px;
  padding: 32px 16px; border: 1px dashed var(--hairline);
}

@media (min-width: 700px) {
  .topbar, .daily, .tasks, .newtask { max-width: 640px; margin-left: auto; margin-right: auto; }
  .daily { margin-top: 8px; margin-bottom: 24px; }
  .remaining { font-size: 52px; }
}

/* ============================================================
   v2: ghi chú phiên, màn Tuần, cài đặt, hàng đợi offline
   ============================================================ */

.topbar-btns { display: flex; gap: 4px; }

.session-intent {
  margin-top: 8px;
  font-size: 13px;
  color: var(--ink-2);
  border-left: 2px solid var(--hairline);
  padding-left: 8px;
}
.intent-input, .outcome-input {
  width: 100%;
  margin-top: 10px;
  font-size: 15px;
  font-family: var(--sans);
  padding: 9px 11px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: #fff;
  resize: none;
}
.modal-intent { font-size: 13px; color: var(--ink-2); border-left: 2px solid var(--hairline); padding-left: 8px; }

.history-line { display: flex; justify-content: space-between; gap: 10px; }
.history li { display: block; }
.history-note { font-size: 12px; color: var(--ink-2); padding: 2px 0 2px 14px; }
.history-note.done { color: var(--gauge); }

/* ---- màn Tuần ---- */
.week-wrap { margin: -8px 16px 20px; }
.week-toggle {
  display: block; width: 100%;
  background: none; border: none;
  font-family: var(--sans); font-size: 12px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-2); padding: 6px 0; cursor: pointer;
}
.week {
  background: var(--surface);
  border: 1px solid var(--hairline);
  padding: 16px;
  display: grid; gap: 18px;
}
.week-block .label { margin-bottom: 10px; }
.legend { font-weight: 400; letter-spacing: 0; text-transform: none; margin-left: 8px; }
.lg { display: inline-block; width: 9px; height: 9px; margin: 0 3px 0 8px; vertical-align: -1px; }
.lg-total { background: var(--gauge-soft); border: 1px solid var(--hairline); }
.lg-deep { background: var(--gauge); }

.wbars {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  align-items: end;
  height: 130px;
}
.wbar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.wbar {
  width: 100%; max-width: 34px;
  min-height: 2px;
  background: var(--gauge-soft);
  border: 1px solid var(--hairline);
  border-bottom: 2px solid var(--ink);
  display: flex; flex-direction: column; justify-content: flex-end;
}
.wbar-deep { background: var(--gauge); width: 100%; }
.wbar-val { font-size: 10px; color: var(--ink-2); }
.wbar-label { font-size: 10px; color: var(--ink-2); text-transform: capitalize; }

.golden { font-size: 14px; margin: 0; }
.golden-slot { display: inline-block; border: 1px solid var(--hairline); padding: 3px 8px; margin: 0 6px 6px 0; background: #fff; }

.est-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.est-list li { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-top: 1px dotted var(--hairline); }
.over-text { color: var(--needle); }
.under-text { color: var(--gauge); }
.est-avg { font-size: 13px; color: var(--ink-2); margin: 10px 0 0; }

/* ---- cài đặt ---- */
.settings-note { font-size: 13px; color: var(--ink-2); margin: 6px 0 10px; }
.settings-note a { color: var(--gauge); }
.apikey-row { display: flex; gap: 8px; align-items: center; }
.apikey {
  font-family: var(--mono); font-size: 11px;
  background: #fff; border: 1px solid var(--hairline);
  padding: 6px 8px; word-break: break-all; flex: 1;
}
