:root {
  --brand-green: #497e04;
  --brand-green-hover: #3a6503;
  --brand-green-light: #60b000;
  --brand-cream: #fefdd6;
  --brand-black: #000000;
  --brand-gray: #696969;
  --text-primary: #1d1d1f;
  --text-secondary: #4b5563;
  --bg-page: #f4f6fb;
  --bg-card: #ffffff;
  --border: #d1d5db;
  --border-light: #e5e7eb;
  --color-error: #b91c1c;
  --color-error-bg: #fef2f2;
  --color-error-border: #fecaca;
  --color-success: #047857;
  --color-success-bg: #ecfdf5;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
  --font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}

body {
  font-family: var(--font-family);
  background: var(--bg-page);
  color: var(--text-primary);
  margin: 0;
  padding: 0;
}

.container {
  max-width: 860px;
  margin: 40px auto;
  background: var(--bg-card);
  padding: 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

h1 {
  margin: 0 0 16px;
  font-size: 26px;
}

.subtitle {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

form {
  display: grid;
  gap: 12px;
}

label {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
  display: block;
}

input,
textarea,
button {
  font-family: var(--font-family);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand-green);
  box-shadow: 0 0 0 3px rgba(73, 126, 4, 0.15);
}

textarea {
  resize: vertical;
}

button {
  background: var(--brand-green);
  color: #ffffff;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s ease;
}

button:hover {
  background: var(--brand-green-hover);
}

button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

button.secondary {
  background: #6b7280;
}

button.secondary:hover {
  background: #4b5563;
}

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

.error {
  color: var(--color-error);
  margin-top: 8px;
}

.success {
  color: var(--color-success);
  margin-top: 8px;
}

.receipt-list {
  margin-top: 24px;
  border-top: 1px solid var(--border-light);
  padding-top: 16px;
}

.receipt-card {
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.receipt-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.receipt-actions a {
  color: var(--brand-green);
  text-decoration: none;
  font-weight: 600;
}

.receipt-actions a:hover {
  text-decoration: underline;
}

.receipt-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.btn-delete {
  background: none;
  color: var(--color-error);
  border: 1px solid var(--color-error);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-delete:hover {
  background: var(--color-error);
  color: #ffffff;
}

.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.nav a {
  color: var(--brand-green);
  text-decoration: none;
}

.receipt-view {
  max-width: 760px;
  margin: 24px auto;
  padding: 32px;
  border: 1px solid var(--border-light);
}

.receipt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--brand-green);
}

.receipt-header-img {
  max-width: 300px;
  height: auto;
}

.receipt-title {
  margin: 0;
  font-size: 28px;
  color: var(--color-error);
  letter-spacing: 2px;
}

.receipt-top-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 4px;
}

.receipt-line {
  display: flex;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 15px;
  line-height: 1.5;
}

.receipt-label {
  font-weight: 700;
  white-space: nowrap;
  min-width: 150px;
  color: var(--text-primary);
}

.receipt-value {
  color: var(--text-secondary);
  word-break: break-word;
}

.receipt-signature {
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.receipt-sig-label {
  margin-top: 4px;
  font-size: 13px;
  color: var(--brand-gray);
  font-style: italic;
}

.receipt-skeleton {
  padding: 16px 0;
}

.receipt-skeleton .skel-line {
  margin-bottom: 14px;
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  align-items: center;
}

.back-link {
  color: var(--brand-green);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.back-link:hover {
  text-decoration: underline;
}

.edit-form {
  display: grid;
  gap: 12px;
}

.edit-form input,
.edit-form textarea {
  width: 100%;
  box-sizing: border-box;
}

.edit-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

/* ── Dashboard ──────────────────────────────────────────── */

.nav-brand {
  display: flex;
  flex-direction: column;
}

.nav-brand h1 {
  margin: 0;
  font-size: 22px;
}

.nav-company {
  font-size: 13px;
  color: var(--brand-gray);
  font-style: italic;
}

.form-section {
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 4px;
}

.form-section legend {
  font-weight: 700;
  font-size: 14px;
  color: var(--brand-green);
  padding: 0 8px;
}

.form-section .form-group {
  margin-bottom: 8px;
}

.form-section .form-group:last-child {
  margin-bottom: 0;
}

.form-section input,
.form-section textarea {
  width: 100%;
  box-sizing: border-box;
}

.field-error {
  border-color: var(--color-error) !important;
  box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.1);
}

.field-hint {
  display: block;
  font-size: 12px;
  color: var(--color-error);
  margin-top: 4px;
}

.input-group {
  display: flex;
}

.input-prefix {
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  font-weight: 700;
  font-size: 14px;
  color: var(--text-secondary);
}

.input-group input {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  flex: 1;
  min-width: 0;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--brand-green);
  color: #ffffff;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  gap: 12px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
  z-index: 1000;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.toast a {
  color: #ffffff;
  text-decoration: underline;
}

/* ── Receipt list ───────────────────────────────────────── */

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.list-header h2 {
  margin: 0;
}

.search-input {
  width: 220px;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
}

.search-input:focus {
  outline: none;
  border-color: var(--brand-green);
  box-shadow: 0 0 0 3px rgba(73, 126, 4, 0.15);
}

.receipt-card {
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.receipt-card:hover {
  border-color: var(--brand-green);
  box-shadow: 0 2px 8px rgba(73, 126, 4, 0.08);
}

.receipt-info {
  flex: 1;
  min-width: 0;
}

.receipt-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.receipt-card-date {
  font-size: 13px;
  color: var(--brand-gray);
  white-space: nowrap;
}

.receipt-card-detail {
  margin-top: 4px;
  font-size: 14px;
}

.receipt-card-meta {
  display: flex;
  gap: 16px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.receipt-card-desc {
  margin-top: 6px;
  font-size: 13px;
  color: var(--brand-gray);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-footer {
  text-align: center;
  margin-top: 8px;
}

.load-more-btn {
  width: 100%;
  padding: 10px;
  font-size: 14px;
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-secondary);
}

.empty-state p {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 600;
}

.empty-sub {
  font-size: 14px;
  font-weight: 400 !important;
  color: var(--brand-gray);
}

.skeleton {
  animation: pulse 1.2s ease-in-out infinite;
  pointer-events: none;
}

.skel-line {
  height: 14px;
  background: var(--border-light);
  border-radius: 4px;
  margin-bottom: 8px;
}

.skel-wide { width: 70%; }
.skel-medium { width: 50%; }
.skel-narrow { width: 30%; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Login page ─────────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-container {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  padding: 40px 36px 36px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-top: 4px solid var(--brand-green);
}

.login-brand {
  text-align: center;
  margin-bottom: 8px;
}

.login-logo {
  max-width: 280px;
  height: auto;
  margin-bottom: 16px;
}

.login-brand h1 {
  font-size: 22px;
  margin: 0 0 4px;
  color: var(--text-primary);
}

.login-brand .login-tagline {
  font-size: 14px;
  color: var(--brand-gray);
  margin: 0 0 4px;
  font-style: italic;
}

.login-descriptor {
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-light);
}

.login-container .form-group {
  margin-bottom: 4px;
}

.password-wrapper {
  position: relative;
}

.password-wrapper input {
  width: 100%;
  padding-right: 44px;
  box-sizing: border-box;
}

.password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  color: var(--brand-gray);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.password-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-page);
}

.login-container input {
  width: 100%;
  box-sizing: border-box;
}

.login-container button[type="submit"] {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  margin-top: 8px;
}

.alert-error {
  margin-top: 16px;
  padding: 10px 14px;
  background: var(--color-error-bg);
  border: 1px solid var(--color-error-border);
  border-radius: var(--radius-sm);
  color: var(--color-error);
  font-size: 14px;
  display: none;
}

.alert-error.visible {
  display: block;
}

/* ── Print ──────────────────────────────────────────────── */

@media print {
  body {
    background: #ffffff;
  }

  .container {
    box-shadow: none;
    margin: 0;
    padding: 0;
    max-width: none;
  }

  .actions,
  .nav,
  .receipt-list,
  .back-link {
    display: none !important;
  }

  .receipt-view {
    border: none;
    padding: 0;
    margin: 0;
  }

  .receipt-header {
    border-bottom-color: #000;
  }

  .receipt-line {
    border-bottom-color: #ccc;
  }
}

/* ── Responsive ─────────────────────────────────────────── */

@media (max-width: 600px) {
  .container {
    margin: 16px;
    padding: 20px;
  }

  .receipt-header {
    flex-direction: column;
    text-align: center;
    gap: 12px;
  }

  .receipt-header-img {
    max-width: 100%;
  }

  .receipt-top-row {
    grid-template-columns: 1fr;
  }

  .receipt-line {
    flex-direction: column;
    gap: 2px;
  }

  .receipt-label {
    min-width: auto;
  }

  .search-input {
    width: 100%;
  }

  .list-header {
    flex-direction: column;
    align-items: stretch;
  }

  .login-container {
    padding: 28px 20px 24px;
  }

  .login-logo {
    max-width: 220px;
  }
}
