/* ==========================================================================
   Invoice Archive
   Layered on top of Bootstrap 5: Bootstrap supplies the reset, the grid and
   the utility classes, everything visual below is this file.

   Type rule used throughout: monospace carries machine data (names, dates,
   sizes, counts), the sans face carries anything a person wrote.
   ========================================================================== */

:root {
  --font-display: 'Bricolage Grotesque', 'IBM Plex Sans', system-ui, sans-serif;
  --font-ui:      'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono:    'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --paper:       #eceff3;
  --card:        #ffffff;
  --card-hover:  #f7f9fb;
  --ink:         #10151b;
  --ink-2:       #39424e;
  --slate:       #6c7887;
  --line:        #dbe1e9;
  --line-soft:   #e8ecf1;
  --accent:      #0b5f75;
  --accent-ink:  #ffffff;
  --accent-soft: #dbebf0;
  --signal:      #8a5a00;
  --danger:      #9c2b1e;

  --radius:   7px;
  --radius-s: 5px;
  --shadow:   0 1px 2px rgba(16, 21, 27, .05), 0 8px 24px -18px rgba(16, 21, 27, .35);
  --wrap:     1240px;
}

[data-theme="dark"] {
  --paper:       #0b0f14;
  --card:        #151b23;
  --card-hover:  #1b232d;
  --ink:         #e6ecf3;
  --ink-2:       #b6c1ce;
  --slate:       #7d8899;
  --line:        #242d39;
  --line-soft:   #1b232d;
  --accent:      #57bcd2;
  --accent-ink:  #062029;
  --accent-soft: #10303c;
  --signal:      #d3a049;
  --danger:      #e0796a;
  --shadow:      0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -20px rgba(0, 0, 0, .8);
}

/* --------------------------------------------------------------- base --- */

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin-inline: auto;
  padding-inline: 22px;
}

.mono { font-family: var(--font-mono); font-size: .875em; letter-spacing: -.01em; }
.dot  { color: var(--slate); margin-inline: .45em; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--slate);
}

code {
  font-family: var(--font-mono);
  font-size: .86em;
  background: var(--line-soft);
  border-radius: 4px;
  padding: .12em .38em;
  color: var(--ink-2);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ---------------------------------------------------------- masthead --- */

.masthead {
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.masthead__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 74px;
  padding-block: 14px;
}

.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }

.brand__glyph {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: var(--radius-s);
  background: var(--accent-soft);
  color: var(--accent);
}

.brand__name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 21px;
  letter-spacing: -.022em;
  margin: 0;
  line-height: 1.15;
}

.brand__meta {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--slate);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.masthead__actions { display: flex; align-items: center; gap: 10px; }

.whoami {
  color: var(--slate);
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.signout {
  font-size: 13.5px;
  color: var(--ink-2);
  border-bottom: 1px solid transparent;
}
.signout:hover { color: var(--accent); text-decoration: none; border-bottom-color: currentColor; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--card);
  color: var(--ink-2);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--card-hover); color: var(--accent); border-color: var(--accent); }

.ico-moon { display: none; }
[data-theme="dark"] .ico-sun  { display: none; }
[data-theme="dark"] .ico-moon { display: block; }

/* ------------------------------------------------------- months panel --- */

.months {
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.months[hidden] { display: none; }

.months__inner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding-block: 9px;
}

.months__toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  height: 28px;
  padding: 0 10px;
  font-family: var(--font-ui);
  font-size: 12.5px;
  color: var(--ink-2);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.months__toggle:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.months__toggle:disabled { cursor: default; opacity: .65; }
.months__toggle:disabled .months__chev { display: none; }

.months__cal { flex: 0 0 auto; opacity: .75; }
.months__label { white-space: nowrap; }

.months__chev { transition: transform .18s ease; }
.months:not(.is-collapsed) .months__chev { transform: rotate(180deg); }

.months__list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 0;
  padding-top: 1px;
}

/* Collapsed: the pinned month, plus whatever is currently filtered. */
.months.is-collapsed .mpill:not(.is-pinned):not(.is-on) { display: none; }

.mpill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 5px 0 10px;
  font-family: var(--font-ui);
  font-size: 12.5px;
  color: var(--ink-2);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.mpill:hover { border-color: var(--accent); color: var(--accent); }

.mpill__n {
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 17px;
  min-width: 19px;
  padding: 0 5px;
  text-align: center;
  color: var(--slate);
  background: var(--line-soft);
  border-radius: 999px;
}

.mpill.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.mpill.is-on .mpill__n {
  background: color-mix(in srgb, var(--accent-ink) 22%, transparent);
  color: var(--accent-ink);
}

/* ---------------------------------------------------------- toolbar --- */

.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(9px);
  border-bottom: 1px solid var(--line);
}

.toolbar__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding-block: 13px;
}

.search { position: relative; flex: 1 1 260px; min-width: 200px; }

.search__ico {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--slate);
  pointer-events: none;
}

.search__input {
  width: 100%;
  height: 38px;
  padding: 0 40px 0 34px;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
}
.search__input::placeholder { color: var(--slate); }
.search__input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.search__input::-webkit-search-cancel-button { cursor: pointer; }

.search__kbd {
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--slate);
  background: var(--line-soft);
  border-radius: 4px;
  padding: 1px 6px;
  pointer-events: none;
}
.search__input:focus ~ .search__kbd { opacity: 0; }

.ctl { display: flex; flex-direction: column; gap: 4px; }

.ctl__label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--slate);
}

.ctl__input {
  height: 38px;
  padding: 0 10px;
  font-size: 13.5px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
}
.ctl__input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
select.ctl__input { min-width: 148px; cursor: pointer; }
input[type="month"].ctl__input { min-width: 152px; cursor: pointer; }
[data-theme="dark"] input[type="month"]::-webkit-calendar-picker-indicator { filter: invert(.8); }

.chips { display: flex; gap: 6px; align-items: center; height: 38px; }

.chip {
  height: 30px;
  padding: 0 11px;
  font-size: 12.5px;
  color: var(--ink-2);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.toolbar__right { display: flex; align-items: center; gap: 8px; margin-left: auto; height: 38px; }

.viewswitch { display: flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }

.viewswitch__btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  background: var(--card);
  color: var(--slate);
  cursor: pointer;
}
.viewswitch__btn + .viewswitch__btn { border-left: 1px solid var(--line); }
.viewswitch__btn.is-on { background: var(--accent-soft); color: var(--accent); }

.btn-ghost {
  height: 34px;
  padding: 0 13px;
  font-size: 13px;
  font-family: var(--font-ui);
  color: var(--ink-2);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn-ghost:disabled { opacity: .5; cursor: not-allowed; }

/* ------------------------------------------------------------ results --- */

.resultline {
  margin: 14px 0 8px;
  font-size: 13px;
  color: var(--slate);
}
.resultline__scope { color: var(--accent); margin-left: .5em; }

.results { padding-bottom: 40px; }

.monthbar {
  display: flex;
  align-items: baseline;
  gap: 12px;
  position: sticky;
  top: 65px;
  z-index: 10;
  padding: 7px 2px 6px;
  margin-top: 12px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.monthbar:first-child { margin-top: 0; }

.monthbar__label {
  font-family: var(--font-display);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -.015em;
}

.monthbar__count { font-family: var(--font-mono); font-size: 11.5px; color: var(--slate); }
.monthbar__rule { flex: 1; height: 1px; background: var(--line-soft); }

/* --- rows --- */

.row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 5px 10px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background .12s;
}
.row:hover { background: var(--card-hover); }
.row:focus-visible { background: var(--card-hover); }

.row__ico { color: var(--danger); opacity: .8; display: grid; place-items: center; }

.row__name {
  display: block;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row:hover .row__name,
.row__name:hover { color: var(--accent); text-decoration: none; }
.row__name mark {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0;
  border-radius: 2px;
}

.row__date, .row__size {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--slate);
  white-space: nowrap;
}
.row__date { min-width: 88px; text-align: right; }
.row__size { min-width: 62px; text-align: right; }

.row__actions { display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.row:hover .row__actions,
.row:focus-within .row__actions { opacity: 1; }

.mini {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--card);
  color: var(--ink-2);
}
.mini:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

.approx {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--signal);
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 0 4px;
  margin-left: 7px;
  vertical-align: 1px;
  cursor: help;
}

/* --- cards --- */

.view-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(216px, 1fr)); gap: 12px; }
.view-grid .monthbar { grid-column: 1 / -1; }

.view-grid .row {
  display: block;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  padding: 14px;
  box-shadow: var(--shadow);
}
.view-grid .row:hover { border-color: var(--accent); }
.view-grid .row__ico { justify-content: flex-start; margin-bottom: 10px; }
.view-grid .row__name { white-space: normal; overflow-wrap: anywhere; line-height: 1.4; }
.view-grid .row__date,
.view-grid .row__size {
  text-align: left;
  min-width: 0;
  margin-top: 9px;
  display: inline-block;
}
.view-grid .row__size { margin-left: 10px; }
.view-grid .row__actions { opacity: 1; margin-top: 12px; }

/* ------------------------------------------------------------- states --- */

.state {
  margin: 34px 0;
  padding: 26px 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}
.state h2 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 6px;
}
.state p { margin: 0; color: var(--slate); font-size: 14px; }
.state--problem { border-left: 3px solid var(--danger); text-align: left; }

.loadmore { display: flex; justify-content: center; padding-bottom: 44px; }

/* ------------------------------------------------------------- viewer --- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}
.viewer[hidden] { display: none; }

.viewer__bar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.viewer__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer__spacer { flex: 1; }
.viewer__frame { flex: 1; background: var(--line-soft); }
.viewer__frame iframe { width: 100%; height: 100%; border: 0; display: block; }

/* --------------------------------------------------------------- auth --- */

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 420px at 50% -12%, var(--accent-soft), transparent 70%),
    var(--paper);
}

.auth-shell { width: 100%; max-width: 396px; }

.auth-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 26px 24px;
  box-shadow: var(--shadow);
}

.auth-mark { display: flex; align-items: center; gap: 13px; margin-bottom: 22px; }

.auth-mark__glyph {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: var(--radius-s);
  background: var(--accent-soft);
  color: var(--accent);
}

.auth-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.022em;
  margin: 0;
}
.auth-sub { margin: 1px 0 0; font-size: 12.5px; color: var(--slate); }

.field { display: block; margin-bottom: 14px; }

.field__label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--slate);
  margin-bottom: 5px;
}

.field__input {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
}
.field__input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

.btn-primary-flat {
  width: 100%;
  height: 41px;
  margin-top: 6px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-s);
  cursor: pointer;
  transition: filter .15s;
}
.btn-primary-flat:hover { filter: brightness(1.12); }
.btn-primary-flat:disabled { opacity: .55; cursor: not-allowed; }

.auth-msg {
  font-size: 13px;
  padding: 9px 11px;
  border-radius: var(--radius-s);
  margin-bottom: 16px;
}
.auth-msg--error { color: var(--danger); background: color-mix(in srgb, var(--danger) 9%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent); }
.auth-msg--info  { color: var(--ink-2); background: var(--line-soft); border: 1px solid var(--line); }

.auth-foot { margin: 18px 0 0; font-size: 11.5px; color: var(--slate); line-height: 1.55; }
.auth-foot--warn { color: var(--signal); }

/* --------------------------------------------------------- responsive --- */

@media (max-width: 860px) {
  .wrap { padding-inline: 15px; }
  .masthead__inner { min-height: 0; }
  .brand__meta { white-space: normal; }
  .toolbar__inner { gap: 9px; }
  .search { flex: 1 1 100%; }
  .toolbar__right { margin-left: 0; width: 100%; justify-content: space-between; }
  .chips { overflow-x: auto; }

  .row {
    grid-template-columns: 26px minmax(0, 1fr) auto;
    grid-template-areas:
      "ico name name"
      "ico meta act";
    row-gap: 4px;
  }
  .row__ico     { grid-area: ico; align-self: start; margin-top: 2px; }
  .row__name    { grid-area: name; }
  .row__date    { grid-area: meta; text-align: left; min-width: 0; }
  .row__size    { display: none; }
  .row__actions { grid-area: act; opacity: 1; }
  .monthbar { top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
