:root {
  color-scheme: light;
  --bg: #f4f7f7;
  --surface: #ffffff;
  --surface-soft: #ecfdf5;
  --text: #12312e;
  --muted: #64748b;
  --border: #d8e3e1;
  --primary: #0f766e;
  --primary-dark: #0b5f58;
  --positive: #087f5b;
  --negative: #c2413b;
  --warning: #9a6700;
  --shadow: 0 14px 40px rgba(15, 118, 110, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; color: var(--text); background: var(--bg); min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.62; }

.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(16px + env(safe-area-inset-top)) max(18px, calc((100vw - 1040px) / 2)) 16px;
  background: rgba(244, 247, 247, 0.94); backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(216, 227, 225, 0.75);
}
.app-header h1 { margin: 2px 0 0; font-size: clamp(1.25rem, 4vw, 1.75rem); }
.eyebrow { margin: 0; color: var(--primary); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.12em; }
.container { width: min(100% - 28px, 1040px); margin: 22px auto 70px; display: grid; gap: 18px; }

.balance-hero {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 28px; border-radius: 24px; color: white;
  background: linear-gradient(135deg, #0f766e, #134e4a); box-shadow: var(--shadow);
}
.balance-hero p { margin: 0 0 8px; opacity: .82; }
.balance-hero strong { display: block; font-size: clamp(2.4rem, 10vw, 4.6rem); line-height: 1; letter-spacing: -0.055em; }
.balance-hero span { display: block; margin-top: 10px; opacity: .78; }
.hero-badge { display: grid; place-items: center; min-width: 76px; height: 76px; border-radius: 22px; background: rgba(255,255,255,.13); font-size: 2.2rem; }

.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.summary-card, .panel { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.summary-card { padding: 18px; border-radius: 18px; }
.summary-card span, .summary-card small { color: var(--muted); }
.summary-card strong { display: block; margin: 8px 0 4px; font-size: 1.65rem; }
.summary-card small { font-weight: 700; }

.panel { padding: 22px; border-radius: 22px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 20px; }
.section-heading h2 { margin: 3px 0 0; font-size: 1.32rem; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 1px solid transparent; font-weight: 800; text-decoration: none; transition: transform .15s ease, background .15s ease; }
.button:active { transform: translateY(1px); }
.button-primary { color: white; background: var(--primary); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { color: var(--text); background: white; border-color: var(--border); }
.button-danger { color: #fff; background: var(--negative); }
.button-large { flex: 1; min-height: 54px; font-size: 1rem; }
.button-row { display: flex; gap: 10px; margin-top: 20px; }
.button-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.file-button input { display: none; }
.icon-button { width: 42px; height: 42px; border-radius: 50%; border: 0; background: #eef4f3; color: var(--text); font-size: 1.55rem; }

.status-badge { display: inline-flex; align-items: center; min-height: 32px; padding: 6px 10px; border-radius: 999px; color: var(--primary); background: #ccfbf1; font-size: .78rem; font-weight: 800; white-space: nowrap; }
.timeline { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.timeline-item { display: flex; align-items: center; gap: 10px; padding: 13px; border-radius: 14px; border: 1px dashed var(--border); background: #fbfdfd; }
.timeline-item.done { border-style: solid; background: var(--surface-soft); }
.timeline-dot { display: grid; place-items: center; min-width: 30px; height: 30px; border-radius: 50%; color: var(--muted); background: #e7eeed; font-size: .76rem; font-weight: 900; }
.timeline-item.done .timeline-dot { color: #fff; background: var(--primary); }
.timeline-item small { display: block; color: var(--muted); font-size: .7rem; }
.timeline-item strong { display: block; margin-top: 2px; }
.help-text { margin: 12px 0 0; color: var(--muted); font-size: .86rem; line-height: 1.45; }
.empty-inline { grid-column: 1 / -1; color: var(--muted); text-align: center; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
label { display: grid; gap: 7px; color: #425b58; font-size: .82rem; font-weight: 750; }
input, select, textarea { width: 100%; min-height: 44px; padding: 10px 12px; color: var(--text); background: white; border: 1px solid var(--border); border-radius: 11px; outline: none; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12); }

.history-list { display: grid; gap: 9px; }
.history-card { width: 100%; display: grid; grid-template-columns: 95px 1fr auto; align-items: center; gap: 14px; padding: 14px; text-align: left; color: inherit; background: #fbfdfd; border: 1px solid var(--border); border-radius: 14px; }
.history-card:hover { border-color: #9fc8c2; }
.history-date strong, .history-main strong { display: block; }
.history-date span, .history-main span { display: block; margin-top: 3px; color: var(--muted); font-size: .78rem; }
.history-date span { text-transform: capitalize; }
.history-balance { font-size: 1.02rem; font-weight: 900; }
.positive { color: var(--positive) !important; }
.negative { color: var(--negative) !important; }
.neutral { color: var(--muted) !important; }
.empty-state { padding: 26px; color: var(--muted); text-align: center; border: 1px dashed var(--border); border-radius: 14px; }

.schedule-panel { display: grid; gap: 10px; }
.schedule-panel .section-heading { margin-bottom: 4px; }
.schedule-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 18px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.schedule-row span { font-weight: 800; }
.schedule-row small { grid-column: 1 / -1; color: var(--muted); }
.schedule-total { padding-top: 8px; text-align: right; }

.record-dialog { width: min(640px, calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 0; border-radius: 22px; box-shadow: 0 30px 100px rgba(15, 35, 33, .28); }
.record-dialog::backdrop { background: rgba(9, 30, 27, .55); backdrop-filter: blur(3px); }
.record-dialog form { padding: 22px; display: grid; gap: 18px; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.dialog-header h2 { margin: 3px 0 0; }
.form-grid, .time-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.disabled-fields { opacity: .55; }
.record-preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 14px; background: #f3f8f7; border-radius: 14px; }
.record-preview div { text-align: center; }
.record-preview span { display: block; color: var(--muted); font-size: .73rem; }
.record-preview strong { display: block; margin-top: 3px; }
.warning-text { grid-column: 1 / -1; margin-top: 5px; color: var(--warning) !important; text-align: center; }
.form-error { margin: 0; padding: 10px 12px; color: #922f2b; background: #fff0ef; border-radius: 10px; font-size: .86rem; }
.dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-actions-right { display: flex; gap: 10px; margin-left: auto; }
.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 100; transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); padding: 12px 16px; color: white; background: #163c38; border-radius: 12px; box-shadow: 0 15px 50px rgba(0,0,0,.23); font-weight: 750; }
.hidden { display: none !important; }

@media (max-width: 760px) {
  .container { width: min(100% - 20px, 1040px); margin-top: 12px; }
  .balance-hero { padding: 22px; border-radius: 20px; }
  .hero-badge { min-width: 58px; height: 58px; font-size: 1.65rem; }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-card { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 3px 10px; }
  .summary-card strong { grid-row: 1 / 3; grid-column: 2; margin: 0; }
  .timeline { grid-template-columns: 1fr 1fr; }
  .button-row { display: grid; }
  .button-grid { grid-template-columns: 1fr; }
  .history-card { grid-template-columns: 75px 1fr auto; gap: 9px; }
  .panel { padding: 17px; border-radius: 18px; }
}

@media (max-width: 520px) {
  .app-header { padding-left: 14px; padding-right: 14px; }
  .filters, .form-grid, .time-fields { grid-template-columns: 1fr; }
  .history-card { grid-template-columns: 1fr auto; }
  .history-date { grid-column: 1; }
  .history-main { grid-column: 1; }
  .history-balance { grid-column: 2; grid-row: 1 / 3; }
  .schedule-row { grid-template-columns: 1fr; }
  .schedule-row strong { font-size: .92rem; }
  .record-dialog { width: 100%; max-height: 92dvh; margin: auto 0 0; border-radius: 22px 22px 0 0; }
  .record-dialog form { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .dialog-actions { align-items: stretch; flex-direction: column-reverse; }
  .dialog-actions-right { width: 100%; margin: 0; }
  .dialog-actions-right .button, .dialog-actions > .button { flex: 1; }
}

.manual-panel { overflow: hidden; }
.manual-instructions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding: 15px;
  border: 1px solid #cde6e2;
  border-radius: 16px;
  background: #f0fdfa;
}
.manual-instructions p { margin: 4px 0 0; color: var(--muted); line-height: 1.45; }
.instruction-icon {
  display: grid;
  place-items: center;
  flex: 0 0 48px;
  height: 48px;
  border-radius: 14px;
  background: white;
  font-size: 1.45rem;
  box-shadow: 0 8px 24px rgba(15, 118, 110, .10);
}
.status-badge.positive { color: #087f5b !important; background: #dff8ed; }
.status-badge.negative { color: #a63833 !important; background: #ffebe9; }
.status-badge.neutral { color: #526a67 !important; background: #edf2f1; }

.record-dialog { overflow-y: auto; }
.receipt-section {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fbfdfd;
}
.receipt-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.receipt-heading strong, .receipt-heading small { display: block; }
.receipt-heading small { margin-top: 3px; color: var(--muted); font-weight: 600; }
.compact-button { min-height: 38px; padding: 8px 12px; font-size: .82rem; }
.receipt-preview {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: white;
}
.receipt-preview img {
  display: block;
  width: 100%;
  max-height: 340px;
  object-fit: contain;
  background: #eef3f2;
}
.receipt-preview-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
}
.receipt-preview-actions span {
  overflow: hidden;
  color: var(--muted);
  font-size: .78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.text-button {
  flex: 0 0 auto;
  padding: 4px;
  border: 0;
  color: var(--negative);
  background: transparent;
  font-weight: 800;
  font-size: .78rem;
}

@media (max-width: 520px) {
  .manual-instructions { align-items: flex-start; }
  .receipt-heading { align-items: stretch; flex-direction: column; }
  .compact-button { width: 100%; }
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.header-button { min-height: 38px; padding: 7px 11px; font-size: .78rem; }
.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,255,255,.8);
  font-size: .74rem;
  font-weight: 750;
  white-space: nowrap;
}
.sync-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148,163,184,.16);
}
.sync-dot.online { background: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,.16); }
.sync-dot.offline { background: #dc2626; box-shadow: 0 0 0 3px rgba(220,38,38,.14); }
.sync-dot.working { background: #d97706; box-shadow: 0 0 0 3px rgba(217,119,6,.15); animation: syncPulse 1s infinite alternate; }
@keyframes syncPulse { to { opacity: .35; transform: scale(.8); } }

.login-dialog {
  width: min(430px, calc(100% - 28px));
  padding: 0;
  border: 0;
  border-radius: 22px;
  box-shadow: 0 30px 100px rgba(15,35,33,.3);
}
.login-dialog::backdrop { background: rgba(9,30,27,.72); backdrop-filter: blur(5px); }
.login-dialog form { display: grid; gap: 17px; padding: 26px; }
.login-dialog h2 { margin: 4px 0 0; }
.login-description { margin: 8px 0 0; color: var(--muted); line-height: 1.5; }
.login-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 18px;
  background: #ecfdf5;
  font-size: 1.7rem;
}

@media (max-width: 760px) {
  .app-header { align-items: flex-start; }
  .header-actions { max-width: 54%; }
  .sync-status { order: 2; width: 100%; justify-content: center; }
}

@media (max-width: 520px) {
  .app-header { position: static; flex-direction: column; align-items: stretch; }
  .header-actions { max-width: none; justify-content: flex-start; }
  .sync-status { order: 0; width: auto; max-width: 100%; }
  .header-button { flex: 1; }
}
