:root {
  color-scheme: light;
  --bg: #f6f2ea;
  --panel: #ffffff;
  --text: #1d1a14;
  --accent: #c34c2d;
  --muted: #6a5f52;
  --line: #dfd2c3;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #fff7ed 0%, var(--bg) 45%, #efe7db 100%);
  color: var(--text);
  min-height: 100vh;
}

.site-header {
  padding: 32px 24px 8px;
  text-align: center;
}

.brand {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.tagline {
  margin-top: 8px;
  color: var(--muted);
}

.site-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.site-link:hover {
  text-decoration: underline;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 24px;
}

.panel {
  background: var(--panel);
  border-radius: 18px;
  border: 1px solid var(--line);
  padding: 20px;
  box-shadow: 0 18px 30px -28px rgba(0, 0, 0, 0.3);
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  align-items: start;
}

.control-group {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: #fffaf3;
  display: block;
  align-self: start;
  height: fit-content;
}

.group-title {
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  list-style: none;
  cursor: pointer;
}

.group-title::-webkit-details-marker {
  display: none;
}

.group-title::after {
  content: "▾";
  float: right;
  color: var(--muted);
  transition: transform 0.2s ease;
}

.control-group[open] .group-title::after {
  transform: rotate(180deg);
}

.group-body {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button-row button {
  flex: 1 1 140px;
}

.invoice-preview {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.invoice-preview-title {
  font-weight: 600;
  color: var(--muted);
}

.invoice-preview iframe {
  width: 100%;
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8f1e7;
}

.file-input {
  position: relative;
  overflow: hidden;
  border: 1px dashed var(--accent);
  padding: 10px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  background: #fff7f1;
}

.file-input input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.select-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  color: var(--muted);
}

.select-field select {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
  background: #fff;
  color: var(--text);
}

.select-field input {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 600;
  background: #fff;
  color: var(--text);
}

button {
  border: none;
  background: var(--accent);
  color: white;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 16px -12px rgba(0, 0, 0, 0.4);
}

button:active {
  transform: translateY(0);
  box-shadow: none;
}

.status {
  margin-top: 16px;
  color: var(--muted);
}

.meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.meta.grand-total {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 2px solid var(--accent);
  background: #fff3e7;
  color: var(--text);
  font-weight: 700;
  text-align: right;
}

.tabs {
  margin-top: 16px;
}

.tabs-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tab {
  border: 1px solid var(--line);
  background: #f8f1e7;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  min-width: 120px;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tab[aria-selected="true"] {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.tab-remove {
  border: none;
  background: transparent;
  color: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0 4px;
  box-shadow: none;
  transform: none;
  border-radius: 0;
  min-width: auto;
}

.tab-remove:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tab-remove:hover,
.tab-remove:active {
  transform: none;
  box-shadow: none;
}

.tab-add {
  min-width: 48px;
  padding: 8px 12px;
}

.tab-name {
  outline: none;
}

.tab-name[contenteditable="true"]:focus {
  background: rgba(255, 255, 255, 0.4);
  border-radius: 6px;
}

.sheet {
  background: var(--panel);
  border-radius: 18px;
  border: 1px solid var(--line);
  padding: 16px;
  min-height: 300px;
  overflow-x: auto;
}

.sheet-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

.sheet-table th,
.sheet-table td {
  border: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  min-width: 120px;
}

.sheet-table th {
  background: #f3ebe0;
  font-weight: 600;
  position: relative;
}

.sheet-table td {
  background: #ffffff;
}

.price-row td {
  background: #fff3e7;
  font-weight: 600;
}

.sum-header {
  text-align: right;
  background: #ecd8c8;
}

.sum-cell {
  text-align: right;
  font-weight: 600;
  background: #f9f3ea;
}



.drag-indicator {
  display: inline-block;
  margin-right: 6px;
  font-size: 14px;
  line-height: 1;
  opacity: 0.75;
  cursor: grab;
  user-select: none;
  pointer-events: auto;
}

.row-drag-indicator {
  display: inline-block;
  margin-right: 6px;
  font-size: 14px;
  line-height: 1;
  opacity: 0.75;
  cursor: grab;
  user-select: none;
  pointer-events: auto;
}

.sheet-table th[contenteditable],
.sheet-table td[contenteditable] {
  outline: 2px solid transparent;
}

.sheet-table th .header-text {
  outline: none;
}

.sheet-table th .header-text:focus,
.sheet-table td[contenteditable]:focus {
  outline-color: var(--accent);
  background: #fff5ec;
}

.col-resize-handle {
  position: absolute;
  top: 0;
  right: -1px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
}

.col-dragging {
  opacity: 0.6;
}

.row-dragging {
  opacity: 0.6;
}

.no-select {
  user-select: none;
}

.site-footer {
  text-align: center;
  padding: 12px 24px 28px;
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 720px) {
  .controls {
    grid-template-columns: 1fr;
  }

  button,
  .file-input,
  .select-field {
    width: 100%;
    text-align: center;
  }

  .select-field select {
    width: 100%;
    text-align: center;
  }

  .select-field input {
    width: 100%;
    text-align: center;
  }

  .sheet-table {
    min-width: 480px;
  }
}
