:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #1d2939;
  --muted: #667085;
  --primary: #2f6fed;
  --primary-dark: #1f56c4;
  --danger: #e5484d;
  --success: #22a06b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --tabbar-h: 64px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
}

h1 {
  font-size: 1.4rem;
  margin: 0;
}

.muted {
  color: var(--muted);
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
}

/* Page */
.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 16px 28px;
}

.page-head {
  margin-bottom: 14px;
}

.page-head p {
  margin: 4px 0 0;
  font-size: 0.9rem;
}

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

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

/* Forms */
.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span {
  font-size: 0.88rem;
  font-weight: 600;
}

.opt {
  color: var(--muted);
  font-weight: 400;
  font-style: normal;
  font-size: 0.8rem;
}

.field input,
.field select {
  width: 100%;
  padding: 13px 14px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}

.field input[type='file'] {
  padding: 10px;
  font-size: 0.9rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 18px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

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

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

.btn-ghost {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
  padding: 10px 14px;
  font-size: 0.9rem;
}

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

.btn-block {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
}

.icon-btn:hover {
  background: #eef1f5;
  color: var(--text);
}

/* Period filter */
.period {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.period select {
  flex: 1;
  padding: 11px 12px;
  font-family: inherit;
  font-size: 0.95rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
}

/* Dashboard */
.total-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
  padding: 22px;
}

.total-amount {
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.chart-box {
  position: relative;
  height: 320px;
}

.total-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
}

/* Table */
.table-card {
  padding: 0;
  overflow: hidden;
}

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

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

.data-table th,
.data-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #fafbfc;
}

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

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.data-table .center {
  text-align: center;
}

.concept {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary-dark);
  background: rgba(47, 111, 237, 0.1);
  border-radius: 999px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  margin: 0;
}

/* Preview */
.preview img,
.image-info img {
  max-width: 100%;
  max-height: 220px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.image-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

/* Modals */
body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(16, 24, 40, 0.5);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.modal.open {
  opacity: 1;
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  transform: translateY(8px);
  transition: transform 0.18s ease;
}

.modal.open .modal-panel {
  transform: translateY(0);
}

.modal-image {
  width: auto;
  max-width: 92vw;
  max-height: 92vh;
  padding: 0;
  overflow: visible;
  background: transparent;
}

.modal-image img {
  display: block;
  width: auto;
  height: auto;
  max-width: 92vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.modal-x {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  background: rgba(16, 24, 40, 0.72);
  color: #fff;
  border-radius: 50%;
  font-size: 1.7rem;
  line-height: 1;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.modal-x:hover {
  background: rgba(16, 24, 40, 0.92);
  color: #fff;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-head h2 {
  font-size: 1.15rem;
  margin: 0;
}

.modal-head .icon-btn {
  width: 40px;
  height: 40px;
  background: #eef1f5;
  color: var(--text);
  border-radius: 50%;
  font-size: 1.7rem;
}

.modal-head .icon-btn:hover {
  background: #e2e6ec;
  color: var(--text);
}


.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions .btn {
  flex: 1;
}

/* Alerts & toasts */
.alert {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-bottom: 14px;
}

.alert-error {
  background: #fdecec;
  color: #a12126;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 16px);
  transform: translateX(-50%);
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 10px;
  color: #fff;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  transition: opacity 0.4s ease;
}

.toast-ok {
  background: var(--success);
}

.toast-error {
  background: var(--danger);
}

/* Login */
.login-wrap {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
  margin: 0;
}

.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: rgba(47, 111, 237, 0.1);
  color: var(--primary);
  margin-bottom: 12px;
}

.login-card h1 {
  font-size: 1.3rem;
}

.login-card p {
  margin: 6px 0 20px;
}

/* Tabbar */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 4px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
}

.tab.active {
  color: var(--primary);
}

@media (min-width: 640px) {
  .page {
    padding-top: 26px;
  }

  h1 {
    font-size: 1.6rem;
  }
}
