/* ============================================================
   Thesis Tracker — "The Manuscript"
   Warm paper, editorial serif, ledger-like tables.
   Chart colors follow the validated dataviz reference palette.
   ============================================================ */

:root {
  /* paper & ink */
  --paper:        #f6f3ea;
  --paper-deep:   #efeadc;
  --card:         #fcfcfb;   /* chart surface (palette-validated) */
  --ink:          #1c1a15;
  --ink-2:        #52514e;
  --ink-muted:    #898781;
  --hairline:     #e1e0d9;
  --baseline:     #c3c2b7;
  --ring:         rgba(11,11,11,0.10);

  /* data */
  --series-1:     #2a78d6;   /* actual progress line */
  --seq-100:      #cde2fb;   /* heatmap ramp */
  --seq-200:      #9ec5f4;
  --seq-350:      #5598e7;
  --seq-500:      #256abf;
  --seq-650:      #104281;

  /* status / deltas */
  --good-text:    #006300;
  --good:         #0ca30c;
  --critical:     #d03b3b;
  --warning-ink:  #8a5a00;
  --warning-bg:   #fdf3dc;

  --accent:       #7a1f2b;   /* oxblood — bookbinding accent */

  --font-display: "Fraunces", Georgia, serif;
  --font-body:    "Karla", system-ui, sans-serif;
  --font-chart:   system-ui, -apple-system, "Segoe UI", sans-serif;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(28,26,21,.05), 0 8px 24px -12px rgba(28,26,21,.18);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  background:
    radial-gradient(1200px 500px at 15% -5%, rgba(122,31,43,.05), transparent 60%),
    radial-gradient(900px 420px at 100% 0%, rgba(42,120,214,.05), transparent 55%),
    var(--paper);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.5;
}

/* subtle paper grain */
body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.028'/%3E%3C/svg%3E");
}

.hidden { display: none !important; }

/* ============================== LOGIN ============================== */

.login-view {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 24px;
  position: relative; z-index: 1;
}

.login-card {
  width: min(460px, 100%);
  text-align: center;
  background: var(--card);
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 56px 44px 48px;
  animation: rise .6s cubic-bezier(.2,.7,.2,1) both;
}

.login-rule {
  height: 3px; width: 72px; margin: 0 auto;
  background: var(--accent);
  position: relative;
}
.login-rule::after {
  content: ""; position: absolute; left: 0; right: 0; top: 5px;
  border-top: 1px solid var(--accent);
}

.login-kicker {
  margin-top: 28px;
  font-size: 12px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--ink-muted); font-weight: 600;
}

.login-title {
  font-family: var(--font-display);
  font-size: clamp(30px, 5vw, 40px);
  font-weight: 550;
  line-height: 1.12;
  margin: 14px 0 10px;
  letter-spacing: -.01em;
}
.login-title em { font-style: italic; font-weight: 420; }

.login-sub {
  color: var(--ink-2); font-size: 14px; margin-bottom: 34px;
}

#login-form input {
  width: 100%;
  font: inherit; font-size: 16px;
  padding: 12px 16px;
  border: 1px solid var(--baseline);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: center;
  letter-spacing: .12em;
  transition: border-color .15s, box-shadow .15s;
}
#login-form input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(122,31,43,.12);
}

#login-form button {
  width: 100%;
  margin-top: 14px;
  font-family: var(--font-body); font-weight: 700; font-size: 15px;
  padding: 12px 16px;
  border: none; border-radius: 8px;
  background: var(--ink); color: var(--paper);
  cursor: pointer;
  transition: transform .12s, background .15s;
}
#login-form button:hover { background: var(--accent); transform: translateY(-1px); }
#login-form button:active { transform: translateY(0); }

.login-error {
  min-height: 20px; margin: 12px 0 22px;
  color: var(--critical); font-size: 14px; font-weight: 600;
}

/* ============================== MASTHEAD ============================== */

.app-view { position: relative; z-index: 1; }

.masthead {
  border-bottom: 1px solid var(--baseline);
  background: linear-gradient(to bottom, rgba(252,252,251,.6), transparent);
}
.masthead-inner {
  max-width: 1060px; margin: 0 auto;
  padding: 34px 24px 26px;
  display: flex; justify-content: space-between; align-items: flex-end; gap: 20px;
  flex-wrap: wrap;
}
.masthead-inner > div { min-width: 0; }

.kicker {
  font-size: 11.5px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--ink-muted); font-weight: 700; margin-bottom: 6px;
}

.masthead-title {
  font-family: var(--font-display);
  font-size: clamp(24px, 4vw, 38px);
  font-weight: 560; letter-spacing: -.015em; line-height: 1.12;
  overflow-wrap: break-word;
}
.masthead-title em { font-weight: 400; }

.masthead-side { text-align: right; }
.today-line { font-size: 13.5px; color: var(--ink-2); margin-bottom: 8px; }
.today-line strong { color: var(--ink); }

.ghost-btn {
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--ink-muted);
  background: none; border: 1px solid var(--hairline); border-radius: 6px;
  padding: 5px 12px; cursor: pointer;
  transition: color .15s, border-color .15s;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--baseline); }

/* ============================== LAYOUT ============================== */

.page {
  max-width: 1060px; margin: 0 auto;
  padding: 28px 24px 64px;
  display: grid; gap: 22px;
}
.page > * { min-width: 0; }

.panel {
  background: var(--card);
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 26px 26px;
  animation: rise .55s cubic-bezier(.2,.7,.2,1) both;
}
.page > *:nth-child(1) { animation-delay: .02s; }
.page > *:nth-child(2) { animation-delay: .07s; }
.page > *:nth-child(3) { animation-delay: .12s; }
.page > *:nth-child(4) { animation-delay: .17s; }
.page > *:nth-child(5) { animation-delay: .22s; }
.page > *:nth-child(6) { animation-delay: .27s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.panel-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.panel-title {
  font-family: var(--font-display);
  font-size: 21px; font-weight: 580; letter-spacing: -.01em;
}
.panel-sub { font-size: 13.5px; color: var(--ink-muted); margin-top: 2px; }

/* ============================== HERO ============================== */

.hero {
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 32px;
  position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(600px 220px at 85% -20%, rgba(122,31,43,.55), transparent 70%);
}

.hero-inner { position: relative; z-index: 1; display: grid; gap: 18px; }

.hero-top {
  display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap;
}
.hero-count {
  font-family: var(--font-display);
  font-size: clamp(48px, 8vw, 74px);
  font-weight: 620; line-height: 1; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.hero-of { font-size: 16px; color: rgba(246,243,234,.66); }
.hero-of strong { color: var(--paper); font-weight: 700; }

.hero-today {
  margin-left: auto; text-align: right;
  font-size: 14px; color: rgba(246,243,234,.75);
}
.hero-today .val { font-size: 26px; font-weight: 700; font-family: var(--font-display); display: block; line-height: 1.1; }
.hero-today .val.ok { color: #7fd67f; }
.hero-today .val.pending { color: #f0c86a; }

.progress-track {
  height: 10px; border-radius: 999px;
  background: rgba(246,243,234,.16);
  overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #5598e7, #9ec5f4);
  transition: width .8s cubic-bezier(.2,.7,.2,1);
}
.hero-foot {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  font-size: 13px; color: rgba(246,243,234,.66);
}
.hero-foot strong { color: var(--paper); }

/* ============================== TILES ============================== */

.tiles {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.tile {
  background: var(--card);
  border: 1px solid var(--ring);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px 14px;
}
.tile-label {
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  font-weight: 700; color: var(--ink-muted); margin-bottom: 6px;
}
.tile-value {
  font-family: var(--font-display);
  font-size: 27px; font-weight: 600; letter-spacing: -.01em; line-height: 1.1;
}
.tile-value small { font-size: 14px; font-weight: 500; color: var(--ink-2); font-family: var(--font-body); }
.tile-note { font-size: 12px; color: var(--ink-muted); margin-top: 4px; }
.tile-value.flame::after { content: " 🔥"; font-size: 18px; }

/* ============================== CHART ============================== */

.seg {
  display: inline-flex; border: 1px solid var(--hairline); border-radius: 8px;
  overflow: hidden; background: var(--paper);
}
.seg-btn {
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--ink-muted); background: none; border: none;
  padding: 7px 14px; cursor: pointer;
  transition: background .15s, color .15s;
}
.seg-btn.active { background: var(--ink); color: var(--paper); }

.chart-wrap { position: relative; }
#chart { display: block; width: 100%; height: 340px; font-family: var(--font-chart); }

.chart-tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--ink); color: var(--paper);
  border-radius: 8px; padding: 10px 13px;
  font-size: 12.5px; line-height: 1.55;
  box-shadow: 0 6px 20px -6px rgba(28,26,21,.4);
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 14px));
}
.chart-tip .tip-date { font-weight: 700; margin-bottom: 3px; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 7px; }
.chart-tip .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.chart-tip .num { font-variant-numeric: tabular-nums; margin-left: auto; padding-left: 14px; font-weight: 600; }

.legend {
  display: flex; gap: 22px; flex-wrap: wrap;
  margin-top: 10px; padding-left: 6px;
  font-size: 13px; color: var(--ink-2); font-family: var(--font-chart);
}
.legend .item { display: inline-flex; align-items: center; gap: 8px; }
.legend .swatch { width: 16px; height: 0; border-top: 2.5px solid; border-radius: 2px; }
.legend .swatch.dashed { border-top-style: dashed; }

/* ============================== HEATMAP ============================== */

.heatmap-scroll { overflow-x: auto; padding-bottom: 4px; }
.heatmap { display: inline-grid; grid-auto-flow: column; gap: 4px; }
.hm-col { display: grid; grid-template-rows: repeat(7, 18px); gap: 4px; }
.hm-cell {
  width: 18px; height: 18px; border-radius: 4px;
  background: var(--paper-deep);
  position: relative;
}
.hm-cell.future { background: transparent; border: 1px dashed var(--hairline); }
.hm-cell.l0 { background: var(--paper-deep); }
.hm-cell.l1 { background: var(--seq-100); }
.hm-cell.l2 { background: var(--seq-200); }
.hm-cell.l3 { background: var(--seq-350); }
.hm-cell.l4 { background: var(--seq-500); }
.hm-cell.l5 { background: var(--seq-650); }
.hm-cell.late::after {
  content: ""; position: absolute; right: 2px; top: 2px;
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--critical);
}
.hm-cell.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.hm-cell:hover { outline: 2px solid var(--ink); outline-offset: 1px; cursor: default; }

.hm-month {
  font-size: 11px; color: var(--ink-muted); font-family: var(--font-chart);
  height: 14px; margin-bottom: 2px; white-space: nowrap;
}

.heatmap-key {
  display: flex; align-items: center; gap: 6px;
  margin-top: 12px; font-size: 12px; color: var(--ink-muted);
  font-family: var(--font-chart); flex-wrap: wrap;
}
.heatmap-key .hm-cell { cursor: default; }
.heatmap-key .gap { width: 10px; }

/* ============================== UPLOAD ============================== */

.upload-panel {
  border: 1.5px dashed var(--baseline);
  background: linear-gradient(to bottom, var(--card), #faf8f2);
  text-align: center;
  transition: border-color .2s, background .2s, transform .2s;
}
.upload-panel.dragover {
  border-color: var(--series-1);
  background: #eef5fd;
  transform: scale(1.005);
}

.upload-inner {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 8px 0 4px;
}
.upload-glyph { font-size: 34px; }

.primary-btn {
  font: inherit; font-size: 15px; font-weight: 700;
  background: var(--accent); color: #fff;
  border: none; border-radius: 8px;
  padding: 12px 26px; cursor: pointer;
  transition: transform .12s, box-shadow .15s, background .15s;
  box-shadow: 0 2px 10px -2px rgba(122,31,43,.45);
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 5px 16px -3px rgba(122,31,43,.5); }
.primary-btn:disabled { opacity: .55; cursor: wait; transform: none; }

.upload-note { font-size: 12.5px; color: var(--ink-muted); margin-top: 12px; }

.upload-status {
  margin: 14px auto 0; max-width: 560px;
  border-radius: 8px; padding: 12px 16px;
  font-size: 14px; font-weight: 600; text-align: left;
}
.upload-status.ok    { background: #e9f6e9; color: var(--good-text); border: 1px solid #bfe3bf; }
.upload-status.warn  { background: var(--warning-bg); color: var(--warning-ink); border: 1px solid #efd9a6; }
.upload-status.err   { background: #fbe9e9; color: #8f1f1f; border: 1px solid #efc3c3; }
.upload-status .sub  { font-weight: 400; font-size: 13px; margin-top: 2px; }

/* ============================== TABLE ============================== */

.table-wrap { overflow-x: auto; }

.uploads-table {
  width: 100%; border-collapse: collapse;
  font-size: 14px;
}
.uploads-table th {
  text-align: left; font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-muted); font-weight: 700;
  border-bottom: 2px solid var(--ink);
  padding: 8px 12px;
  white-space: nowrap;
}
.uploads-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
  white-space: nowrap;
}
.uploads-table tr:hover td { background: #faf8f1; }

.uploads-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.uploads-table th.num { text-align: right; }

.td-added   { color: var(--good-text);  font-weight: 700; }
.td-removed { color: var(--critical);   font-weight: 700; }
.td-zero    { color: var(--ink-muted);  font-weight: 400; }

.file-link {
  color: var(--ink); font-weight: 600; text-decoration: none;
  border-bottom: 1px solid var(--baseline);
  transition: color .15s, border-color .15s;
}
.file-link:hover { color: var(--series-1); border-color: var(--series-1); }
.file-link::after { content: " ↓"; color: var(--ink-muted); font-weight: 400; }

.badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  letter-spacing: .05em; border-radius: 999px; padding: 2px 9px;
  vertical-align: 1px; margin-left: 8px;
}
.badge.ontime { background: #e9f6e9; color: var(--good-text); }
.badge.late   { background: #fbe9e9; color: #8f1f1f; }

.time-cell .t { font-weight: 600; }
.time-cell .d { color: var(--ink-muted); font-size: 12.5px; }

.del-btn {
  font: inherit; font-size: 12px; color: var(--ink-muted);
  background: none; border: none; cursor: pointer;
  text-decoration: underline dotted;
}
.del-btn:hover { color: var(--critical); }

.empty-state {
  text-align: center; padding: 28px 12px; color: var(--ink-muted);
  font-size: 14.5px; font-style: italic; font-family: var(--font-display);
}

/* ============================== DIFF VIEWER ============================== */

.diff-modal { position: fixed; inset: 0; z-index: 60; }
.diff-scrim {
  position: absolute; inset: 0;
  background: rgba(28,26,21,.55);
  backdrop-filter: blur(3px);
  animation: fadein .2s ease both;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.diff-sheet {
  position: absolute; inset: 4vh 0 0 0;
  margin: 0 auto;
  width: min(820px, 100%);
  background: var(--card);
  border: 1px solid var(--ring);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -4px 60px -10px rgba(28,26,21,.5);
  display: flex; flex-direction: column;
  animation: sheetup .3s cubic-bezier(.2,.7,.2,1) both;
}
@keyframes sheetup {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.diff-head {
  display: flex; align-items: flex-start; gap: 16px;
  padding: 20px 26px 16px;
  border-bottom: 2px solid var(--ink);
}
.diff-head-main { min-width: 0; flex: 1; }
.diff-title {
  font-family: var(--font-display);
  font-size: 19px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.diff-sub { font-size: 12.5px; color: var(--ink-muted); margin-top: 2px; }

.diff-counts { display: flex; gap: 8px; align-items: center; padding-top: 3px; }
.diff-counts .pill {
  font-size: 12.5px; font-weight: 700; border-radius: 999px; padding: 3px 11px;
  font-variant-numeric: tabular-nums;
}
.diff-counts .pill.add { background: #e9f6e9; color: var(--good-text); }
.diff-counts .pill.del { background: #fbe9e9; color: #8f1f1f; }

.diff-close {
  font-size: 26px; line-height: 1; color: var(--ink-muted);
  background: none; border: none; cursor: pointer; padding: 0 2px;
}
.diff-close:hover { color: var(--ink); }

.diff-body {
  overflow-y: auto; flex: 1;
  padding: 26px 34px 60px;
  font-family: var(--font-display);
  font-size: 15.5px; line-height: 1.75;
  color: var(--ink);
}
.diff-para { margin-bottom: 1em; }
.diff-para.removed-para { opacity: .85; }

.seg-add {
  background: #dff2df; color: #063f06;
  border-radius: 3px; padding: 1px 3px;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.seg-del {
  background: #fbe5e5; color: #8f1f1f;
  text-decoration: line-through; text-decoration-thickness: 1.5px;
  border-radius: 3px; padding: 1px 3px;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}

.diff-gap {
  display: block; width: 100%;
  font: inherit; font-family: var(--font-body);
  font-size: 12.5px; font-weight: 600; letter-spacing: .06em;
  color: var(--ink-muted);
  background: var(--paper);
  border: 1px dashed var(--baseline); border-radius: 8px;
  padding: 8px 12px; margin: 0 0 1em;
  cursor: pointer; text-align: center;
  transition: color .15s, border-color .15s, background .15s;
}
.diff-gap:hover { color: var(--ink); border-color: var(--ink-muted); background: #f2efe6; }

.diff-loading, .diff-error {
  font-family: var(--font-body); font-size: 14px; color: var(--ink-muted);
  text-align: center; padding: 40px 0;
}
.diff-error { color: var(--critical); }

@media (max-width: 640px) {
  .diff-sheet { inset: 3vh 0 0 0; border-radius: 12px 12px 0 0; }
  .diff-head { padding: 16px 16px 12px; flex-wrap: wrap; }
  .diff-body { padding: 20px 18px 50px; font-size: 15px; }
}

/* ============================== CELEBRATION ============================== */

.celebrate {
  position: fixed; inset: 0; z-index: 100; pointer-events: none;
  display: grid; place-items: center;
}
.celebrate-text {
  font-family: var(--font-display); font-style: italic; font-weight: 560;
  font-size: clamp(34px, 6vw, 58px);
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--ring); border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 26px 44px;
  animation: pop 2.6s cubic-bezier(.2,.7,.3,1) both;
}
.celebrate-text small {
  display: block; font-family: var(--font-body); font-style: normal;
  font-size: 14px; font-weight: 600; letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink-muted); text-align: center; margin-top: 6px;
}
@keyframes pop {
  0%   { opacity: 0; transform: scale(.85) translateY(14px); }
  12%  { opacity: 1; transform: scale(1) translateY(0); }
  82%  { opacity: 1; }
  100% { opacity: 0; transform: scale(.98) translateY(-8px); }
}
.confetti {
  position: fixed; top: -12px; width: 9px; height: 14px; z-index: 99;
  animation: fall linear both;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); }
}

/* ============================== FOOTER ============================== */

.colophon {
  text-align: center; color: var(--ink-muted);
  font-size: 12.5px; padding-top: 10px;
}

@media (max-width: 640px) {
  .masthead-inner { padding: 24px 18px 20px; }
  .masthead-side { text-align: left; }
  .page { padding: 20px 14px 48px; }
  .panel { padding: 18px 16px 20px; }
  .hero { padding: 22px 20px; }
  #chart { height: 260px; }
}
