:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --surface: #ffffff;
  --surface-strong: #eef4e7;
  --line: #d9dfd0;
  --text: #1d261b;
  --muted: #66705f;
  --primary: #2f6f3e;
  --primary-dark: #235631;
  --danger: #b3322a;
  --danger-soft: #f9e7e4;
  --warning: #8a5a00;
  --shadow: 0 14px 36px rgba(44, 55, 36, 0.12);
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button, input, select { font: inherit; }

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: #fff;
  background: var(--primary);
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

button:active { transform: translateY(1px); }
button.secondary { color: var(--primary-dark); background: var(--surface-strong); border: 1px solid var(--line); }
button.danger { color: var(--danger); background: var(--danger-soft); border: 1px solid #e8b5ad; }
button.ghost { color: var(--muted); background: transparent; border: 1px solid var(--line); }
button[disabled] { opacity: 0.55; cursor: not-allowed; }

.danger-text { color: var(--danger); }

.app {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 18px 14px 36px;
}

.topbar { display: grid; gap: 4px; margin-bottom: 16px; }
h1 { margin: 0; font-size: clamp(24px, 7vw, 36px); line-height: 1.15; letter-spacing: 0; }
h2 { margin: 0; font-size: 18px; letter-spacing: 0; }
.subtitle { margin: 0; color: var(--muted); font-size: 14px; }
.today { margin: 2px 0 0; color: var(--primary-dark); font-size: 14px; font-weight: 800; }

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.panel-title, .userbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.summary strong { display: block; overflow-wrap: anywhere; font-size: clamp(20px, 6vw, 28px); line-height: 1.1; }

label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 700; }

input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 111, 62, 0.15); }
input::placeholder { color: #9ca694; opacity: 1; }
input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { margin: 0; -webkit-appearance: none; }

.auth-form, .form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.auth-form { grid-template-columns: 1fr 1fr auto; align-items: end; }
.helper { margin: 10px 0 0; color: var(--muted); font-size: 13px; }

.role-badge {
  display: inline-flex;
  margin-left: 6px;
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--primary-dark);
  background: var(--surface-strong);
  font-size: 12px;
  font-weight: 800;
}

.user-actions, .form-actions, .toolbar, .file-actions, .row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.form-actions { margin-top: 12px; }
.form-actions button { flex: 1 1 130px; }
.toolbar { align-items: stretch; justify-content: space-between; margin-bottom: 12px; }
.file-actions { flex: 1 1 100%; justify-content: stretch; }
.file-actions button, .file-actions .file-label { flex: 1 1 150px; }

.file-label {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-dark);
  background: var(--surface-strong);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.file-label input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.notice {
  display: none;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  color: var(--primary-dark);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  font-size: 14px;
}

.notice.show { display: block; }
.notice.warn { color: var(--warning); background: #fff7df; border-color: #ebd38d; }

.section-caption {
  margin: 0 0 10px;
  border: 2px solid #b8c9a7;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--primary-dark);
  background: #e8f2df;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.2;
}

.date-total-section { margin: 12px 0 14px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.scroll-table { max-height: 360px; overflow: auto; scrollbar-color: var(--primary) #e4eadc; scrollbar-width: auto; }
.scroll-table::-webkit-scrollbar { width: 12px; height: 12px; }
.scroll-table::-webkit-scrollbar-track { background: #e4eadc; }
.scroll-table::-webkit-scrollbar-thumb { background: var(--primary); border: 2px solid #e4eadc; border-radius: 8px; }

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: #fff;
}

th, td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #f2f6ed;
  color: #3d4938;
  font-size: 13px;
  z-index: 1;
}

td.number, th.number { text-align: right; }
tr:last-child td { border-bottom: 0; }
.row-actions { justify-content: flex-end; flex-wrap: nowrap; }
.row-actions button { min-height: 38px; padding: 0 10px; font-size: 13px; }
.empty { padding: 28px 10px; color: var(--muted); text-align: center; }

.help { display: grid; gap: 10px; color: var(--muted); font-size: 14px; }
.help pre {
  overflow-x: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f9faf6;
  color: var(--text);
  font-size: 13px;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(20, 26, 18, 0.56);
  z-index: 20;
}

.confirm-overlay.show { display: flex; }
.confirm-box {
  width: min(100%, 420px);
  border: 3px solid var(--danger);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
}

.confirm-warning { margin: 0 0 14px; color: var(--danger); font-size: 22px; font-weight: 900; line-height: 1.25; }
.confirm-step { margin: 0 0 16px; color: var(--muted); font-size: 14px; font-weight: 800; }
.confirm-actions { display: flex; gap: 8px; }
.confirm-actions button { flex: 1 1 0; }
.confirm-actions .default-cancel {
  color: #fff;
  background: var(--primary);
  border: 2px solid var(--primary-dark);
  box-shadow: 0 0 0 3px rgba(47, 111, 62, 0.22);
}

@media (max-width: 720px) {
  .app { padding: 14px 10px 28px; }
  .summary-grid, .form-grid, .auth-form { grid-template-columns: 1fr; }
  .panel { padding: 12px; }
  .panel-title, .userbar { align-items: flex-start; flex-direction: column; }
  table { min-width: 0; }
  thead { display: none; }
  tbody, tr, td { display: block; }
  tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  tr:last-child { border-bottom: 0; }
  td {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 8px;
    border-bottom: 0;
    padding: 7px 10px;
    white-space: normal;
  }
  td::before { content: attr(data-label); color: var(--muted); font-weight: 800; }
  td.number { text-align: left; }
  td.actions-cell { display: block; }
  td.actions-cell::before { display: none; }
  .row-actions { justify-content: stretch; }
  .row-actions button { flex: 1 1 0; }
}
