:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-glass: rgba(255, 255, 255, 0.78);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #d8dde6;
  --line-soft: #e9edf3;
  --accent: #0a84ff;
  --accent-hover: #006edb;
  --danger: #d92d20;
  --danger-hover: #b42318;
  --success-bg: #edf8f0;
  --success-text: #157347;
  --shadow: 0 18px 42px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 8px 22px rgba(15, 23, 42, 0.05);
  --radius: 8px;
  --control-height: 40px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: linear-gradient(180deg, #fbfbfd 0%, #f5f5f7 46%, #f2f4f7 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  letter-spacing: 0;
}

body.auth-page {
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

a:hover {
  color: var(--accent-hover);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 58px;
  padding: 12px max(24px, calc((100vw - 1180px) / 2 + 24px));
  background: var(--surface-glass);
  border-bottom: 1px solid rgba(216, 221, 230, 0.72);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.72) inset;
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
}

.brand {
  color: var(--text);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand:hover {
  color: var(--text);
}

.topnav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  flex-wrap: wrap;
}

.topnav a {
  color: #3f3f46;
  border-radius: var(--radius);
  padding: 8px 11px;
  font-size: 14px;
  font-weight: 650;
  line-height: 1;
}

.topnav a:hover {
  color: var(--text);
  background: rgba(10, 132, 255, 0.09);
}

.page {
  width: min(1180px, calc(100% - 40px));
  margin: 30px auto 56px;
}

h1,
h2,
h3 {
  color: var(--text);
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.16;
  font-weight: 800;
}

h2 {
  margin: 0 0 14px;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 760;
}

h3 {
  margin: 0 0 10px;
  font-size: 16px;
  line-height: 1.3;
  font-weight: 760;
}

section + section {
  margin-top: 28px;
}

h1 + .form-grid,
h1 + .login-panel {
  margin-top: 18px;
}

.login-panel {
  width: min(430px, 100%);
  margin: 0 auto;
  padding: 30px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(216, 221, 230, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.page .login-panel {
  margin-top: 52px;
}

.login-panel h1 {
  margin-bottom: 22px;
  font-size: 28px;
}

.login-panel button[type="submit"] {
  width: 100%;
  margin-top: 4px;
}

form {
  margin: 0;
}

label {
  display: grid;
  gap: 8px;
  margin: 14px 0;
  color: #303033;
  font-size: 14px;
  font-weight: 680;
}

input,
textarea,
select {
  width: 100%;
  min-height: var(--control-height);
  padding: 9px 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid #c9d1dc;
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.82) inset;
  font: inherit;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

textarea {
  min-height: 118px;
  resize: vertical;
}

input:hover,
textarea:hover,
select:hover {
  border-color: #aeb8c6;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.14);
}

input[type="file"] {
  min-height: auto;
  padding: 8px;
  background: #ffffff;
}

input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  padding: 0;
  box-shadow: none;
}

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--control-height);
  padding: 9px 14px;
  color: #ffffff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 10px 22px rgba(10, 132, 255, 0.2);
  cursor: pointer;
  font: inherit;
  font-weight: 720;
  line-height: 1.1;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 140ms ease, background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

button:hover,
.button-link:hover {
  color: #ffffff;
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 12px 26px rgba(10, 132, 255, 0.25);
}

button:active,
.button-link:active {
  transform: translateY(1px);
}

.danger-button {
  background: var(--danger);
  border-color: var(--danger);
  box-shadow: 0 10px 22px rgba(217, 45, 32, 0.16);
}

.danger-button:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  box-shadow: 0 12px 26px rgba(217, 45, 32, 0.2);
}

.secondary-button {
  color: var(--text);
  background: #ffffff;
  border-color: #c9d1dc;
  box-shadow: var(--shadow-soft);
}

.secondary-button:hover {
  color: var(--text);
  background: #f7f9fc;
  border-color: #aeb8c6;
  box-shadow: var(--shadow-soft);
}

.compact-form {
  display: inline;
  margin: 0;
}

.compact-form button {
  min-height: 32px;
  padding: 6px 10px;
  box-shadow: none;
  font-size: 13px;
}

.compact-link {
  min-height: 32px;
  padding: 6px 10px;
  box-shadow: none;
  font-size: 13px;
}

.toolbar,
.detail-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.toolbar-actions,
.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.actions {
  justify-content: flex-start;
  margin-top: 20px;
}

.inline-form {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.inline-form input {
  width: auto;
  min-width: 132px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: #303033;
  white-space: nowrap;
}

.inline-check input {
  min-width: 0;
}

.form-grid,
.info-grid,
.summary-grid,
.columns {
  display: grid;
  gap: 16px;
}

.form-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  align-items: end;
  padding: 22px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(216, 221, 230, 0.88);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.form-grid button[type="submit"] {
  justify-self: start;
}

.wide {
  grid-column: 1 / -1;
}

table {
  width: 100%;
  overflow: hidden;
  border-spacing: 0;
  border: 1px solid rgba(216, 221, 230, 0.88);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-soft);
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: rgba(248, 250, 252, 0.96);
  font-size: 13px;
  font-weight: 760;
}

td {
  color: #2f3237;
  background: rgba(255, 255, 255, 0.96);
  font-size: 14px;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: #fbfdff;
}

td a {
  color: var(--text);
  font-weight: 720;
}

td a:hover {
  color: var(--accent);
}

.info-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  padding: 18px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(216, 221, 230, 0.88);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

dd {
  margin: 4px 0 0;
  color: var(--text);
  font-size: 17px;
  font-weight: 780;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  color: #075985;
  background: #eef6ff;
  border: 1px solid #cfe7ff;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 720;
}

.summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.metric,
.columns > div {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(216, 221, 230, 0.88);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.metric strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 32px;
  line-height: 1.15;
  font-weight: 820;
}

.columns {
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
}

.columns > div {
  padding: 18px;
}

.upload-grid,
.attachment-lists {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: 16px;
}

.upload-card,
.attachment-lists > div,
.no-invoice-form {
  padding: 16px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(216, 221, 230, 0.88);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.upload-card {
  display: grid;
  gap: 12px;
  align-content: start;
  min-width: 0;
}

.upload-card h3,
.attachment-lists h3 {
  margin-bottom: 0;
}

.upload-dropzone {
  display: grid;
  place-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 132px;
  margin: 0;
  padding: 16px;
  color: var(--text);
  text-align: center;
  background: #fbfdff;
  border: 1px dashed #aeb8c6;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.upload-dropzone:hover,
.upload-dropzone:focus,
.upload-dropzone.is-dragover {
  background: #eef6ff;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.1);
}

.upload-dropzone-title {
  font-weight: 760;
}

.upload-dropzone-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 560;
}

.upload-dropzone input[type="file"] {
  width: min(100%, 260px);
  margin-top: 4px;
}

.no-invoice-form {
  margin-top: 14px;
}

.attachment-lists {
  margin-top: 16px;
}

.attachment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.export-preview-section {
  scroll-margin-top: 84px;
}

.report-preview {
  display: block;
  width: 100%;
  max-width: 820px;
  aspect-ratio: 210 / 297;
  margin: 0 auto 12px;
  background: white;
  border: 1px solid var(--line-soft);
}

.info-grid > div, .columns > div, label, .actions > *, .attachment-item > span {
  min-width: 0;
  max-width: 100%;
}

h1, dd, .attachment-item > span, td, p {
  overflow-wrap: anywhere;
}

.actions > form { max-width: 100%; }

ul {
  margin: 10px 0 0;
  padding-left: 20px;
}

li {
  margin: 7px 0;
  color: #3b3f46;
}

p {
  margin: 0 0 12px;
}

.error {
  margin: 0 0 14px;
  padding: 10px 12px;
  color: #b42318;
  background: #fff1f0;
  border: 1px solid #fac5c0;
  border-radius: var(--radius);
  font-weight: 650;
}

.notice {
  margin: 0 0 18px;
  padding: 12px 14px;
  color: #8a5a00;
  background: #fff8e6;
  border: 1px solid #fedf89;
  border-radius: var(--radius);
  font-weight: 650;
}

.notice p {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.muted a {
  font-weight: 700;
}

@media (max-width: 760px) {
  .topbar {
    position: static;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 18px;
  }

  .topnav {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    min-width: 0;
    justify-content: flex-start;
    row-gap: 8px;
  }

  .topnav a {
    display: inline-flex;
    justify-content: flex-start;
    padding: 8px 9px;
  }

  .page {
    width: min(100% - 28px, 1180px);
    margin-top: 22px;
  }

  h1 {
    font-size: 28px;
  }

  .login-panel,
  .form-grid,
  .info-grid,
  .metric,
  .columns > div {
    box-shadow: none;
  }

  .toolbar,
  .detail-head {
    align-items: flex-start;
  }

  .toolbar-actions,
  .inline-form,
  .actions {
    width: 100%;
    justify-content: flex-start;
  }

  .inline-form input,
  .inline-form button,
  .toolbar-actions .button-link,
  .actions .button-link,
  .actions button {
    width: 100%;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  th,
  td {
    padding: 10px 12px;
  }
}
