@import url("https://fonts.googleapis.com/css2?family=Sometype+Mono:wght@400;500;700&display=swap");

/* Mobile-first, minimal, dark by default */
* {
  box-sizing: border-box;
  border-radius: 0 !important;
  /* Requirement: keep UI corners square */
  font-family: "Sometype Mono", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

:root {
  --bg: #151515;
  --panel: #101010;
  --panel-2: #141414;
  --text: #f2f2f2;
  --muted: #a8a8a8;
  --border: #222222;
  --accent: #0a84ff;
  --danger: #ff3b30;
  --warning: #ff9f0a;
  --ok: #34c759;

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;

  --screen-padding-x: var(--space-lg);

  --font-xs: clamp(11px, 3.5vw, 12px);
  --font-nav: clamp(11px, 3.5vw, 12px);
  --font-sm: clamp(12px, 4vw, 14px);
  --font-md: clamp(14px, 4.2vw, 16px);
  --font-lg: clamp(18px, 5.5vw, 22px);
  --font-xl: clamp(24px, 7vw, 32px);

  --tap-target: 48px;
}

button {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

html,
body {
  height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: "Sometype Mono", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

#app {
  min-height: 100vh;
  padding-bottom: 84px;
  /* bottom nav spacing */
}

@keyframes screenFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.screen {
  padding: var(--space-lg) var(--screen-padding-x);
}

.screen:not(.hidden) {
  animation: screenFadeIn 0.25s ease-out forwards;
}

.hidden {
  display: none !important;
}

.screen-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px 14px 2px;
}

.screen-title {
  font-size: var(--font-lg);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.screen-header>div {
  min-width: 0;
}

#dashboard-greeting {
  font-size: var(--font-xs);
  letter-spacing: 0.2px;
}

.screen-subtitle {
  color: var(--muted);
  font-size: var(--font-sm);
  text-align: right;
  max-width: 60%;
}

.dashboard-top {
  display: grid;
  place-items: center;
  padding: 10px 0 6px 0;
}

.widget {
  position: relative;
  width: min(70vw, 300px);
  height: min(70vw, 300px);
}

.budget-ring {
  width: 100%;
  height: 100%;
}

.ring-bg {
  fill: none;
  stroke: #1f1f1f;
  stroke-width: 10;
}

.ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 10;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 60px 60px;
  stroke-dasharray: 289;
  /* 2*pi*46 (approx). We'll set actual dashoffset in JS. */
  stroke-dashoffset: 289;
}

.ring-segment {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 60px 60px;
}

.widget-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 86%;
  text-align: center;
  padding: 0 6px;
}

.widget-big {
  font-size: var(--font-xl);
  font-weight: 800;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.widget-small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.banner {
  margin: 4px auto var(--space-lg) auto;
  width: fit-content;
  max-width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  background: var(--panel-2);
  font-size: var(--font-xs);
}

#budget-warning,
#recurring-edit-warning {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.banner.warn {
  border-color: rgba(255, 159, 10, 0.7);
}

.banner.danger {
  border-color: rgba(255, 59, 48, 0.8);
}

.section {
  margin-top: 14px;
}

.section-title {
  font-weight: 700;
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 10px 0;
}

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

.item {
  border: 1px solid var(--border);
  background: var(--panel);
  padding: var(--space-md);
}

.item-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.item-title {
  font-weight: 700;
  font-size: var(--font-md);
  word-break: break-word;
}

.category-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.category-dot {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  display: inline-block;
}

.item-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

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

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

input[type="number"],
input[type="text"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: var(--space-md);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  outline: none;
  font-size: var(--font-md);
  min-height: var(--tap-target);
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text) 50%),
    linear-gradient(135deg, var(--text) 50%, transparent 50%);
  background-position:
    calc(100% - 22px) calc(50% + 2px),
    calc(100% - 16px) calc(50% + 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 38px;
}

textarea {
  resize: vertical;
  min-height: 72px;
}

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

.toggle-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-height: var(--tap-target);
}

.toggle-wrap label {
  margin-bottom: 0;
  line-height: 1;
}

/* Keep checkbox large & tappable */
input[type="checkbox"] {
  width: 20px;
  height: 20px;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.form-actions {
  padding-top: 6px;
}

.primary {
  width: 100%;
  padding: var(--space-md);
  min-height: var(--tap-target);
  border: 1px solid rgba(255, 255, 255, 0.8);
  background: #ffffff;
  color: #101010;
  font-weight: 800;
  font-size: var(--font-lg);
}

.error {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 59, 48, 0.8);
  background: rgba(255, 59, 48, 0.12);
  color: var(--danger);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 900;
  height: 64px;
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  padding-bottom: 0px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: 0;
  padding-right: 0;
  border-top: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  overflow: visible;
}

.nav-fab-slot {
  flex: 0 0 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: visible;
  height: 100%;
}

.nav-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: var(--font-nav);
  font-weight: 700;
  min-height: var(--tap-target);
  height: 100%;
  padding: 0;
}

.nav-btn.active {
  color: var(--text);
}

.fab {
  width: 58px;
  height: 58px;
  border: none;
  background: #ffffff;
  color: #000000;
  font-size: 28px;
  font-weight: 400;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50% !important;
  z-index: 1001;
  box-shadow: 0 0 0 4px #ffffff, 0 8px 24px rgba(0, 0, 0, 0.6);
  position: absolute;
  top: 0;
  transform: translateY(-50%) rotate(0deg);
  transition: transform 0.3s ease;
}

.fab.rotated {
  transform: translateY(-50%) rotate(-45deg);
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.space-between {
  justify-content: space-between;
}

.field.compact {
  margin: 0;
}

/* History action dropdown — icon only, no visible label */
.history-action-select {
  width: var(--tap-target);
  min-height: var(--tap-target);
  padding: 0;
  margin-top: 0;
  margin-left: 0;
  display: block;
  font-size: 12px;
  color: transparent;
  /* hide selected option text */
  text-indent: -9999px;
  background-position: center center;
  background-size: 8px 8px, 8px 8px;
  cursor: pointer;
  border-color: transparent;
  background-color: transparent;
}

.history-action-select option {
  color: var(--text);
  background: var(--panel);
  text-indent: 0;
}

#save-budget {
  border-color: rgba(255, 255, 255, 0.8);
  background: #ffffff;
  color: #101010;
}

/* Back button */
.back-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 20px;
  padding: 0 8px 0 0;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.back-btn:active {
  color: var(--text);
}

/* History item action row */
.history-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

/* In-app confirm modal */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 24px;
}

.confirm-overlay.hidden {
  display: none;
}

.confirm-box {
  background: var(--panel);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 320px;
  padding: 20px 16px 16px 16px;
}

.confirm-message {
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 18px;
  color: var(--text);
}

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

.confirm-btn {
  flex: 1;
  padding: var(--space-md) var(--space-sm);
  min-height: var(--tap-target);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: var(--font-sm);
  font-weight: 700;
  cursor: pointer;
}

.confirm-btn-danger {
  border-color: rgba(255, 59, 48, 0.7);
  color: var(--danger);
}

/* Action sheet */
.action-sheet-box {
  padding: 20px 16px 16px 16px;
}

.action-sheet-header {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 14px;
}

.action-sheet-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-sheet-opt {
  flex: 1;
  padding: 13px 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}

.action-sheet-opt.danger {
  border-color: rgba(255, 59, 48, 0.6);
  color: var(--danger);
}

.action-sheet-cancel-row {
  margin-top: 10px;
}

#action-sheet-cancel {
  width: 100%;
  padding: 12px 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

/* History item right column: amount stacked above pencil */
.history-item-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

/* Custom Date Picker Styles */
.date-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.date-input-wrapper input {
  flex: 1;
  padding-right: 40px !important;
  cursor: pointer;
}

.date-dropdown-btn {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  font-size: 12px;
  border-radius: 4px;
}

.date-dropdown-btn:hover {
  color: var(--text);
  background: var(--panel-2);
}

.custom-calendar {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding: 4px;
}

.calendar-nav {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.calendar-nav:hover {
  background: var(--panel-2);
}

.calendar-month-year {
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.calendar-day-header {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  padding: 4px;
  font-weight: 500;
}

.calendar-day {
  text-align: center;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  font-size: 12px;
  background: transparent;
  border: none;
}

.calendar-day:hover {
  background: var(--panel-2);
}

.calendar-day.selected {
  background: var(--accent);
  color: white;
}

/* Accordion Settings */
.accordion-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 20px;
  margin-left: calc(-1 * var(--screen-padding-x));
  margin-right: calc(-1 * var(--screen-padding-x));
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

details.accordion-item {
  padding: 0;
  overflow: hidden;
  border-left: none;
  border-right: none;
  border-bottom: none;
  border-radius: 0 !important;
}

details.accordion-item:first-child {
  border-top: none;
}

details.accordion-item summary {
  list-style: none;
  /* Hide default triangle */
}

details.accordion-item summary::-webkit-details-marker {
  display: none;
  /* Hide default triangle in WebKit */
}

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px var(--screen-padding-x);
  cursor: pointer;
  user-select: none;
  outline: none;
}

.accordion-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

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

.accordion-header .item-title {
  font-weight: 500;
  font-size: 15px;
}

.accordion-header:active {
  background: var(--panel-2);
}

.chevron {
  transition: transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--muted);
}

.accordion-content {
  padding: 16px var(--screen-padding-x) 24px var(--screen-padding-x);
  border-top: 1px solid var(--border);
  background: var(--bg);
}

details.accordion-item[open] .accordion-content {
  animation: accordionOpen 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transform-origin: top center;
}

@keyframes accordionOpen {
  0% {
    opacity: 0;
    transform: translateY(-8px);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

details.accordion-item[open] .chevron {
  transform: rotate(180deg);
}

/* Ensure list inside repeating section has no top margin if empty */
#recurring-list:empty {
  display: none;
}

/* Export screen field spacing */
.export-field+.export-field {
  margin-top: 15px;
}

/* Export screen section spacing */
.export-category-section {
  margin-top: 10px;
}

/* Export filter table styling */
.filter-table {
  display: flex;
  width: 100%;
  border: 1px solid var(--border);
}

.filter-cell {
  flex: 1;
  padding: 12px 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: normal;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  border: none;
  box-shadow: none;
}

.filter-cell:not(:first-child) {
  border-left: 1px solid var(--border);
}

.filter-cell:hover {
  background: var(--panel-2);
  color: var(--text);
}

/* Export Status Overlay (Labor Illusion) */
.export-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  background: var(--bg);
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.export-overlay.hidden {
  display: none !important;
}

.export-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.spinner {
  display: inline-block;
  width: 48px;
  height: 48px;
  box-sizing: border-box;
  border: 4px solid #000000;
  border-top-color: #ffffff;
  border-radius: 50% !important;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.export-success-icon {
  width: 48px;
  height: 48px;
  color: #ffffff;
}

.export-overlay-text {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.calendar-day.today {
  border: 1px solid var(--accent);
}

.calendar-day.other-month {
  color: var(--muted);
}

.calendar-day.disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.5;
}

/* History item pencil action button */
.history-action-btn {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  -webkit-appearance: none;
  appearance: none;
  color: #ff6b6b;
  padding: 0;
  margin: 0;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

/* Remove Android tap highlight */
* {
  -webkit-tap-highlight-color: transparent;
}

/* History month select — center the chevron vertically */
#history-month,
#history-month-trigger {
  text-align: center;
  padding-right: 38px;
  background-position:
    calc(100% - 22px) 50%,
    calc(100% - 16px) 50%;
}

/* Recurring checkbox — white bg, dark tick */
input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: #101010;
  background: #ffffff;
}

/* Dashboard Accordion (Aesthetic Grid Animation) */
.dashboard-accordion {
  margin-bottom: 10px;
}

.dashboard-accordion-header {
  cursor: pointer;
  transition: background 0.2s ease;
}

.dashboard-accordion-header:active {
  background: var(--panel-2);
}

.dashboard-accordion-title {
  font-size: var(--font-sm);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.dashboard-chevron {
  transition: transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--muted);
}

.dashboard-accordion.is-open .dashboard-chevron {
  transform: rotate(180deg);
}

.dashboard-accordion-wrapper {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.dashboard-accordion.is-open .dashboard-accordion-wrapper {
  grid-template-rows: 1fr;
}

.dashboard-accordion-content {
  min-height: 0;
  overflow: hidden;
}

.dashboard-accordion-inner {
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.8s ease 0.1s, transform 0.8s cubic-bezier(0.16, 1, 0.3, 1) 0.05s;
  padding: 4px 12px 14px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-top: none;
}

.dashboard-accordion.is-open .dashboard-accordion-inner {
  opacity: 1;
  transform: translateY(0);
}

.dashboard-expense-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.dashboard-expense-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.dashboard-expense-item:first-child {
  padding-top: 8px;
}

.dashboard-expense-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
}

.dashboard-expense-date {
  font-size: 11px;
  color: var(--muted);
}

.dashboard-expense-amount {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

/* Custom Dropdown Animation Component */
.custom-dropdown-container {
  position: relative;
  width: 100%;
}

.custom-dropdown-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  user-select: none;
  width: 100%;
  box-sizing: border-box;
}

.custom-dropdown-value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-dropdown-chevron-wrapper {
  display: flex;
  align-items: center;
  color: var(--muted);
  flex-shrink: 0;
}

.custom-dropdown-chevron {
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.custom-dropdown-container.is-open .custom-dropdown-chevron {
  transform: rotate(180deg);
}

.custom-dropdown-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  z-index: 100;
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.7s cubic-bezier(0.16, 1, 0.3, 1);
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
}

.custom-dropdown-container.is-open .custom-dropdown-panel {
  grid-template-rows: 1fr;
}

.custom-dropdown-list {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 240px;
  background: var(--panel);
  border: 1px solid var(--border);
  opacity: 0;
  transition: opacity 0.6s ease;
}

.custom-dropdown-container.is-open .custom-dropdown-list {
  opacity: 1;
}

.custom-dropdown-option {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s ease;
  font-size: 14px;
  color: var(--muted);
}

.custom-dropdown-option:last-child {
  border-bottom: none;
}

.custom-dropdown-option:hover {
  background: var(--panel-2);
}

.custom-dropdown-option.selected {
  color: var(--text);
  font-weight: 700;
  background: var(--panel-2);
}

/* --- Mobile Breakpoints Strategy --- */

@media (min-width: 360px) {
  :root {
    --screen-padding-x: var(--space-xl);
  }
}

@media (min-width: 390px) {
  .dashboard-accordion-inner {
    padding: var(--space-sm) var(--space-lg) var(--space-lg) var(--space-lg);
  }
}

@media (min-width: 430px) {

  /* On large phablets, scale the graph to 300px immediately */
  .widget {
    width: 300px;
    height: 300px;
  }
}