:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --panel: #ffffff;
  --text: #18202a;
  --muted: #66717f;
  --border: #d9dfe6;
  --soft: #eef2f6;
  --primary: #1f5fbf;
  --primary-dark: #164a96;
  --danger: #b42318;
  --success: #18794e;
  --warning: #8a6116;
  --shadow: 0 8px 24px rgba(23, 35, 52, .08);
  --radius: 14px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

.app {
  width: min(1500px, calc(100% - 40px));
  margin: 28px auto 60px;
}

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

h1 {
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: -.025em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  max-width: 820px;
}

.header-tools {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.memory-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #b9d8c9;
  background: #eef9f3;
  color: var(--success);
  padding: 9px 12px;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
}

.memory-badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.install-app-button {
  min-height: 42px;
  height: auto;
  border-color: #9bbce8;
  background: #edf5ff;
  color: var(--primary-dark);
  white-space: normal;
}

.install-app-button:hover {
  border-color: #79a3dc;
  background: #e1efff;
}

.install-device-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-title h2 {
  margin: 0;
  font-size: 18px;
}

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

.grid {
  display: grid;
  grid-template-columns: 1.1fr 1.25fr .75fr .55fr;
  gap: 14px;
}

label {
  display: block;
  color: #364152;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}

input, select, button {
  font: inherit;
}

input, select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  padding: 0 11px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 95, 191, .12);
}

input.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(180, 35, 24, .10);
}

.date-field {
  min-width: 0;
}

.date-field label {
  color: var(--danger);
  font-size: 14px;
}

.date-input-wrap {
  position: relative;
}

.date-input-wrap input {
  color: transparent;
  cursor: pointer;
}

.date-input-wrap input::-webkit-datetime-edit {
  color: transparent;
}

.date-input-wrap input::-webkit-datetime-edit-day-field:focus,
.date-input-wrap input::-webkit-datetime-edit-month-field:focus,
.date-input-wrap input::-webkit-datetime-edit-year-field:focus {
  color: transparent;
  background: transparent;
}

.date-input-wrap input::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 1;
}

.date-readable {
  position: absolute;
  top: 50%;
  left: 12px;
  max-width: calc(100% - 48px);
  overflow: hidden;
  color: var(--text);
  font-size: 16px;
  font-weight: 750;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
  transform: translateY(-50%);
}

button {
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0 14px;
  background: #fff;
  color: #263244;
  font-weight: 750;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background .15s, border-color .15s, transform .05s;
  text-decoration: none;
  white-space: nowrap;
}

button:hover {
  background: var(--soft);
  border-color: #bfc8d2;
}

button:active {
  transform: translateY(1px);
}

button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

button.primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

button.danger {
  color: var(--danger);
}

button.small {
  height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.description-editor {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  margin-bottom: 18px;
  padding: 18px;
  border: 2px solid #9bbce8;
  border-radius: 12px;
  background: #f2f7ff;
}

.step-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
}

.description-editor label {
  margin-bottom: 4px;
  color: var(--text);
  font-size: 18px;
}

.description-help {
  margin: 0 0 12px;
  color: #4b5d73;
  font-size: 15px;
}

.description-editor input {
  height: 48px;
  border-color: #9bbce8;
  font-size: 17px;
  font-weight: 700;
}

.automatic-note {
  display: block;
  margin-top: 8px;
  color: var(--success);
  font-size: 14px;
  font-weight: 750;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 11px;
}

table {
  width: 100%;
  min-width: 1080px;
  table-layout: fixed;
  border-collapse: collapse;
  background: #fff;
}

th, td {
  border-bottom: 1px solid var(--border);
  padding: 9px;
  vertical-align: middle;
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f6f8fa;
  color: #4c5868;
  font-size: 12px;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.table-header-hint {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0;
  text-transform: none;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfd; }

th:nth-child(1), td.index { width: 44px; }
th:nth-child(2), td.name { width: 170px; }
th:nth-child(3), td.iban { width: 265px; }
th:nth-child(4), td.amount { width: 140px; }
th:nth-child(5), td.description { width: 265px; }
th:nth-child(6), td.tckn { width: 130px; }
th:nth-child(7), td.actions { width: 70px; }

td.index {
  text-align: center;
  color: var(--muted);
  font-weight: 700;
}

td.actions { text-align: center; }

td input {
  height: 38px;
  font-size: 14px;
}

.description-control {
  display: flex;
  align-items: center;
  gap: 7px;
}

.description-control input:disabled {
  background: #f1f3f5;
  color: #66717f;
  opacity: 1;
  cursor: not-allowed;
}

.description-control input {
  min-width: 0;
  flex: 1;
}

.description-control.has-custom input:disabled {
  border-color: #d8b260;
  background: #fff8e8;
  color: #5f4813;
}

button.edit-description {
  width: 38px;
  min-width: 38px;
  padding: 0;
  font-size: 19px;
}

.special-description-badge {
  display: block;
  margin-top: 4px;
  color: var(--warning);
  font-size: 11px;
  font-weight: 800;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.metric {
  background: #f7f9fb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.metric .k {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.metric .v {
  font-weight: 800;
  font-size: 18px;
}

.footer-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-panel {
  text-align: center;
}

.footer-panel .footer-actions {
  justify-content: center;
}

.footer-panel .status {
  text-align: center;
}

.status {
  margin-top: 14px;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  display: none;
  white-space: pre-line;
}

.status.show { display: block; }
.status.error {
  background: #fff1f0;
  border: 1px solid #f0b8b3;
  color: var(--danger);
}

.status.success {
  background: #eef9f3;
  border: 1px solid #b9d8c9;
  color: var(--success);
}

.status.warning {
  background: #fff8e8;
  border: 1px solid #ead39e;
  color: var(--warning);
}

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

.saved-at {
  color: var(--muted);
  font-size: 12px;
  margin-left: 4px;
}

dialog {
  width: min(640px, calc(100% - 40px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 0;
  border: 0;
  border-radius: 16px;
  color: var(--text);
  box-shadow: 0 24px 80px rgba(20, 30, 45, .28);
}

dialog::backdrop {
  background: rgba(18, 25, 35, .55);
}

.modal-content {
  padding: 24px;
}

.modal-content h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.modal-intro {
  margin: 0 0 18px;
  color: var(--muted);
}

.modal-summary {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 11px;
}

.modal-summary-row {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-summary-row:last-child {
  border-bottom: 0;
}

.modal-summary-label {
  color: var(--muted);
  font-weight: 700;
}

.special-summary-list {
  display: grid;
  gap: 8px;
}

.special-summary-item {
  padding: 9px 10px;
  border-radius: 8px;
  background: #fff8e8;
  color: #5f4813;
}

.confirm-question {
  margin: 20px 0 14px;
  font-size: 18px;
  font-weight: 800;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.install-steps {
  display: grid;
  gap: 12px;
  margin: 0 0 18px;
  padding-left: 28px;
}

.install-steps li {
  padding-left: 4px;
  font-size: 17px;
  font-weight: 700;
}

.install-note {
  margin: 0 0 20px;
  padding: 13px 14px;
  border: 1px solid #b9d8c9;
  border-radius: 10px;
  background: #eef9f3;
  color: #145c3d;
}

@media (max-width: 1100px) {
  .app {
    width: calc(100% - 24px);
    margin-top: 20px;
  }

  header {
    flex-wrap: wrap;
  }

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

@media (max-width: 1024px) {
  .app {
    margin: 16px auto 36px;
  }

  header {
    flex-direction: column;
    gap: 12px;
  }

  header > div:last-child {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
  }

  .header-tools {
    justify-content: flex-start;
  }

  .saved-at {
    margin-left: 0;
  }

  .panel {
    padding: 16px;
  }

  .panel-title {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    border-radius: 0;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100% !important;
  }

  table {
    min-width: 0;
    table-layout: auto;
    background: transparent;
  }

  thead {
    display: none;
  }

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

  tbody tr {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: #fff;
  }

  tbody tr:hover {
    background: #fff;
  }

  tbody tr:last-child td,
  td {
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
  }

  td::before {
    content: attr(data-label);
    color: #4c5868;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .02em;
    text-transform: uppercase;
  }

  td.index {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f6f8fa;
    color: var(--text);
    font-size: 16px;
  }

  td.index::before {
    content: attr(data-label);
  }

  td.actions {
    border-bottom: 0;
  }

  td.actions button {
    justify-self: end;
    min-width: 88px;
  }

  td input {
    height: 44px;
  }

  .description-control,
  .special-description-badge {
    grid-column: 2;
  }

  button.edit-description {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }

}

@media (max-width: 700px) {
  tbody,
  .summary {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app {
    width: calc(100% - 16px);
    margin-top: 8px;
  }

  h1 {
    font-size: 24px;
  }

  .subtitle {
    font-size: 14px;
  }

  .panel {
    padding: 14px;
    border-radius: 12px;
  }

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

  .description-editor {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 10px;
    padding: 14px;
  }

  .step-number {
    width: 34px;
    height: 34px;
    font-size: 17px;
  }

  .description-editor label {
    font-size: 16px;
  }

  .description-help {
    font-size: 14px;
  }

  tbody tr:last-child td,
  td {
    grid-template-columns: 96px minmax(0, 1fr);
  }

  td.iban input {
    font-size: 12px;
    letter-spacing: -.15px;
  }

  .footer-panel .footer-actions button {
    width: 100%;
  }

  dialog {
    width: calc(100% - 16px);
    max-height: calc(100vh - 16px);
    border-radius: 12px;
  }

  .modal-content {
    padding: 18px;
  }

  .modal-content h2 {
    font-size: 20px;
  }

  .modal-summary-row {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .modal-actions {
    flex-direction: column;
  }

  .modal-actions button {
    width: 100%;
  }

  .header-tools,
  .install-app-button {
    width: 100%;
  }
}
