:root {
  --navy: #0f2744;
  --navy-light: #1a3a5c;
  --navy-dark: #0a1a2e;
  --yellow: #e8b923;
  --yellow-hover: #f5c842;
  --white: #f8f9fa;
  --gray: #8b9cb3;
  --error: #e74c3c;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--navy-dark);
  color: var(--white);
  min-height: 100vh;
  line-height: 1.5;
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  background: linear-gradient(160deg, var(--navy-dark) 0%, var(--navy) 50%, var(--navy-light) 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--navy);
  border: 1px solid rgba(232, 185, 35, 0.2);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}

.login-logo {
  display: block;
  width: 80px;
  height: auto;
  margin: 0 auto 1.25rem;
}

.login-title {
  font-size: 1.125rem;
  font-weight: 600;
  text-align: center;
  color: var(--yellow);
  letter-spacing: 0.02em;
  margin-bottom: 0.25rem;
}

.login-subtitle {
  font-size: 0.8125rem;
  text-align: center;
  color: var(--gray);
  margin-bottom: 2rem;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.4rem;
}

.form-group input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: 0.9375rem;
  color: var(--white);
  background: var(--navy-dark);
  border: 1px solid rgba(139, 156, 179, 0.3);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--yellow);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 480px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

.error-msg {
  font-size: 0.8125rem;
  color: var(--error);
  margin-bottom: 1rem;
  display: none;
}

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

.success-msg {
  font-size: 0.875rem;
  color: var(--yellow);
  text-align: center;
  margin-bottom: 1.25rem;
}

.setup-msg {
  display: none;
  font-size: 0.8125rem;
  text-align: center;
  margin-bottom: 1rem;
  padding: 0.65rem 0.75rem;
  border-radius: 6px;
  line-height: 1.4;
}

.setup-msg.visible.ok {
  display: block;
  color: #b8f0c8;
  background: rgba(46, 204, 113, 0.12);
  border: 1px solid rgba(46, 204, 113, 0.35);
}

.setup-msg.visible.err {
  display: block;
  color: #ffb4ab;
  background: rgba(231, 76, 60, 0.12);
  border: 1px solid rgba(231, 76, 60, 0.35);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  width: 100%;
  background: var(--yellow);
  color: var(--navy-dark);
}

.btn-primary:hover {
  background: var(--yellow-hover);
}

.btn-secondary {
  width: 100%;
  background: transparent;
  color: var(--gray);
  border: 1px solid rgba(139, 156, 179, 0.4);
}

.btn-secondary:hover {
  border-color: var(--yellow);
  color: var(--yellow);
}

.hidden {
  display: none;
}

body.is-loading {
  cursor: wait;
}

body.is-loading .btn {
  pointer-events: none;
  opacity: 0.7;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  max-width: 90%;
  padding: 0.875rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--navy-dark);
  background: var(--yellow);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  transition: opacity 0.3s, transform 0.3s;
}

.toast.hidden {
  display: none;
}

.toast.visible {
  display: block;
  animation: toast-in 0.3s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Dashboard */
.dashboard {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.875rem 1.5rem;
  background: var(--navy);
  border-bottom: 2px solid var(--yellow);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.header-logo {
  width: 40px;
  height: auto;
}

.header-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--yellow);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-accent {
  background: var(--yellow);
  color: var(--navy-dark);
}

.btn-accent:hover {
  background: var(--yellow-hover);
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
}

.btn-inline {
  width: auto;
}

.btn-secondary.btn-sm,
.btn-secondary.btn-inline {
  width: auto;
}

.project-tabs {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  background: var(--navy-dark);
  border-bottom: 1px solid rgba(232, 185, 35, 0.15);
  min-height: 52px;
  align-items: center;
}

.project-tab {
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--gray);
  background: var(--navy);
  border: 1px solid rgba(139, 156, 179, 0.3);
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  white-space: nowrap;
}

.project-tab:hover {
  color: var(--yellow);
  border-color: rgba(232, 185, 35, 0.5);
}

.project-tab.active {
  color: var(--navy-dark);
  background: var(--yellow);
  border-color: var(--yellow);
}

.dashboard-main {
  flex: 1;
  padding: 1.5rem;
}

.empty-state {
  text-align: center;
  padding: 4rem 1.5rem;
  color: var(--gray);
  font-size: 0.9375rem;
}

.empty-state strong {
  color: var(--yellow);
}

.table-panel {
  background: var(--navy);
  border: 1px solid rgba(232, 185, 35, 0.15);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(232, 185, 35, 0.15);
}

.table-panel-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--yellow);
}

.table-panel-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-danger {
  background: transparent;
  color: #f08080;
  border: 1px solid rgba(240, 128, 128, 0.45);
}

.btn-danger:hover {
  background: rgba(231, 76, 60, 0.15);
  border-color: #f08080;
  color: #ff9e9e;
}

.btn-xs {
  padding: 0.3rem 0.55rem;
  font-size: 0.75rem;
}

.cell-actions {
  text-align: right;
  white-space: nowrap;
}

.data-table th:last-child,
.data-table .cell-actions {
  width: 140px;
}

.cell-actions .btn + .btn {
  margin-left: 0.35rem;
}

.btn-edit {
  background: transparent;
  color: var(--yellow);
  border: 1px solid rgba(232, 185, 35, 0.45);
}

.btn-edit:hover {
  background: rgba(232, 185, 35, 0.12);
  border-color: var(--yellow);
}

.modal-box-wide {
  max-width: 520px;
}

.receipt-modal-body {
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.modal .form-row .form-group {
  margin-bottom: 1rem;
}

.amount-section {
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--navy-dark);
  border: 1px solid rgba(232, 185, 35, 0.15);
  border-radius: var(--radius);
}

.amount-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.amount-section-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--yellow);
}

.btn-add-line {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1;
  color: var(--navy-dark);
  background: var(--yellow);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s;
}

.btn-add-line:hover {
  background: var(--yellow-hover);
}

.amount-lines {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.amount-line {
  display: grid;
  grid-template-columns: 1fr 100px 32px;
  gap: 0.5rem;
  align-items: start;
}

.amount-line input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  color: var(--white);
  background: var(--navy);
  border: 1px solid rgba(139, 156, 179, 0.3);
  border-radius: 6px;
  outline: none;
}

.amount-line input:focus {
  border-color: var(--yellow);
}

.btn-remove-line {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  color: var(--gray);
  background: none;
  border: 1px solid rgba(139, 156, 179, 0.3);
  border-radius: 6px;
  cursor: pointer;
}

.btn-remove-line:hover {
  color: var(--error);
  border-color: rgba(231, 76, 60, 0.5);
}

.btn-remove-line.hidden {
  visibility: hidden;
  pointer-events: none;
}

.receipt-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  margin-bottom: 0.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--yellow);
  border-top: 1px solid rgba(232, 185, 35, 0.2);
}

.amount-breakdown {
  font-size: 0.75rem;
  color: var(--gray);
  margin-top: 0.15rem;
  line-height: 1.4;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead {
  background: var(--navy-dark);
}

.data-table th {
  text-align: left;
  padding: 0.75rem 1.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--yellow);
  border-bottom: 1px solid rgba(232, 185, 35, 0.2);
}

.data-table td {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid rgba(139, 156, 179, 0.15);
  color: var(--white);
}

.data-table tbody tr.row-clickable {
  cursor: pointer;
}

.data-table tbody tr.row-clickable:hover td {
  background: rgba(232, 185, 35, 0.08);
}

.data-table .empty-row td {
  text-align: center;
  color: var(--gray);
  font-style: italic;
  padding: 2.5rem 1.25rem;
}

.data-table .empty-row:hover td {
  background: transparent;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(10, 26, 46, 0.75);
}

.modal.open {
  display: flex;
}

.modal-box {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--navy);
  border: 1px solid rgba(232, 185, 35, 0.25);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.modal-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--yellow);
  margin-bottom: 0.25rem;
}

.modal-subtitle {
  font-size: 0.8125rem;
  color: var(--gray);
  margin-bottom: 1.5rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  color: var(--gray);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

.modal-close:hover {
  color: var(--yellow);
  background: rgba(232, 185, 35, 0.1);
}

.modal .form-group {
  margin-bottom: 1rem;
}

.modal .btn-primary {
  width: auto;
}

.modal-box-receipt {
  max-width: 420px;
  padding: 1.25rem;
  max-height: 90vh;
  overflow-y: auto;
}

.receipt-select-label {
  font-size: 0.75rem;
  color: var(--gray);
  margin-bottom: 0.65rem;
}

.receipt-item-selector {
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--navy-dark);
  border: 1px solid rgba(232, 185, 35, 0.2);
  border-radius: var(--radius);
}

.receipt-item-option {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0;
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--white);
  border-bottom: 1px solid rgba(139, 156, 179, 0.15);
}

.receipt-item-option:last-child {
  border-bottom: none;
}

.receipt-item-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--yellow);
  cursor: pointer;
  flex-shrink: 0;
}

.receipt-item-option .item-detail {
  flex: 1;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.receipt-item-option .item-reason {
  color: var(--white);
}

.receipt-item-option .item-amount {
  color: var(--yellow);
  font-weight: 600;
  white-space: nowrap;
}

.receipt-selector-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.receipt-selector-actions button {
  padding: 0.25rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--gray);
  background: none;
  border: 1px solid rgba(139, 156, 179, 0.35);
  border-radius: 4px;
  cursor: pointer;
}

.receipt-selector-actions button:hover {
  color: var(--yellow);
  border-color: var(--yellow);
}

.receipt-view-actions {
  justify-content: center;
  margin-top: 1rem;
}

.receipt-document {
  background: #fff;
  color: #1a1a1a;
  padding: 2rem 1.75rem;
  border-radius: 4px;
  font-size: 0.875rem;
  line-height: 1.5;
}

.receipt-document .rd-logo {
  width: 72px;
  height: auto;
  display: block;
  margin: 0 auto 0.75rem;
}

.receipt-document .rd-company {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: #0f2744;
  margin-bottom: 0.15rem;
}

.receipt-document .rd-subtitle {
  text-align: center;
  font-size: 0.6875rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #666;
  margin-bottom: 1rem;
}

.receipt-document .rd-divider {
  border: none;
  border-top: 2px solid #0f2744;
  margin: 1rem 0;
}

.receipt-document .rd-divider-gold {
  border: none;
  border-top: 3px solid #e8b923;
  margin: 0.75rem 0 1rem;
}

.receipt-document .rd-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.8125rem;
}

.receipt-document .rd-meta dt {
  color: #666;
  font-weight: 600;
}

.receipt-document .rd-meta dd {
  margin: 0;
  color: #222;
}

.receipt-document .rd-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
  font-size: 0.8125rem;
}

.receipt-document .rd-table th {
  text-align: left;
  padding: 0.5rem 0.25rem;
  border-bottom: 2px solid #0f2744;
  color: #0f2744;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.receipt-document .rd-table th:last-child,
.receipt-document .rd-table td:last-child {
  text-align: right;
}

.receipt-document .rd-table td {
  padding: 0.45rem 0.25rem;
  border-bottom: 1px solid #eee;
}

.receipt-document .rd-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  color: #0f2744;
}

.receipt-document .rd-footer {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: #888;
}

/* ——— Mobile & tablet responsive ——— */
html {
  -webkit-text-size-adjust: 100%;
}

body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.toast {
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
}

@media (max-width: 900px) {
  .header {
    padding: 0.75rem 1rem;
  }

  .dashboard-main {
    padding: 1rem;
  }

  .project-tabs {
    padding: 0.75rem 1rem;
  }
}

@media (max-width: 768px) {
  .header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .header-brand {
    justify-content: center;
  }

  .header-actions {
    flex-direction: column;
    width: 100%;
    gap: 0.5rem;
  }

  .header-actions .btn {
    width: 100%;
    min-height: 44px;
  }

  .table-panel-header {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem;
    gap: 0.75rem;
  }

  .table-panel-title {
    font-size: 1rem;
    text-align: center;
  }

  .table-panel-actions {
    flex-direction: column;
    width: 100%;
    gap: 0.5rem;
  }

  .table-panel-actions .btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .project-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 0.5rem;
    gap: 0.4rem;
  }

  .project-tab {
    flex-shrink: 0;
    min-height: 40px;
  }

  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal.open {
    align-items: flex-end;
  }

  .modal-box,
  .modal-box-wide,
  .modal-box-receipt {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    border-radius: 12px 12px 0 0;
    margin: 0;
    padding: 1.25rem 1rem calc(1.25rem + env(safe-area-inset-bottom));
  }

  .receipt-modal-body {
    max-height: 55vh;
  }

  .modal-actions {
    flex-direction: column-reverse;
    gap: 0.5rem;
  }

  .modal-actions .btn {
    width: 100%;
    min-height: 44px;
  }

  .modal .btn-primary {
    width: 100%;
  }

  .receipt-document {
    padding: 1.25rem 1rem;
    font-size: 0.8125rem;
  }

  .receipt-document .rd-logo {
    width: 56px;
  }

  .receipt-item-option .item-detail {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
  }
}

@media (max-width: 640px) {
  .login-card {
    padding: 2rem 1.25rem;
  }

  .login-title {
    font-size: 1rem;
  }

  .empty-state {
    padding: 2.5rem 1rem;
    font-size: 0.875rem;
  }

  .table-wrap {
    overflow-x: visible;
  }

  .data-table thead {
    display: none;
  }

  .data-table tbody tr.row-clickable {
    display: block;
    margin-bottom: 0.75rem;
    background: var(--navy-dark);
    border: 1px solid rgba(232, 185, 35, 0.2);
    border-radius: var(--radius);
    overflow: hidden;
  }

  .data-table tbody tr.row-clickable:hover td {
    background: transparent;
  }

  .data-table tbody tr.row-clickable:active {
    background: rgba(232, 185, 35, 0.06);
  }

  .data-table td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.65rem 1rem;
    border-bottom: 1px solid rgba(139, 156, 179, 0.12);
    text-align: right;
  }

  .data-table td:last-child {
    border-bottom: none;
  }

  .data-table td::before {
    content: attr(data-label);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--yellow);
    flex-shrink: 0;
    text-align: left;
  }

  .data-table td[data-label="#"]::before {
    content: "#";
  }

  .data-table .cell-actions {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    white-space: normal;
  }

  .data-table .cell-actions::before {
    margin-bottom: 0.25rem;
  }

  .data-table .cell-actions .btn {
    width: 100%;
    min-height: 40px;
    margin-left: 0 !important;
    margin-top: 0.35rem;
  }

  .data-table .empty-row {
    display: block;
  }

  .data-table .empty-row td {
    display: block;
    text-align: center;
    padding: 2rem 1rem;
  }

  .data-table .empty-row td::before {
    display: none;
  }

  .amount-line {
    grid-template-columns: 1fr 88px 36px;
  }

  .amount-line input {
    font-size: 16px;
  }

  .form-group input {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .header-title {
    font-size: 0.875rem;
  }

  .header-logo {
    width: 32px;
  }

  .amount-line {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: 0.4rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(139, 156, 179, 0.15);
  }

  .amount-line:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }

  .amount-line .btn-remove-line {
    justify-self: start;
  }

  .receipt-document .rd-meta {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .receipt-document .rd-meta dt {
    margin-top: 0.5rem;
  }

  .receipt-document .rd-meta dt:first-child {
    margin-top: 0;
  }
}

@media (max-width: 380px) {
  .header-title {
    font-size: 0.8125rem;
  }

  .project-tab {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
