*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --teal: #0d9488;
  --teal-dark: #0f766e;
  --green: #16a34a;
  --red: #dc2626;
  --bg: #f0fdfa;
  --card: #ffffff;
  --text: #134e4a;
  --muted: #5eead4;
  --border: #ccfbf1;
  --shadow: 0 2px 8px rgba(13, 148, 136, 0.08);
  --nav-h: 64px;
  --header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--teal-dark);
  color: white;
  padding-top: env(safe-area-inset-top, 0px);
  box-shadow: 0 1px 0 rgba(0,0,0,0.12);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px;
}
.header-row-main {
  height: 52px;
}
.header-row-meta {
  height: 36px;
  background: rgba(0,0,0,0.12);
  border-top: 1px solid rgba(255,255,255,0.1);
}
.header-row-meta-solo {
  justify-content: flex-end;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: inherit;
}
.brand-text {
  min-width: 0;
}
.brand h1 {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand .tagline {
  font-size: 0.65rem;
  opacity: 0.8;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  background: rgba(0,0,0,0.15);
  padding: 4px;
  border-radius: 12px;
}
.header-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: white;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.header-icon-btn svg {
  width: 18px;
  height: 18px;
}
.header-icon-btn:active,
.header-icon-btn.active {
  background: rgba(255,255,255,0.22);
}
.header-logout-form {
  display: contents;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
  text-transform: uppercase;
}
.user-pill-text {
  min-width: 0;
  line-height: 1.15;
}
.user-name {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  display: block;
  font-size: 0.6rem;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lang-switch-compact {
  flex-shrink: 0;
  padding: 2px;
  border-radius: 8px;
  background: rgba(0,0,0,0.2);
}
.lang-switch-compact .lang-btn {
  padding: 4px 8px;
  font-size: 0.65rem;
  min-width: 28px;
  text-align: center;
}

.login-top-tools {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 12px;
  display: flex;
  gap: 8px;
  z-index: 50;
}
.login-tool-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  color: var(--teal-dark);
  font-size: 0.75rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.login-tool-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.login-tool-btn:first-child {
  padding: 8px;
}

.install-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.install-modal-card {
  background: white;
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.install-modal-card h3 {
  font-size: 1.1rem;
  color: var(--teal-dark);
  margin-bottom: 12px;
}
.install-steps {
  font-size: 0.9rem;
  line-height: 1.6;
  color: #374151;
  margin-bottom: 16px;
}

.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--bg);
}
.login-wrap {
  width: 100%;
  max-width: 400px;
}
.login-brand {
  text-align: center;
  margin-bottom: 16px;
}
.login-logo {
  display: block;
  width: min(240px, 70vw);
  height: auto;
  margin: 0 auto 4px;
}
.login-card { margin-bottom: 16px; }
.login-lang {
  justify-content: center;
  background: white;
  border: 1px solid var(--border);
}
.login-lang .lang-btn {
  color: #4b5563;
}
.login-lang .lang-btn.active {
  background: var(--teal);
  color: white;
}
.login-lang .lang-btn:not(.active):active {
  background: rgba(13, 148, 136, 0.12);
}

.brand-logo {
  width: 36px;
  height: 36px;
  padding: 3px;
  border-radius: 8px;
  background: white;
  object-fit: contain;
  flex-shrink: 0;
}

.lang-switch {
  display: flex;
  overflow: hidden;
  flex-shrink: 0;
}
.lang-switch-compact .lang-btn {
  color: rgba(255,255,255,0.7);
}
.lang-btn {
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
}
.lang-btn.active {
  background: white;
  color: var(--teal-dark);
}
.lang-btn:not(.active):active { background: rgba(255,255,255,0.25); }

.app-main {
  padding: 16px;
  max-width: 480px;
  margin: 0 auto;
}

.date-badge {
  text-align: center;
  font-size: 0.85rem;
  color: var(--teal-dark);
  font-weight: 600;
  margin-bottom: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.stats-grid .stat-card:last-child { grid-column: 1 / -1; }

.stat-card {
  background: var(--card);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-card.full-width { margin-bottom: 16px; }

.stat-card.sales { border-left: 4px solid var(--green); }
.stat-card.purchases { border-left: 4px solid var(--red); }
.stat-card.profit.positive { border-left: 4px solid var(--teal); }
.stat-card.profit.negative { border-left: 4px solid #f59e0b; }

.stat-label { font-size: 0.75rem; color: #6b7280; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { font-size: 1.5rem; font-weight: 700; }

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--teal-dark);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  text-align: center;
}

.summary-row div { display: flex; flex-direction: column; gap: 4px; }
.summary-row strong { font-size: 1.1rem; }
.muted { font-size: 0.75rem; color: #6b7280; }

.text-green { color: var(--green); }
.text-red { color: var(--red); }

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.action-btn {
  display: block;
  text-align: center;
  padding: 14px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  color: white;
  transition: transform 0.15s;
}

.action-btn:active { transform: scale(0.97); }
.sales-btn { background: var(--green); }
.purchase-btn { background: var(--red); }

.txn-list { list-style: none; }
.txn-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.txn-item:last-child { border-bottom: none; }

.txn-amount { font-weight: 700; font-size: 1rem; display: block; }
.txn-desc { font-size: 0.8rem; color: #6b7280; display: block; margin-top: 2px; }
.txn-time { font-size: 0.75rem; color: #9ca3af; white-space: nowrap; }
.txn-actions { display: flex; align-items: center; gap: 8px; }

.receipt-link {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--teal);
  text-decoration: none;
  margin-top: 4px;
  font-weight: 600;
}

.empty {
  text-align: center;
  color: #9ca3af;
  font-size: 0.85rem;
  padding: 12px 0;
}

.form { display: flex; flex-direction: column; gap: 14px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--teal-dark);
}

.form-input {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.4;
  background-color: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
  min-height: 48px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

select.form-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%230d9488' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
  padding-right: 36px;
  cursor: pointer;
}

.form-input:focus { border-color: var(--teal); }

.select-wrap { position: relative; width: 100%; }
.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 8px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%230d9488' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  pointer-events: none;
}
.select-wrap select.form-input {
  background-image: none;
  padding-right: 36px;
}

.input-with-btn {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.input-with-btn .form-input {
  flex: 1;
  min-width: 0;
}
.btn-search {
  flex-shrink: 0;
  padding: 0 18px;
  min-height: 48px;
  border: none;
  border-radius: 10px;
  background: var(--teal);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn-search:active { background: var(--teal-dark); transform: scale(0.97); }

.hidden { display: none !important; }
.field-hint { font-size: 0.8rem; margin-top: 6px; }
.hint-found { color: var(--teal-dark); font-weight: 600; }
.hint-new { color: #b45309; }
.mb-8 { margin-bottom: 8px; }

.form-row-3 { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 8px; }
.form-row-3 .form-group { min-width: 0; }

.btn {
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--teal); color: white; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-danger {
  background: #fef2f2;
  color: var(--red);
  border: 2px solid #fecaca;
  width: 100%;
}
.btn-danger:active { background: #fee2e2; }

.exit-bill-form { margin-top: 12px; }
.btn-exit {
  width: 100%;
  padding: 12px;
  border: 2px solid #fecaca;
  border-radius: 10px;
  background: #fff;
  color: var(--red);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.btn-exit:active { background: #fef2f2; }

.danger-card { border: 1px solid #fecaca; background: #fffbfb; }
.danger-desc { font-size: 0.85rem; color: #6b7280; margin-bottom: 12px; line-height: 1.4; }

.file-upload { position: relative; }

.receipt-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.btn-receipt {
  padding: 14px 10px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--teal-dark);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  min-height: 48px;
}
.btn-receipt:active { border-color: var(--teal); background: #ccfbf1; }
.file-name { font-size: 0.85rem; color: #6b7280; margin-top: 8px; display: block; }
.file-name-ok { color: var(--teal-dark); font-weight: 600; }

.btn-delete {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-delete:active { color: var(--red); background: #fef2f2; }

.month-picker { display: flex; flex-direction: column; gap: 8px; }
.month-picker label { font-size: 0.8rem; font-weight: 600; color: var(--teal-dark); }

.daily-list { list-style: none; }
.daily-list li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.daily-list li:last-child { border-bottom: none; }
.daily-date { font-weight: 600; }
.daily-count { color: #9ca3af; font-size: 0.75rem; }
.daily-amount { font-weight: 700; text-align: right; }

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--card);
  display: flex;
  justify-content: space-around;
  align-items: center;
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
  z-index: 100;
  max-width: 480px;
  margin: 0 auto;
}

@media (min-width: 481px) {
  .bottom-nav { left: 50%; transform: translateX(-50%); border-radius: 16px 16px 0 0; }
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: #9ca3af;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 10px;
  transition: color 0.2s;
}

.nav-item.active { color: var(--teal); }
.nav-item span:last-child { font-size: 0.58rem; }
.nav-icon {
  width: 22px;
  height: 22px;
  display: block;
}

.bill-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.bill-tabs::-webkit-scrollbar { display: none; }

.bill-tab {
  flex-shrink: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--card);
  border: 2px solid var(--border);
  text-decoration: none;
  color: var(--text);
  min-width: 100px;
}
.bill-tab.active {
  border-color: var(--teal);
  background: #ccfbf1;
}
.bill-tab-new {
  min-width: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--teal);
}
.bill-tab-name {
  display: block;
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}
.bill-tab-status {
  font-size: 0.65rem;
  color: #6b7280;
}

.customer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.customer-mobile { font-size: 0.85rem; color: #6b7280; margin-top: 4px; }

.status-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.status-open { background: #dbeafe; color: #1d4ed8; }
.status-billed { background: #fef3c7; color: #b45309; }
.status-partial { background: #fee2e2; color: #dc2626; }
.status-paid { background: #dcfce7; color: #16a34a; }

.form-row { display: flex; gap: 10px; }
.form-row .flex-2 { flex: 2; }
.btn-block { width: 100%; }
.mt-12 { margin-top: 12px; }

.bill-total-row, .summary-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 12px;
  margin-top: 12px;
  border-top: 2px solid var(--border);
  font-size: 1rem;
}
.bill-total-row strong, .summary-line strong { font-size: 1.25rem; }
.summary-line.due { margin-top: 8px; padding-top: 8px; border-top: 1px dashed #fecaca; }

.payment-history {
  list-style: none;
  margin-top: 12px;
  font-size: 0.8rem;
  color: #6b7280;
}
.payment-history li { padding: 4px 0; }

.bill-list { list-style: none; }
.bill-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
}
.bill-list-item:last-child { border-bottom: none; }
.bill-list-right { text-align: right; }

.form-error {
  background: #fef2f2;
  color: var(--red);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}
.form-success {
  background: #ecfdf5;
  color: var(--teal-dark);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}
.user-list { list-style: none; }
.user-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.user-list-item:last-child { border-bottom: none; }
.user-list-mobile {
  display: block;
  font-size: 0.8rem;
  color: #6b7280;
  margin-top: 2px;
}
.user-list-role {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--teal-dark);
  white-space: nowrap;
}
.hint-text {
  text-align: center;
  color: #9ca3af;
  font-size: 0.85rem;
  margin-top: 8px;
}
