﻿:root {
  color-scheme: dark;
  --bg: #0b0f12;
  --bg-soft: #121920;
  --card: #12161c;
  --card-strong: #171e26;
  --text: #e7edf3;
  --muted: #9aa7b6;
  --accent: #ffb347;
  --accent-strong: #ff8a3d;
  --danger: #ff6b6b;
  --border: #223040;
  --shadow: rgba(0, 0, 0, 0.35);
}

body.theme-light {
  color-scheme: light;
  --bg: #f4f5f7;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --card-strong: #f0f2f6;
  --text: #1a1f25;
  --muted: #5b6572;
  --accent: #f06b1a;
  --accent-strong: #d8550f;
  --danger: #b93d3d;
  --border: #d7dbe2;
  --shadow: rgba(20, 28, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "BIZ UDPGothic", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  background: radial-gradient(circle at top, #1a222b 0%, var(--bg) 55%) fixed;
  color: var(--text);
  min-height: 100vh;
}

body.theme-light {
  background: radial-gradient(circle at top, #ffffff 0%, #eef1f6 50%) fixed;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: linear-gradient(135deg, var(--card-strong), var(--card));
  border-bottom: 1px solid var(--border);
  box-shadow: 0 8px 24px var(--shadow);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.top-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
}

.btn {
  background: var(--accent);
  border: none;
  color: #1a1a1a;
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(255, 140, 60, 0.25);
  cursor: pointer;
}

.btn:hover {
  background: var(--accent-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

.btn-small {
  padding: 6px 10px;
  font-size: 12px;
}

.top-actions .btn {
  padding: 8px 10px;
  font-size: 12px;
}

.container {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.estimate-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 10px 24px var(--shadow);
}

body:not(.plan-selected) .estimate-card:first-of-type .table-wrap,
body:not(.plan-selected) .estimate-card:first-of-type .card-list,
body:not(.plan-selected) .estimate-card:first-of-type .totals {
  display: none;
}

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

.name-row input {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
}

.honorific {
  font-weight: 700;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.plan-select-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.plan-hide-toggle {
  font-size: 12px;
  color: var(--muted);
}

.plan-hide-toggle input {
  margin: 0;
}

.section-title select {
  min-width: 20px;
}

.section-header h2 {
  margin: 0;
  font-size: 18px;
}

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

.estimate-table {
  width: auto;
  border-collapse: collapse;
  min-width: 680px;
  table-layout: fixed;
}

body.hide-tax-discount .estimate-table th:nth-child(4),
body.hide-tax-discount .estimate-table td:nth-child(4),
body.hide-tax-discount .estimate-table th:nth-child(5),
body.hide-tax-discount .estimate-table td:nth-child(5) {
  display: none;
}

body.hide-tax-discount .card-row[data-row="tax"],
body.hide-tax-discount .card-row[data-row="discount"] {
  display: none;
}

body.hide-plan-items .estimate-table tr[data-in-plan="1"] {
  display: none;
}

body.hide-plan-items .card-item[data-in-plan="1"] {
  display: none;
}

.estimate-table th,
.estimate-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px;
  text-align: left;
}

body.hide-col-unit .estimate-table th:nth-child(3),
body.hide-col-unit .estimate-table td:nth-child(3) {
  display: none;
}

body.hide-col-tax .estimate-table th:nth-child(4),
body.hide-col-tax .estimate-table td:nth-child(4) {
  display: none;
}

body.hide-col-discount .estimate-table th:nth-child(5),
body.hide-col-discount .estimate-table td:nth-child(5) {
  display: none;
}

body.hide-col-unit .card-row[data-row="unit"],
body.hide-col-tax .card-row[data-row="tax"],
body.hide-col-discount .card-row[data-row="discount"] {
  display: none;
}

.estimate-table th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.estimate-table th:nth-child(2) {
  text-align: right;
}

.estimate-table input,
.estimate-table select {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
}

.estimate-table input.autosize {
  width: auto;
  min-width: 48px;
}

.card-list {
  display: none;
  margin-top: 12px;
  gap: 10px;
}

.card-item {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: var(--card-strong);
  display: grid;
  gap: 10px;
}

.card-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: center;
}

.card-row label {
  font-size: 12px;
  color: var(--muted);
}

.card-row input,
.card-row select {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
}

.card-actions {
  display: flex;
  justify-content: flex-end;
}

.estimate-table th:nth-child(1),
.estimate-table td:nth-child(1) {
  min-width: 0;
}

.estimate-table th:nth-child(2),
.estimate-table td:nth-child(2) {
  min-width: 0;
}

.estimate-table th:nth-child(3),
.estimate-table td:nth-child(3),
.estimate-table th:nth-child(5),
.estimate-table td:nth-child(5),
.estimate-table th:nth-child(6),
.estimate-table td:nth-child(6) {
  min-width: 0;
}

.estimate-table th:nth-child(4),
.estimate-table td:nth-child(4) {
  min-width: 0;
}

.estimate-table th:nth-child(7),
.estimate-table td:nth-child(7) {
  min-width: 0;
}

.estimate-table input[type="number"] {
  max-width: 110px;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.plan-row td {
  background: var(--card-strong);
}

.plan-name {
  font-size: 14px;
}

.plan-amount-cell {
  text-align: right;
  font-weight: 700;
  font-size: 12px;
}

.row-delete {
  background: transparent;
  border: none;
  color: var(--danger);
  font-weight: 700;
  cursor: pointer;
}

.totals {
  margin-top: 16px;
  display: grid;
  gap: 8px;
  font-size: 14px;
  margin-left: 0;
  max-width: 100%;
}

.totals div {
  display: flex;
  justify-content: space-between;
}

.total-strong {
  font-size: 16px;
  font-weight: 700;
}

.dialog {
  border: none;
  width: min(92vw, 520px);
  padding: 0;
  border-radius: 18px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 20px 48px var(--shadow);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.dialog.is-open {
  display: block;
  position: fixed;
  inset: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 30;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 20;
}

.dialog-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dialog-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.open-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.open-item strong {
  font-size: 14px;
}

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

.settings-section h4 {
  margin: 0;
}

.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab-btn {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.is-active {
  background: var(--accent);
  color: #1a1a1a;
  border-color: transparent;
  box-shadow: 0 8px 18px rgba(255, 140, 60, 0.25);
}

.settings-panels {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-panel {
  display: none;
  flex-direction: column;
  gap: 10px;
}

.settings-panel.is-active {
  display: flex;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
}

.save-row {
  display: flex;
  gap: 8px;
}

.save-row input {
  flex: 1;
}

.items-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) 72px 80px 60px 28px;
  gap: 8px;
  align-items: center;
}

.items-row input[type="number"] {
  max-width: 90px;
}

.items-row select {
  min-width: 72px;
}

.items-row .icon-btn {
  justify-self: end;
}

#extra-items-list .items-row {
  grid-template-columns: minmax(0, 1.8fr) 80px 60px 28px;
}

.tax-rate-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) 80px 72px 28px;
  gap: 8px;
  align-items: center;
}

.tax-rate-row input[type="number"] {
  max-width: 90px;
}

.plan-row-grid input[type="number"] {
  max-width: 96px;
}

.plan-row-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) 32px minmax(0, 0.8fr) minmax(0, 0.8fr) 60px 36px;
  gap: 8px;
  align-items: center;
}

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

.plan-price-row input[type="number"] {
  max-width: 120px;
}

.hall-row-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 0.8fr) 60px 36px;
  gap: 8px;
  align-items: center;
}

.hall-row-grid input[type="number"] {
  max-width: 100px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--danger);
  font-weight: 700;
  cursor: pointer;
  width: 32px;
  height: 32px;
  line-height: 1;
  align-self: center;
}

.add-row td {
  padding: 6px 8px;
}

.add-row .add-btn {
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--accent);
  width: 32px;
  height: 32px;
}

.add-row .add-btn:hover {
  background: var(--card-strong);
}

.move-controls {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.move-controls .icon-btn {
  width: 28px;
  height: 28px;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.items-row input,
.items-row select {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
}

.tax-rate-row input,
.tax-rate-row select,
.tax-rate-row label {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
}

.tax-rate-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

@media (min-width: 900px) {
  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .top-actions {
    flex-wrap: nowrap;
  }

  .container {
    max-width: 960px;
    margin: 0 auto;
  }
}

@media print {
  :root {
    --print-amount-col: 120px;
  }
  body {
    background: white;
    color: black;
  }

  .estimate-table tr[data-in-plan="1"] td:nth-child(4),
  .estimate-table tr[data-in-plan="1"] td:nth-child(5) {
    visibility: hidden;
  }

  .container {
    align-items: center;
  }

  .table-wrap {
    overflow: visible !important;
  }

  .estimate-table {
    min-width: 0 !important;
    width: 100% !important;
    table-layout: fixed;
  }

  .estimate-table col[data-col="action"] {
    width: 0 !important;
  }

  .estimate-table th:nth-child(7),
  .estimate-table td:nth-child(7) {
    display: none !important;
  }

  .estimate-card:nth-of-type(2) .estimate-table td:nth-child(4) {
    font-size: 12px;
  }

  .topbar,
  .btn,
  .btn-ghost,
  .section-header button,
  dialog {
    display: none !important;
  }

  .icon-btn,
  .row-delete,
  .card-actions,
  .add-row {
    display: none !important;
  }

  .plan-hide-toggle {
    display: none !important;
  }

  input,
  select {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    color: black !important;
    padding: 0 !important;
  }

  select {
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    background-image: none !important;
  }

  .estimate-card {
    box-shadow: none;
    border: 1px solid #ccc;
    display: inline-block;
    width: min(92vw, 760px);
  }

  .estimate-table col[data-col="amount"] {
    width: var(--print-amount-col);
  }

  .estimate-table th:nth-child(6),
  .estimate-table td:nth-child(6) {
    text-align: right;
    width: var(--print-amount-col);
  }

  .estimate-table th:nth-child(2),
  .estimate-table th:nth-child(3),
  .estimate-table th:nth-child(4),
  .estimate-table th:nth-child(5),
  .estimate-table td:nth-child(2),
  .estimate-table td:nth-child(3),
  .estimate-table td:nth-child(4),
  .estimate-table td:nth-child(5) {
    text-align: right;
  }

  .estimate-table td:nth-child(2) input,
  .estimate-table td:nth-child(3) input,
  .estimate-table td:nth-child(4) select,
  .estimate-table td:nth-child(5) input,
  .estimate-table td:nth-child(6) input {
    text-align: right !important;
  }

  .estimate-table td:nth-child(4) select {
    text-align-last: right;
  }

  .estimate-table td:nth-child(6) input {
    text-align: right !important;
  }

  .plan-row td:nth-child(6),
  .plan-amount-cell {
    text-align: right;
    width: var(--print-amount-col);
  }

  .totals {
    margin-left: 0 !important;
    width: 100% !important;
  }

  .totals div {
    display: grid;
    grid-template-columns: 1fr var(--print-amount-col);
    align-items: baseline;
    gap: 8px;
  }

  .totals span {
    justify-self: start;
  }

  .totals strong {
    text-align: right;
    justify-self: end;
    min-width: 0;
    display: inline-block;
  }

  .name-row input,
  .honorific,
  .estimate-title {
    font-size: 18px;
    font-weight: 700;
    color: black;
  }

  .name-row input {
    -webkit-text-fill-color: black !important;
    opacity: 1 !important;
  }
}

.estimate-title {
  white-space: nowrap;
}

#plan-name-input,
#hall-name-input {
  width: 150px;
  max-width: 100%;
}


.app-root.is-hidden {
  display: none;
}

.login-screen.is-hidden {
  display: none;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, rgba(255, 199, 130, 0.25), rgba(10, 12, 18, 0.9)),
    linear-gradient(160deg, #0b0f1a, #171a24 60%, #141822);
}

.login-card {
  width: min(360px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 16px 34px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.login-field input {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card-strong);
  color: var(--text);
}

.login-submit {
  width: 100%;
}

.login-error {
  min-height: 18px;
  margin: 0;
  font-size: 12px;
  color: #ff9b9b;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.login-error.is-visible {
  opacity: 1;
}

.user-area {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-label {
  font-size: 12px;
  color: var(--muted);
}
