:root {
  --color-background: #f7f1e8;
  --color-surface: #fffaf2;
  --color-surface-muted: #efe3d0;
  --color-border: #decfb8;
  --color-primary: #a16207;
  --color-primary-hover: #854d0e;
  --color-primary-soft: #f3e4c7;
  --color-primary-text: #fff8ed;
  --color-button: #c8a46d;
  --color-button-hover: #b48a50;
  --color-text: #241a0f;
  --color-text-muted: #7c6a55;
  --color-success: #15803d;
  --color-warning: #b45309;
  --color-danger: #dc2626;
  --font-family-base: Inter, Segoe UI, Roboto, Arial, sans-serif;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 28px rgba(15, 23, 42, 0.12);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  width: 100%;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--color-background);
}

body {
  margin: 0;
  width: 100%;
  min-width: 0;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  background: linear-gradient(180deg, #fbf6ed 0%, var(--color-background) 100%);
  color: var(--color-text);
  font-family: var(--font-family-base);
  -webkit-text-size-adjust: 100%;
  touch-action: pan-y;
}

body,
main,
section,
article,
header,
nav,
form,
div,
p,
h1,
h2,
h3 {
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  max-width: 100%;
  min-width: 0;
}

img,
svg,
canvas,
iframe,
pre {
  max-width: 100%;
}

.app-shell {
  width: min(100%, 1000px);
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 100vw;
  overflow-x: hidden;
  overflow-y: visible;
  overscroll-behavior-x: none;
  -webkit-overflow-scrolling: touch;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: linear-gradient(180deg, #fbf6ed 0%, var(--color-background) 100%);
}

.screen,
.view {
  display: none;
}

.screen.active,
.view.active {
  display: block;
  min-width: 0;
  max-width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 0 14px;
  min-width: 0;
}

.brand-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.08;
  color: #6f3f12;
  overflow-wrap: anywhere;
}

h2 {
  font-size: 22px;
  color: #6f3f12;
  overflow-wrap: anywhere;
}

h3 {
  font-size: 17px;
  color: #6f3f12;
  overflow-wrap: anywhere;
}

p,
.eyebrow {
  color: var(--color-text-muted);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0 10px;
}

#app-screen.menu-mode .topbar {
  align-items: center;
}

.app-heading {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.app-heading > div,
.brand > div {
  min-width: 0;
}

.topbar-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 8px;
}

.eyebrow {
  margin-bottom: 1px;
  font-size: 12px;
}

.main-menu {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
  padding: 10px 0 0;
  max-width: 520px;
  margin: 0 auto;
}

.menu-btn {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  min-height: 164px;
  padding: 14px 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: linear-gradient(180deg, #fffaf2 0%, #ecd9bd 100%);
  color: var(--color-text);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(91, 62, 29, 0.13);
  min-width: 0;
}

.menu-btn span {
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: center;
}

.menu-btn:hover {
  border-color: #c6a574;
  background: linear-gradient(180deg, #fffdf7 0%, #e5d0ae 100%);
}

.menu-btn-wide {
  grid-column: 1 / -1;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 12px;
}

.panel {
  margin: 0 0 12px;
  padding: 14px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  min-width: 0;
  max-width: 100%;
}

.form-grid {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.abm-actions {
  display: grid;
  gap: 10px;
}

.abm-actions .btn {
  min-height: 58px;
}

.help-text {
  margin: 10px 0 0;
  padding: 12px;
  border-left: 4px solid var(--color-button);
  border-radius: 8px;
  background: #fff6e8;
  color: var(--color-text-muted);
  font-size: 14px;
  line-height: 1.45;
}

.field-block {
  display: grid;
  gap: 5px;
}

.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  color: var(--color-text);
  font-size: 14px;
  font-weight: 650;
}

.field-actions {
  display: flex;
  gap: 8px;
}

.field-actions .icon-btn {
  min-height: 34px;
  width: 34px;
  background: rgba(255, 246, 232, 0.94);
}

.ia-usage {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--color-text-muted);
  font-size: 13px;
}

.ia-usage span {
  min-height: 28px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 5px 8px;
  background: #fff6e8;
}

label {
  display: grid;
  gap: 5px;
  min-width: 0;
  max-width: 100%;
  color: var(--color-text);
  font-size: 14px;
  font-weight: 650;
}

.input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--color-text);
}

input[type="date"].input,
input[type="date"] {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}

input[type="date"]::-webkit-date-and-time-value {
  min-width: 0;
  max-width: 100%;
  text-align: left;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  flex: 0 0 auto;
  max-width: 24px;
}

textarea.input {
  resize: vertical;
}

.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.btn,
.icon-btn {
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 750;
  cursor: pointer;
  max-width: 100%;
}

.btn {
  white-space: normal;
  overflow-wrap: anywhere;
}

.btn-primary {
  background: var(--color-button);
  color: #2b1d0f;
  border-color: var(--color-button);
}

.btn-primary:hover {
  background: var(--color-button-hover);
}

.btn-secondary {
  background: var(--color-surface-muted);
  color: var(--color-text);
  border-color: var(--color-border);
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--color-primary);
  font-weight: 750;
  text-decoration: underline;
  cursor: pointer;
}

.login-link {
  justify-self: center;
  grid-column: 1 / -1;
  padding: 2px 4px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 42px;
  background: linear-gradient(180deg, #fffdf7 0%, #f1e2cb 100%);
  color: #5b3a1c;
  border-color: #d8c3a4;
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 5px 12px rgba(91, 62, 29, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.icon-btn:hover {
  background: linear-gradient(180deg, #fff8ed 0%, #e5cda9 100%);
  color: #3f2712;
}

.icon-btn:active {
  transform: translateY(1px);
  box-shadow: inset 0 2px 5px rgba(91, 62, 29, 0.16);
}

.login-footer {
  padding: 4px 0 0;
  color: var(--color-text-muted);
  font-size: 12px;
  text-align: center;
}

.icon {
  position: relative;
  display: inline-block;
  width: 20px;
  height: 20px;
}

.icon svg,
.menu-icon svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon::before,
.icon::after,
.menu-icon::before,
.menu-icon::after {
  content: none !important;
}

.menu-icon {
  width: clamp(118px, 29vw, 156px);
  height: clamp(82px, 20vw, 108px);
  border-radius: 0;
}

.menu-image {
  display: block;
  max-width: 100%;
  object-fit: contain;
  object-position: center;
  background: transparent;
  box-shadow: none;
}

.button-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
}

.export-actions {
  justify-content: flex-end;
  margin: 0 0 10px;
}

.dashboard-actions {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 10px;
}

.result-card .button-row {
  margin-top: 10px;
}

.results {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.dashboard-grid {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.dashboard-card {
  min-width: 0;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  padding: 10px;
  box-shadow: var(--shadow-sm);
}

.dashboard-card h3 {
  margin-bottom: 8px;
}

.bar-list {
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  gap: 4px;
  font-size: 12px;
}

.bar-label,
.bar-meter {
  display: grid;
  grid-template-columns: minmax(0, 120px) minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.bar-label strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.bar-label span {
  min-width: 0;
}

.bar-row span,
.axis-labels span,
.ring span {
  color: var(--color-text-muted);
}

.hbar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #eadcc7;
}

.hbar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #a16207, #d6a95f);
}

.pie-wrap {
  display: grid;
  grid-template-columns: minmax(0, 132px) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.pie {
  display: grid;
  place-items: center;
  width: 124px;
  aspect-ratio: 1;
  border-radius: 50%;
}

.pie span {
  display: grid;
  place-items: center;
  width: 72px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--color-surface);
  font-size: 12px;
  font-weight: 850;
  text-align: center;
}

.legend {
  display: grid;
  gap: 7px;
  font-size: 13px;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.ring-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 240px));
  justify-content: center;
  gap: 14px;
  min-width: 0;
}

.ring {
  display: grid;
  place-items: center;
  text-align: center;
  min-height: 206px;
  padding: 18px 14px;
  border-radius: 8px;
  background: #fff6e8;
}

.ring {
  position: relative;
}

.ring > div {
  display: grid;
  place-items: center;
  width: min(148px, 76%);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--color-surface) 0 54%, transparent 55%),
    conic-gradient(#15803d 0 var(--ring), #eadcc7 var(--ring) 360deg);
}

.ring strong {
  font-size: 18px;
}

.ring span {
  max-width: 132px;
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.project-pies {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 280px));
  justify-content: center;
  gap: 14px;
  min-width: 0;
}

.project-pie-card {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 9px;
  min-height: 248px;
  padding: 16px;
  border-radius: 8px;
  background: #fff6e8;
  text-align: center;
}

.solid-pie {
  width: min(142px, 70%);
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(36, 26, 15, 0.08);
}

.project-pie-card strong {
  max-width: 100%;
  font-size: 15px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.project-pie-card span {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1.3;
  overflow-wrap: break-word;
  text-align: left;
}

.project-pie-card i {
  margin-top: 3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.line-chart {
  width: 100%;
  max-height: 150px;
  min-height: 120px;
  border-radius: 8px;
  background: linear-gradient(180deg, #fffaf2, #fff6e8);
}

.line-chart circle {
  fill: #a16207;
}

.axis-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  overflow-x: hidden;
  max-width: 100%;
  min-width: 0;
  padding-top: 8px;
  font-size: 12px;
}

.axis-labels span {
  display: grid;
  flex: 1 1 70px;
  gap: 2px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.vertical-bars {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  min-height: 190px;
  overflow-x: hidden;
  max-width: 100%;
  min-width: 0;
  padding-bottom: 4px;
}

.vbar-item {
  display: grid;
  flex: 1 1 74px;
  grid-template-rows: 130px auto;
  gap: 8px;
  min-width: 0;
  text-align: center;
}

.vbar {
  display: flex;
  align-items: end;
  justify-content: center;
  height: 130px;
  border-radius: 8px;
  background: #eadcc7;
  overflow: hidden;
}

.vbar span {
  display: block;
  width: 100%;
  border-radius: 8px 8px 0 0;
}

.vbar-item small {
  color: var(--color-text-muted);
  font-size: 11px;
}

.balance-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr));
  gap: 10px;
  min-width: 0;
}

.balance-board section {
  padding: 10px;
  border-radius: 8px;
  background: #fff6e8;
  min-width: 0;
}

.balance-board h4 {
  margin: 0;
  font-size: 14px;
}

.balance-board header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.balance-board header strong {
  color: var(--color-primary);
  font-size: 21px;
}

.balance-board div {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px solid var(--color-border);
  min-width: 0;
}

.balance-board strong {
  font-size: 15px;
}

.result-card {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  max-width: 100%;
}

.result-card h3 {
  margin-bottom: 8px;
}

.kv {
  display: grid;
  grid-template-columns: minmax(82px, 34%) minmax(0, 1fr);
  gap: 6px 10px;
  font-size: 14px;
  min-width: 0;
}

.kv > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.kv span:nth-child(odd) {
  color: var(--color-text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--color-primary-soft);
  color: #713f12;
  font-size: 12px;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(120px);
  width: min(100% - 28px, 520px);
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: #ffffff;
  opacity: 0;
  transition: 160ms ease-in-out;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: var(--color-danger);
}

.modal {
  width: min(100% - 24px, 860px);
  max-width: calc(100vw - 24px);
  max-height: min(86vh, 86dvh);
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 14px;
  background: var(--color-background);
  box-sizing: border-box;
}

.modal-narrow {
  width: min(100% - 24px, 480px);
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.preview {
  margin-top: 12px;
}

.preview iframe,
.preview img,
.preview pre {
  width: 100%;
  max-width: 100%;
  min-height: 360px;
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #ffffff;
}

.preview pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.preview img {
  min-height: 0;
  height: auto;
  display: block;
}

.empty {
  padding: 18px;
  border: 1px dashed var(--color-border);
  border-radius: 8px;
  color: var(--color-text-muted);
  text-align: center;
}

[hidden] {
  display: none !important;
}

@media (min-width: 720px) {
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-card.wide-card {
    grid-column: 1 / -1;
  }

  .abm-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid h3,
  .form-grid label:has(textarea),
  .form-grid label:has(input[type="file"]),
  .form-grid .field-block,
  .form-grid .button-row,
  .form-grid .btn {
    grid-column: 1 / -1;
  }
}

@media (max-width: 430px) {
  .app-shell {
    width: 100%;
    max-width: 100vw;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  h1 {
    font-size: 22px;
  }

  .main-menu {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .menu-btn {
    min-height: 138px;
    padding: 10px 8px;
    gap: 8px;
    font-size: 13px;
  }

  .menu-icon {
    width: clamp(108px, 38vw, 132px);
    height: clamp(74px, 27vw, 94px);
  }

  .bar-row,
  .pie-wrap {
    grid-template-columns: 1fr;
  }

  .bar-label,
  .bar-meter,
  .kv {
    grid-template-columns: 1fr;
  }

  .bar-row {
    align-items: stretch;
  }

  .pie {
    justify-self: center;
  }

  .ring-grid,
  .project-pies {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .ring {
    min-height: auto;
    padding: 18px 14px;
  }

  .ring > div {
    width: min(150px, 58vw);
  }

  .ring strong {
    font-size: 18px;
  }

  .ring span,
  .project-pie-card span {
    font-size: 12px;
  }

  .project-pie-card {
    width: 100%;
    min-height: auto;
    padding: 18px 16px;
  }

  .solid-pie {
    width: min(152px, 58vw);
  }

  .modal {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
    padding: 12px;
  }

  .modal-header {
    align-items: flex-start;
  }

  .preview iframe,
  .preview pre {
    min-height: 280px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
