:root {
  --bg: #eef1f4;
  --panel: #1f3a5f;
  --accent: #c45c26;
  --text: #1a1a1a;
  --muted: #5a6570;
  --yellow: #fff3b0;
}

* { box-sizing: border-box; }

html[lang="zh"] body {
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
}

html[lang="ja"] body {
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
}

body {
  margin: 0;
  font-family: "Hiragino Sans", "Noto Sans JP", "Noto Sans SC", "Yu Gothic", sans-serif;
  background:
    radial-gradient(1200px 400px at 10% -10%, #d9e6f5 0%, transparent 60%),
    radial-gradient(900px 360px at 100% 0%, #f3e2d4 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background: linear-gradient(105deg, #1f3a5f, #2f5d8c 55%, #3a6f7c);
  color: #fff;
}

.topbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  padding: 10px 16px;
}

.topbar-row-nav {
  border-bottom: 1px solid #ffffff28;
}

.topbar-row-filters {
  align-items: end;
  min-height: 58px;
}

.topbar-row-filters.hidden {
  display: none;
}

.brand {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-right: 8px;
}

.env-banner {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: #c62828;
  color: #fff;
  border: 1px solid #ffcdd2;
}

.env-banner.hidden {
  display: none;
}

body.env-dev .topbar {
  background: linear-gradient(105deg, #5c1a1a, #8b2e2e 55%, #a0452c);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.lang-switch {
  display: inline-flex;
  border: 1px solid #ffffff66;
  border-radius: 6px;
  overflow: hidden;
}

.lang-switch button {
  border-radius: 0;
  background: #ffffff1e;
  padding: 6px 10px;
  font-size: 12px;
}

.lang-switch button.active {
  background: var(--accent);
}

.lang-switch-light {
  align-self: flex-end;
  border-color: #1f3a5f44;
}

.lang-switch-light button {
  background: #1f3a5f14;
  color: #1f3a5f;
}

.lang-switch-light button.active {
  background: var(--accent);
  color: #fff;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.user-bar.hidden {
  display: none;
}

.user-bar #userLabel {
  opacity: 0.95;
  white-space: nowrap;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 24, 40, 0.55);
}

.login-overlay.hidden {
  display: none;
}

.busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 24, 40, 0.35);
}

.busy-overlay.hidden {
  display: none;
}

.busy-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 28px;
  border-radius: 10px;
  background: #fff;
  color: #1a1a1a;
}

.busy-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #d5dde6;
  border-top-color: #c45c26;
  border-radius: 50%;
  animation: busy-spin 0.8s linear infinite;
}

.busy-text {
  font-size: 14px;
}

@keyframes busy-spin {
  to { transform: rotate(360deg); }
}

.login-card {
  width: min(360px, calc(100vw - 32px));
  padding: 24px 22px 20px;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card h2 {
  margin: 0 0 4px;
  font-size: 1.2rem;
  color: #1f3a5f;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: #334155;
}

.login-card input {
  padding: 8px 10px;
  border: 1px solid #cfd6dd;
  border-radius: 4px;
  font-size: 14px;
}

.login-card #btnLogin {
  background: var(--accent);
  margin-top: 4px;
}

.login-error {
  min-height: 18px;
  font-size: 13px;
  color: #b00020;
}

.page-nav {
  display: inline-flex;
  border: 1px solid #ffffff66;
  border-radius: 6px;
  overflow: hidden;
}

.page-nav button {
  border-radius: 0;
  background: #ffffff1e;
}

.page-nav button.active {
  background: var(--accent);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: end;
}

.filters-panel.hidden {
  display: none;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  opacity: 0.95;
}

.filters select,
.filters input[type="number"] {
  min-width: 120px;
  padding: 6px 8px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
}

.filters select:disabled {
  opacity: 0.8;
  cursor: not-allowed;
}

button,
.file-btn {
  border: none;
  border-radius: 4px;
  padding: 8px 12px;
  cursor: pointer;
  background: #ffffff22;
  color: #fff;
  font-size: 13px;
}

button.primary { background: var(--accent); }
button:hover, .file-btn:hover { filter: brightness(1.08); }

.status {
  display: none;
}

.sheet-title {
  padding: 4px 16px 8px;
  font-size: 1.1rem;
  font-weight: 600;
}

#grid {
  margin: 0 12px 24px;
  background: #fff;
  border: 1px solid #cfd6dd;
  overflow: auto;
  max-height: calc(100vh - 200px);
}

#grid.hidden,
.sheet-title.hidden,
.account-panel.hidden,
#adminUsersSection.hidden,
#editUserForm.hidden {
  display: none;
}

.account-panel {
  margin: 0 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 1100px;
}

.account-card {
  background: #fff;
  border: 1px solid #cfd6dd;
  border-radius: 8px;
  padding: 16px 18px 18px;
}

.account-card h2,
.account-card h3 {
  margin: 0 0 12px;
  color: #1f3a5f;
}

.account-card h3 {
  font-size: 1rem;
}

.account-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 420px;
}

.account-form-grid {
  max-width: none;
}

.account-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: #334155;
}

.account-form input[type="text"],
.account-form input[type="password"],
.account-form input:not([type="checkbox"]),
.account-form select {
  padding: 8px 10px;
  border: 1px solid #cfd6dd;
  border-radius: 4px;
  font-size: 14px;
}

.account-form button.primary {
  align-self: flex-start;
  background: var(--accent);
}

.account-form .form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.account-form .form-actions button {
  background: #1f3a5f;
  color: #fff;
}

.check-row {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
}

.form-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.dept-checks-label {
  font-size: 13px;
  color: #334155;
  margin-bottom: 6px;
}

.dept-check-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.dept-check-list label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.user-table-wrap {
  overflow: auto;
  margin: 16px 0;
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.user-table th,
.user-table td {
  border-bottom: 1px solid #e5e9ee;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.user-table th {
  background: #e8eef5;
  color: #1f3a5f;
}

.user-table button {
  background: #1f3a5f;
  color: #fff;
  padding: 4px 10px;
}

.handsontable td.htDimmed {
  background: #f7f7f7;
  color: #666;
}

.handsontable td.derived-cell {
  background: var(--yellow) !important;
}

.handsontable td.unsaved-cell {
  background: #cfe8ff !important;
}

.handsontable td.section-cell {
  background: #1f3a5f !important;
  color: #fff !important;
  font-weight: 700;
}

.handsontable thead th {
  background: #e8eef5 !important;
  font-weight: 600;
}

.handsontable td.month-block-left,
.handsontable th.month-block-left {
  border-left: 2px solid #111 !important;
}

.handsontable td.month-block-right,
.handsontable th.month-block-right {
  border-right: 2px solid #111 !important;
}

.handsontable td.month-block-top,
.handsontable th.month-block-top {
  border-top: 2px solid #111 !important;
}

.handsontable td.month-block-bottom,
.handsontable th.month-block-bottom {
  border-bottom: 2px solid #111 !important;
}

.handsontable td.kind-header-cell {
  position: relative;
  padding: 2px 18px 2px 4px !important;
  vertical-align: middle;
}

.kind-header-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
}

.kind-header-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-hide-btn {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 14px;
  height: 14px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 2px;
  background: transparent;
  color: #7a8694;
  font-size: 12px;
  line-height: 14px;
  cursor: pointer;
}

.col-hide-btn:hover {
  background: #dce3ea;
  color: #b00020;
}

.handsontable td.row-hide-cell {
  position: relative;
  padding-left: 16px !important;
}

.row-hide-btn {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 14px;
  height: 14px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 2px;
  background: transparent;
  color: #7a8694;
  font-size: 12px;
  line-height: 14px;
  cursor: pointer;
}

.row-hide-btn:hover {
  background: #dce3ea;
  color: #b00020;
}
