:root {
  --bg: #f4efe4;
  --panel: #fffaf0;
  --panel-strong: #f0e1bf;
  --text: #2d2418;
  --muted: #76644b;
  --accent: #2f6b3b;
  --accent-dark: #1f4a28;
  --danger: #a63d2d;
  --danger-dark: #7d2d21;
  --border: #d7c7a1;
  --shadow: 0 18px 40px rgba(77, 57, 27, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(240, 225, 191, 0.8), transparent 38%),
    linear-gradient(180deg, #f7f2e8 0%, var(--bg) 100%);
}

.app {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 56px;
}

.hero {
  padding: 24px 4px;
}

.hero-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

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

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.78rem;
  color: var(--muted);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(2rem, 4vw, 3.3rem);
}

.intro {
  max-width: 640px;
  color: var(--muted);
  line-height: 1.6;
}

.app-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
}

.login-panel {
  width: min(520px, 100%);
  margin: 0 auto;
  padding: 32px;
  background:
    linear-gradient(180deg, rgba(255, 250, 240, 0.98), rgba(255, 247, 230, 0.94)),
    radial-gradient(circle at top right, rgba(47, 107, 59, 0.08), transparent 36%);
}

.logout-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  min-height: 48px;
}

.admin-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 18px;
  border-radius: 14px;
  background: linear-gradient(135deg, #efe0b7, #f8edd0);
  border: 1px solid rgba(125, 96, 43, 0.22);
  color: #5d4721;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(93, 71, 33, 0.12);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 18px;
  border-radius: 14px;
  background: rgba(255, 250, 240, 0.9);
  border: 1px solid rgba(47, 107, 59, 0.2);
  color: var(--accent-dark);
  text-decoration: none;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(47, 107, 59, 0.1);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.logout-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 18px;
  border-radius: 14px;
  background: linear-gradient(135deg, #8a2f24, #b64533);
  color: #fff;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(166, 61, 45, 0.22);
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

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

.admin-link:hover {
  transform: translateY(-1px);
  background: linear-gradient(135deg, #e4cf95, #f1dfae);
  box-shadow: 0 14px 28px rgba(93, 71, 33, 0.18);
}

.back-link:hover {
  transform: translateY(-1px);
  background: #fffdf7;
  border-color: rgba(47, 107, 59, 0.34);
  box-shadow: 0 14px 28px rgba(47, 107, 59, 0.14);
}

.logout-button:hover {
  background: linear-gradient(135deg, #7b2a20, #a63d2d);
}

.panel {
  background: rgba(255, 250, 240, 0.95);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.controls {
  display: grid;
  gap: 24px;
  padding: 24px;
}

.summary-card {
  display: inline-flex;
  align-items: baseline;
  gap: 12px;
  width: fit-content;
  padding: 18px 22px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--panel-strong), #fff6de);
}

.summary-label,
.summary-unit {
  color: var(--muted);
}

#totalAmount {
  font-size: clamp(2rem, 5vw, 3rem);
}

.coal-form {
  display: grid;
  gap: 10px;
}

.remove-form {
  padding-top: 4px;
  border-top: 1px solid rgba(215, 199, 161, 0.8);
}

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

.coal-form label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.file-tools {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.file-tools-title {
  margin-bottom: 0;
  font-weight: 700;
}

.file-status {
  margin-bottom: 0;
  color: var(--muted);
  min-height: 1.5em;
}

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

.form-row,
.action-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

input[type="number"],
input[type="text"],
input[type="password"],
select {
  flex: 1 1 240px;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 1rem;
  background: #fffdf7;
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
}

input:focus,
select:focus {
  outline: 2px solid rgba(47, 107, 59, 0.22);
  outline-offset: 2px;
  border-color: var(--accent);
}

button {
  border: 0;
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.primary-btn,
.secondary-btn {
  background: var(--accent);
  color: #fff;
}

.primary-btn:hover,
.secondary-btn:hover {
  background: var(--accent-dark);
}

.danger-btn {
  background: var(--danger);
  color: #fff;
}

.danger-btn:hover {
  background: var(--danger-dark);
}

.inventory {
  margin-top: 24px;
  padding: 24px;
}

.admin-users {
  display: grid;
  gap: 16px;
}

.admin-accordion {
  border: 0;
}

.admin-accordion-summary {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  cursor: pointer;
  list-style: none;
}

.admin-accordion-summary::-webkit-details-marker {
  display: none;
}

.admin-accordion-summary::after {
  content: "+";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: #f4ead1;
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 700;
  flex-shrink: 0;
}

.admin-accordion[open] .admin-accordion-summary::after {
  content: "-";
}

.admin-accordion-content {
  margin-top: 18px;
}

.audit-log {
  display: grid;
  gap: 14px;
}

.audit-log-card {
  display: grid;
  gap: 8px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fffdf8;
}

.audit-log-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.audit-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.audit-add {
  background: rgba(47, 107, 59, 0.14);
  color: var(--accent-dark);
}

.audit-delete {
  background: rgba(166, 61, 45, 0.14);
  color: var(--danger-dark);
}

.audit-remove {
  background: rgba(173, 118, 26, 0.16);
  color: #8a6117;
}

.audit-update,
.audit-merge {
  background: rgba(54, 96, 147, 0.14);
  color: #2b527f;
}

.admin-user-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fffdf8;
}

.admin-user-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.password-hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.inventory-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
}

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

.clear-log-button {
  min-height: 42px;
  padding: 10px 14px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.filters label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.entry-count {
  color: var(--muted);
  font-weight: 600;
}

.summary-by-type {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
  align-items: flex-start;
}

.summary-pill {
  width: fit-content;
  max-width: 100%;
  padding: 10px 14px;
  border-radius: 999px;
  background: #f4ead1;
  color: var(--text);
  font-weight: 600;
}

.empty-state {
  padding: 22px;
  border: 1px dashed var(--border);
  border-radius: 16px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.6);
}

.coal-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 12px;
}

.coal-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: #fffdf8;
}

.coal-item-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.coal-item-text {
  flex: 1;
  min-width: 0;
}

.entry-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.entry-actions button {
  min-width: 110px;
}

.coal-value {
  font-size: 1.1rem;
  font-weight: 700;
}

.coal-date {
  color: var(--muted);
  font-size: 0.92rem;
}

.coal-meta {
  color: var(--text);
  font-size: 0.95rem;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

@media (max-width: 640px) {
  .app {
    width: min(100% - 20px, 920px);
    padding-top: 16px;
    padding-bottom: 28px;
  }

  .controls,
  .inventory {
    padding: 16px;
  }

  .hero-top {
    flex-direction: column;
  }

  .hero-actions {
    width: 100%;
    justify-content: stretch;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  input[type="number"],
  input[type="text"],
  input[type="password"],
  select {
    padding: 11px 12px;
    font-size: 0.96rem;
    border-radius: 12px;
  }

  .coal-form {
    gap: 8px;
  }

  .coal-form label {
    margin-bottom: 4px;
    font-size: 0.95rem;
  }

  #coalForm .form-row {
    align-items: stretch;
    gap: 8px;
  }

  #removeForm .form-row {
    align-items: stretch;
    gap: 8px;
  }

  #coalAmount {
    flex: 0 1 auto;
    width: 100%;
    max-width: 100%;
    padding: 9px 12px;
    font-size: 0.92rem;
    line-height: 1.2;
  }

  #removeAmount {
    flex: 0 1 auto;
    width: 100%;
    max-width: 100%;
    padding: 9px 12px;
    font-size: 0.92rem;
    line-height: 1.2;
  }

  #coalForm .primary-btn {
    padding: 10px 14px;
  }

  #removeForm .danger-btn {
    padding: 10px 14px;
  }

  .summary-card {
    width: 100%;
    justify-content: space-between;
  }

  .form-row,
  .action-row {
    flex-direction: column;
  }

  .form-row > *,
  .action-row > * {
    width: 100%;
  }

  .logout-link,
  .admin-link,
  .back-link,
  .logout-button,
  button {
    width: 100%;
  }

  button {
    padding: 12px 14px;
    font-size: 0.96rem;
    border-radius: 12px;
  }

  .login-panel {
    padding: 22px 18px;
    border-radius: 22px;
  }

  .summary-pill {
    width: 100%;
    border-radius: 18px;
  }

  .coal-item,
  .inventory-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .inventory-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .admin-accordion-summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .coal-item-content {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .entry-actions {
    width: 100%;
    flex-direction: column;
  }

  .audit-log-top {
    align-items: flex-start;
    flex-direction: column;
  }
}
