:root {
  --bg: #f2f2f2;
  --surface: #ffffff;
  --surface-2: #f7f7f7;
  --text: #111111;
  --muted: #555555;
  --accent: #111111;
  --accent-dark: #000000;
  --danger: #222222;
  --line: #d6d6d6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: linear-gradient(150deg, #fcfcfc 0%, #efefef 60%, #f7f7f7 100%);
  color: var(--text);
}

.topbar {
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  min-height: 78px;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar-logo-wrap {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

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

.topbar-search {
  width: min(460px, 50vw);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  background: #fff;
}

.brand-logo {
  width: 180px;
  height: auto;
  filter: grayscale(100%);
}

.container {
  max-width: 1200px;
  margin: 18px auto;
  padding: 0 16px 30px;
}

.tools-panel {
  margin-bottom: 14px;
}

.tools-selector {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #d5dce3;
  background: rgba(255, 255, 255, 0.88);
  color: #334150;
  padding: 9px 13px;
  border-radius: 12px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.tools-selector:hover {
  background: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.tools-selector::-webkit-details-marker {
  display: none;
}

.tools-selector::before {
  content: '▸';
  font-size: 12px;
  transition: transform 0.2s ease;
}

.tools-panel[open] .tools-selector::before {
  transform: rotate(90deg);
}

.tools-panel[open] .top-widgets {
  margin-top: 12px;
  animation: tools-reveal 0.28s ease;
}

@keyframes tools-reveal {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.filters-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 16px;
  padding: 12px;
  background: #fafafa;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-group h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #333;
  margin: 0;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.filter-group-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.filter-group-content label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  margin: 0;
}

.filter-group-content .series-filter-label {
  flex-direction: row;
  gap: 6px;
  white-space: nowrap;
}

.filter-label-text {
  font-weight: 600;
  color: #666;
}

.series-filter-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  color: #333;
  cursor: pointer;
  margin: 0;
  justify-content: flex-start;
}

.series-filter-label input[type="checkbox"] {
  cursor: pointer;
}

.filter-date-input,
.filter-amount-input {
  padding: 6px 8px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 4px;
  width: 100%;
  box-sizing: border-box;
}

.filter-date-input:focus,
.filter-amount-input:focus {
  outline: none;
  border-color: #0066cc;
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.1);
}

.actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.actions-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.series-inline-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #4b5765;
  font-weight: 700;
}

button,
.secondary,
a.secondary {
  appearance: none;
  background-color: #FAFBFC;
  border: 1px solid rgba(27, 31, 35, 0.15);
  border-radius: 6px;
  box-shadow: rgba(27, 31, 35, 0.04) 0 1px 0, rgba(255, 255, 255, 0.25) 0 1px 0 inset;
  box-sizing: border-box;
  color: #24292E;
  cursor: pointer;
  display: inline-block;
  font-family: -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  list-style: none;
  padding: 6px 16px;
  position: relative;
  transition: background-color 0.2s cubic-bezier(0.3, 0, 0.5, 1);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  vertical-align: middle;
  white-space: nowrap;
  word-wrap: break-word;
}

button:hover,
.secondary:hover,
a.secondary:hover {
  background-color: #F3F4F6;
  text-decoration: none;
  transition-duration: 0.1s;}

.secondary {
  text-decoration: none;
}

#new-invoice-btn {
  background: #0b63d8;
  border-color: #0b63d8;
  font-size: 18px;
  padding: 14px 24px;
  border-radius: 10px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color:#fff;
}

#new-invoice-btn:hover {
  background: #0953b3;
  border-color: #0953b3;
}

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

.top-widgets {
  display: flex;
  gap: 12px;
  margin-bottom: 52px;
  align-items: stretch;
}

.calc-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  width: min(500px, 100%);
  flex: 0 0 min(500px, 100%);
}

.filter-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  width: min(360px, 100%);
}

.filter-card h2 {
  font-size: 14px;
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.series-filter-grid {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 0;
}

.series-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  border: none;
  background: transparent;
  border-radius: 0;
  padding: 0;
  transition: none;
}

.series-chip input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: #0b63d8;
  cursor: pointer;
  flex: 0 0 auto;
}

.series-chip span {
  color: #2b3a49;
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
}

.series-chip input:checked + span {
  color: #1f2d3a;
}

.notes-card {
  background: linear-gradient(145deg, #fff7b8 0%, #ffe98a 100%);
  border: 1px solid #e0c964;
  border-radius: 10px;
  padding: 12px;
  flex: 1;
  width: auto;
  box-shadow: none;
  transform: rotate(-0.5deg);
  display: flex;
  flex-direction: column;
}

.notes-card h2 {
  margin: 0 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #5a4a11;
}

#quick-notes {
  width: 100%;
  margin: 0;
  border: none;
  border-radius: 0;
  padding: 8px 2px;
  resize: vertical;
  background: transparent;
  color: #3b300c;
  min-height: 230px;
  flex: 1;
}

#quick-notes:focus {
  outline: none;
}

#save-notes {
  margin-top: auto;
  align-self: flex-end;
  min-width: 110px;
  width: auto;
  padding: 8px 14px;
  background: linear-gradient(180deg, #efce8a 0%, #ddb86f 100%);
  border: 1px solid #8f6e2a;
  color: #2b210d;
  border-radius: 9px;
  font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65), 0 2px 0 #8a6a28;
}

#save-notes:hover {
  background: linear-gradient(180deg, #f4d794 0%, #e6c173 100%);
}

#save-notes:active {
  transform: translateY(1px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 1px 0 #24292e;
}

.calc-card h2 {
  font-size: 14px;
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.calc-shell {
  border: 1px solid #2f3439;
  border-radius: 14px;
  background: linear-gradient(160deg, #4f555b 0%, #2f3439 100%);
  padding: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 7px 16px rgba(0, 0, 0, 0.18);
  user-select: none;
}

.calc-display {
  background: linear-gradient(180deg, #d3e6cc 0%, #bdd8b4 100%);
  border: 1px solid #8ba388;
  border-radius: 8px;
  color: #1f2e1e;
  font-family: "Courier New", Courier, monospace;
  font-size: 24px;
  padding: 10px 12px;
  margin-bottom: 10px;
  text-align: right;
  min-height: 50px;
  line-height: 1.2;
  font-weight: 700;
  overflow: hidden;
  white-space: nowrap;
}

.calc-pad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.calc-key {
  border: 1px solid #282d32;
  border-radius: 10px;
  background: linear-gradient(180deg, #fafafa 0%, #dcdcdc 100%);
  color: #101010;
  padding: 10px 0;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: inset 0 1px 0 #ffffff, 0 2px 0 #24292e;
}

.calc-key:hover {
  background: linear-gradient(180deg, #ffffff 0%, #e9e9e9 100%);
}

.calc-key:active {
  transform: translateY(1px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 1px 0 #24292e;
}

.calc-key-fn {
  background: linear-gradient(180deg, #efce8a 0%, #ddb86f 100%);
}

.calc-key-op {
  background: linear-gradient(180deg, #94a8c4 0%, #788faa 100%);
}

.calc-key-eq {
  background: linear-gradient(180deg, #77b4f6 0%, #4b91e2 100%);
  color: #fff;
  grid-row: span 2;
}

.calc-key-zero {
  grid-column: span 2;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border-radius: 10px;
  overflow: visible;
  border: 1px solid var(--line);
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.06);
}

th,
td {
  border-bottom: 1px solid #e9e9e9;
  text-align: left;
  padding: 12px 10px;
  vertical-align: middle;
  font-size: 12px;
}

th {
  background: #f4f4f4;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 2px solid #cfcfcf;
}

tbody tr:nth-child(odd) {
  background: #fff;
}

tbody tr:nth-child(even) {
  background: #fafafa;
}

tbody tr:hover {
  background: #f1f1f1;
}

.actions-cell {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  white-space: nowrap;
  justify-content: flex-end;
  position: relative;
}

.invoices-table th.actions-col {
  text-align: right;
}

.actions-menu-container {
  position: relative;
  display: inline-block;
}

.actions-menu-btn {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  transition: all 0.2s ease;
}

.actions-menu-btn:hover {
  background: #e8e8e8;
  border-color: var(--accent);
}

.actions-menu-btn[aria-expanded="true"] {
  background: var(--accent);
  color: var(--surface);
  border-color: var(--accent);
}

.actions-menu-dropdown {
  position: fixed;
  top: 0;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  min-width: 140px;
  max-width: calc(100vw - 24px);
  display: none;
  padding: 8px;
}

.actions-menu-dropdown.open {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.actions-menu-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.2;
  transition: background 0.15s ease, border-color 0.15s ease;
  text-decoration: none;
}

.actions-menu-item:hover {
  background: #ececec;
  border-color: #c8c8c8;
}

.actions-menu-item.delete-btn {
  color: #c71616;
  border-color: #e2b9b9;
  background: #fff7f7;
}

.actions-menu-item.delete-btn:hover {
  background: #ffecec;
  border-color: #d89a9a;
}

.actions-menu-item.action-send {
  background: #edf9ef;
  border-color: #9cd3a4;
  color: #18652a;
}

.actions-menu-item.action-send:hover {
  background: #ddf2e1;
  border-color: #79bc84;
}

.actions-menu-form {
  margin: 0;
  border: none;
  background: none;
  padding: 0;
  width: 100%;
}

.actions-menu-form button {
  font: inherit;
}

.actions-cell .secondary,
.actions-cell .danger,
.actions-cell a.secondary,
.actions-cell button {
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.1;
}

.inline-action-form {
  margin: 0;
}

.actions-cell .danger {
  background: #c71616;
  border-color: #9f0f0f;
}

.actions-cell .danger:hover {
  background: #a91010;
}

.bulk-bar {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

.alert {
  background: rgb(174, 227, 153);
  color: #111;
  border: 1px solid #d1d1d1;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-weight: 600;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 99;
}

.hidden {
  display: none;
}

.modal-card {
  width: min(980px, 100%);
  max-height: 95vh;
  overflow: auto;
  background: var(--surface);
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 16px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: block;
  font-weight: 600;
  color: #333;
}

input,
select {
  width: 100%;
  margin-top: 5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px;
}

textarea {
  width: 100%;
  margin-top: 5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px;
}

.items-section {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.items-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.item-row {
  display: grid;
  grid-template-columns: 1.2fr 0.6fr 0.8fr 0.8fr auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: start;
}

.item-row .item-name {
  min-height: 76px;
  resize: vertical;
}

.items-columns {
  display: grid;
  grid-template-columns: 1.2fr 0.6fr 0.8fr 0.8fr auto;
  gap: 8px;
  margin: 8px 0 10px;
  color: #66707a;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.totals {
  margin-top: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.form-footer {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.suggestions {
  position: relative;
  margin-top: 4px;
}

.suggestion {
  width: 100%;
  text-align: left;
  border-radius: 0;
  border: 1px solid #ddd;
  border-top: none;
  background: #fff;
  color: #222;
}

.sort-btn {
  border: none;
  background: transparent;
  color: #111;
  padding: 0;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sort-btn.active-sort {
  color: #000;
}

.sort-btn:hover {
  background: #efefef;
  color: #111;
}

.sort-arrow {
  font-size: 11px;
  line-height: 1;
  min-width: 12px;
  text-align: center;
}

.invoices-table th.amount-col,
.invoices-table td.amount-col {
  text-align: right;
  white-space: nowrap;
}

.invoices-table th.amount-col .sort-btn {
  width: 100%;
  justify-content: flex-end;
}

.hidden-form {
  display: none;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(420px, 92vw);
  background: var(--surface);
  border: 1px solid #dcdcdc;
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.07);
}

.auth-head {
  text-align: center;
  margin-bottom: 14px;
}

.auth-logo {
  width: 145px;
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto 10px;
  filter: grayscale(100%);
}

.auth-head h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.01em;
}

.auth-head p {
  margin: 6px 0 0;
  color: #666;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-submit {
  width: 100%;
  margin-top: 10px;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
}

.settings-card h2 {
  margin: 0 0 14px;
}

.settings-card h3 {
  margin: 20px 0 10px;
  font-size: 16px;
}

.settings-help {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.settings-series-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.settings-full {
  grid-column: 1 / -1;
}

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

  .settings-grid,
  .settings-series-grid {
    grid-template-columns: 1fr;
  }

  .item-row {
    grid-template-columns: 1fr;
  }

  .filters-section {
    grid-template-columns: 1fr;
  }

  .items-columns {
    display: none;
  }

  .top-widgets {
    flex-direction: column;
  }

  .tools-selector {
    width: 100%;
    justify-content: center;
  }

  .calc-card {
    width: 100%;
    flex: 1 1 auto;
  }

  .topbar {
    min-height: unset;
  }

  .topbar-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }

  .topbar-logo-wrap {
    justify-content: center;
  }

  .topbar-tools {
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-search {
    width: 100%;
    align-self: stretch;
  }

  .brand-logo {
    width: 170px;
  }

  .actions-cell {
    flex-direction: column;
    white-space: normal;
    position: relative;
  }

  .series-filter-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .actions-left {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  table,
  thead,
  tbody,
  th,
  td,
  tr {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    border: 1px solid var(--line);
    margin-bottom: 10px;
    border-radius: 10px;
    overflow: hidden;
  }

  td {
    border-bottom: 1px solid #eee;
  }
}
