:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1a1d26;
  --text-muted: #6b7280;
  --border: #e5e8ef;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

/* Header */
.header {
  margin-bottom: 1.5rem;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.header__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  font-size: 1.1rem;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
}

.header__title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header__subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stats__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
}

.stats__label {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.stats__value {
  margin: 0.35rem 0 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--primary);
  line-height: 1.1;
}

/* Layout */
.main {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.35rem;
}

.card__title {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.card__head .card__title {
  margin-bottom: 0;
}

.card__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 0.85rem;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
}

.sort {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.sort__label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.sort__select {
  font: inherit;
  font-size: 0.875rem;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none'%3E%3Cpath d='M6 9l6 6 6-6' stroke='%236b7280' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
}

.sort__select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

/* Form */
.form__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field__label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.field__input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field__input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
  background: var(--surface);
}

.field__input--area {
  resize: vertical;
  min-height: 88px;
}

#form-status {
  margin: 0.75rem 0 0;
}

#form-status:not(:empty) {
  margin-bottom: 0.5rem;
}

.form__actions {
  margin-top: 0.25rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.15rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

.btn--primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn--danger {
  color: var(--danger);
  background: var(--danger-soft);
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
}

.btn--danger:hover:not(:disabled) {
  color: #fff;
  background: var(--danger);
}

.btn--ghost {
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
}

.btn--ghost:hover:not(:disabled) {
  background: #eef0f4;
}

/* Delete dialog */
.dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: calc(100vw - 2rem);
  width: 22rem;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog__box {
  padding: 1.25rem 1.35rem 1.15rem;
  margin: 0;
}

.dialog__title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.dialog__text {
  margin: 0.5rem 0 1.15rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Search */
.search {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}

.search__icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search__input {
  width: 100%;
  padding: 0.55rem 0.85rem 0.55rem 2.35rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search__input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
  background: var(--surface);
}

/* Status */
.status {
  min-height: 0;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
}

.status--error {
  color: var(--danger);
  padding: 0.5rem 0.75rem;
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
}

.status--success {
  color: #047857;
  padding: 0.5rem 0.75rem;
  background: #ecfdf5;
  border-radius: var(--radius-sm);
}

.status--info {
  color: #3730a3;
  padding: 0.5rem 0.75rem;
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
}

/* Table */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.25rem;
  padding: 0 0.25rem;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  padding: 0.75rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg);
  white-space: nowrap;
}

.table tbody tr:hover {
  background: #fafbfc;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table__actions-col {
  width: 1%;
  white-space: nowrap;
}

.table__comment {
  max-width: 280px;
  word-break: break-word;
}

.table__empty td {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 1rem;
}

.table__hint {
  margin: 0.75rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer p {
  margin: 0;
}

/* Mobile cards for table rows */
@media (max-width: 768px) {
  .stats {
    grid-template-columns: 1fr;
  }

  .stats__value {
    font-size: 1.5rem;
  }

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

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

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

  .search {
    max-width: none;
  }

  .sort__select {
    width: 100%;
  }

  .table thead {
    display: none;
  }

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

  .table tr {
    margin-bottom: 0.85rem;
    padding: 0.85rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
  }

  .table tr:hover {
    background: var(--bg);
  }

  .table td {
    padding: 0.35rem 0;
    border: none;
  }

  .table td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
  }

  .table td.table__cell-actions {
    margin-top: 0.65rem;
    padding-top: 0.65rem;
    border-top: 1px solid var(--border);
  }

  .table td.table__cell-actions::before {
    display: none;
  }

  .table__empty td {
    display: block;
  }

  .table__empty td::before {
    display: none;
  }
}

@media (max-width: 480px) {
  .app {
    padding: 1rem 0.75rem 1.5rem;
  }

  .card {
    padding: 1rem;
  }
}
