:root {
  --bg: #f3f0ea;
  --paper: #fffdf8;
  --ink: #1c1916;
  --muted: #6e685f;
  --line: #e4ddd2;
  --danger-bg: #f8ece7;
  --danger: #8c3b2e;
  --shadow: 0 1px 0 rgba(28, 25, 22, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.7), transparent 32rem),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Helvetica, Arial, sans-serif;
}

main {
  width: min(1120px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 0 80px;
}

.mast {
  margin-bottom: 28px;
  padding: 28px 28px 26px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.mast-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 72px;
  margin-bottom: 26px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.brand {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand img {
  display: block;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
}

.brand strong {
  display: block;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.brand span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.account {
  grid-column: 1;
  justify-self: start;
  align-self: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

#account-email {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout {
  width: fit-content;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

.logout:hover {
  text-decoration: underline;
}

button,
input,
select {
  font: inherit;
}

#refresh,
.download,
.view,
#viewer-close,
.pager button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 620;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

#refresh svg,
.download svg,
.view svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

#refresh {
  grid-column: 3;
  justify-self: end;
  align-self: center;
  flex-shrink: 0;
  min-height: 34px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
  font-size: 12px;
  font-weight: 600;
}

#refresh svg {
  width: 14px;
  height: 14px;
}

#refresh:hover:not(:disabled) {
  color: var(--ink);
  background: var(--bg);
  border-color: #c9c0b4;
}

.view,
#viewer-close,
.pager button {
  color: var(--ink);
  background: var(--paper);
  border-color: var(--line);
}

#refresh:hover:not(:disabled),
.view:hover:not(:disabled),
#viewer-close:hover,
.pager button:hover:not(:disabled):not([aria-current="page"]) {
  background: var(--bg);
  border-color: #c9c0b4;
}

.download {
  color: #fffdf8;
  background: var(--ink);
  border-color: var(--ink);
}

.download:hover:not(:disabled) {
  background: #3a342e;
}

.download:active:not(:disabled),
.view:active:not(:disabled),
#refresh:active:not(:disabled),
#viewer-close:active {
  transform: translateY(1px);
}

#refresh:disabled,
.download:disabled,
.view:disabled,
.pager button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.mast-search {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.search-field {
  position: relative;
}

.search-icon {
  position: absolute;
  top: 50%;
  left: 16px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
  transform: translateY(-50%);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

input {
  width: 100%;
  padding: 16px 18px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.mast input {
  height: 52px;
  padding: 0 18px 0 46px;
  background: var(--bg);
  border-radius: 12px;
  box-shadow: none;
  font-size: 15px;
}

.mast input:hover:not(:disabled) {
  border-color: #c9c0b4;
}

.mast input:focus {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-color: transparent;
}

.mast input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.date-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.date-filters label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.date-filters span {
  color: #4e4943;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.date-filters select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 14px;
}

.date-filters select:hover:not(:disabled) {
  border-color: #c9c0b4;
}

.date-filters select:focus {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-color: transparent;
}

.date-filters select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input:focus {
  outline: 2px solid var(--ink);
  border-color: transparent;
}

.status {
  min-height: 1.4em;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.status.error {
  padding: 14px 16px;
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: 12px;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1fr) minmax(0, 1.6fr) minmax(0, 0.9fr) max-content;
  gap: 14px 16px;
  align-items: center;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.field {
  min-width: 0;
}

.meta-label {
  display: block;
  margin-bottom: 4px;
  color: #4e4943;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.number,
.value {
  display: block;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.35;
}

.number {
  font-size: 18px;
  font-weight: 680;
  letter-spacing: 0.02em;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 22px;
}

.pager-label {
  margin-right: 6px;
  color: var(--muted);
  font-size: 14px;
}

.pager button,
.pager .ellipsis {
  min-width: 36px;
  text-align: center;
}

.pager button[aria-current="page"] {
  color: #fffdf8;
  background: var(--ink);
  border-color: var(--ink);
}

.pager .ellipsis {
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-shrink: 0;
}

.view,
.download,
#viewer-close {
  padding: 0 14px;
}

.empty {
  padding: 42px 16px;
  color: var(--muted);
  text-align: center;
  background: rgba(255, 253, 248, 0.55);
  border: 1px dashed var(--line);
  border-radius: 16px;
}

#viewer {
  width: min(1080px, calc(100vw - 32px));
  height: min(90vh, 920px);
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(28, 25, 22, 0.28);
}

#viewer[open] {
  display: flex;
  flex-direction: column;
}

#viewer::backdrop {
  background: rgba(28, 25, 22, 0.48);
}

.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

#viewer-title {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  font-weight: 500;
}

#viewer-file {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.viewer-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

#viewer-status {
  margin: 12px 18px 0;
}

#viewer-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: #ece8e1;
}

@media (max-width: 1040px) {
  .row {
    grid-template-columns: 1fr 1fr;
  }

  .field.customer,
  .actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  main {
    width: min(1120px, calc(100% - 32px));
    padding-top: 16px;
  }

  .mast {
    padding: 18px 16px 16px;
  }

  .mast-top {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 16px;
    min-height: 0;
    margin-bottom: 20px;
    padding-bottom: 18px;
  }

  .brand,
  .account,
  #refresh {
    grid-column: 1;
    justify-self: center;
  }

  .brand {
    order: 1;
  }

  .account {
    order: 2;
    align-items: center;
  }

  #refresh {
    order: 3;
  }

  .brand strong {
    font-size: 22px;
  }

  .brand img {
    width: 44px;
    height: 44px;
  }

  .mast input {
    height: 48px;
  }

  .row {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .field.customer,
  .actions {
    grid-column: 1 / -1;
  }

  .actions,
  .viewer-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .viewer-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  #viewer {
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
  }
}

body.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

body.login main {
  width: min(28rem, calc(100% - 40px));
  padding: 32px 0;
}

.login-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 36px 40px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card strong {
  margin-top: 16px;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.login-card h1 {
  margin: 8px 0 0;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-weight: 500;
}

.login-card p {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.login-card p span {
  color: var(--ink);
}

.login-card .status {
  width: 100%;
  margin-top: 18px;
  text-align: left;
}

.microsoft-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  margin-top: 28px;
  padding: 0 18px;
  color: var(--paper);
  background: var(--ink);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 620;
  text-decoration: none;
}

.microsoft-button:hover {
  background: #3a342e;
}

.microsoft-button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}
