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

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f4f5f7;
  color: #1a1a1a;
  line-height: 1.5;
}

header {
  background: #1e293b;
  color: #f8fafc;
  padding: 1.25rem 2rem;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logout-form {
  margin: 0;
}

header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.subtitle {
  margin: 0.25rem 0 0;
  opacity: 0.75;
  font-size: 0.9rem;
}

.btn-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  background: rgba(255, 255, 255, 0.1);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.18);
}

.btn-icon-muted {
  background: transparent;
}

.btn-icon-muted:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-icon-record {
  background: transparent;
  color: #94a3b8;
  border: none;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 4px;
}

.btn-icon-record:hover {
  background: #f1f5f9;
  color: #475569;
}

.btn-icon-save {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.btn-icon-save:hover {
  background: #1d4ed8;
}

.field-body-action .btn-icon-save {
  align-self: stretch;
  height: auto;
  min-height: 2rem;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.login-card h1 {
  margin: 0;
  font-size: 1.5rem;
}

.settings-section {
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.75rem 0.85rem;
  margin: 0 0 0.75rem;
}

.settings-section legend {
  padding: 0 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
}

.checkbox-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: normal;
  margin-top: 0.35rem;
}

.checkbox-label input {
  width: auto;
  margin: 0;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}

.card {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.count {
  font-weight: normal;
  color: #64748b;
  font-size: 0.9rem;
}

.hint {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: #64748b;
}

.empty {
  color: #64748b;
  font-style: italic;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.flash-ok {
  background: #dcfce7;
  color: #166534;
}

.flash-error {
  background: #fee2e2;
  color: #991b1b;
}

.compact-form {
  display: grid;
  gap: 0.5rem;
}

.settings-form label:not(.checkbox-label) {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(4.5rem, auto) 1fr;
  gap: 0.5rem 0.65rem;
  align-items: start;
  margin-bottom: 0.5rem;
}

.field-row:last-child {
  margin-bottom: 0;
}

.field-row-stack {
  grid-template-columns: 1fr;
  gap: 0.3rem;
}

.field-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  line-height: 1.3;
  padding-top: 0.45rem;
}

.field-row-stack .field-label {
  padding-top: 0;
}

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

.field-body-action {
  display: flex;
  gap: 0.35rem;
  align-items: stretch;
}

.field-body-action input,
.field-body-action textarea {
  flex: 1;
  min-width: 0;
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: normal;
  font-family: inherit;
}

textarea {
  resize: vertical;
  min-height: 3.5rem;
}

button {
  padding: 0.45rem 0.9rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
}

button:hover {
  background: #1d4ed8;
}

.btn-compact {
  flex-shrink: 0;
  padding: 0.4rem 0.65rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

.btn-danger {
  background: #dc2626;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-compact-danger {
  width: 100%;
}

.records {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.record {
  position: relative;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  overflow: hidden;
}

.record .record-manage-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.35rem;
  z-index: 1;
}

.record-body {
  padding: 0.75rem 2rem 0.5rem 0.85rem;
}

.record-text {
  font-size: 1.05rem;
  font-weight: 500;
  color: #0f172a;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.record-comments {
  list-style: none;
  margin: 0.45rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.record-comment {
  font-size: 0.78rem;
  font-weight: normal;
  color: #64748b;
  line-height: 1.35;
  word-break: break-word;
}

.record-comment::before {
  content: "— ";
  color: #cbd5e1;
}

.record-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.3rem 0.65rem;
  border-top: 1px solid #f1f5f9;
  background: #fafbfc;
  font-size: 0.68rem;
  color: #94a3b8;
  line-height: 1.2;
}

.record-meta {
  font-variant-numeric: tabular-nums;
}

.record-priority {
  margin-right: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.25rem;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background: #f59e0b;
  border-radius: 999px;
}

body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 8px;
  padding: 1rem 1.15rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

.modal-dialog-wide {
  max-width: 520px;
}

.modal-dialog h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  padding-right: 2rem;
}

.modal-close {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #64748b;
  font-size: 1.25rem;
  line-height: 1;
}

.modal-close:hover {
  background: #f1f5f9;
  color: #334155;
}

.modal-section {
  padding: 0.65rem 0;
  border-bottom: 1px solid #f1f5f9;
}

.modal-section:first-of-type {
  padding-top: 0;
}

.modal-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.modal-section-danger {
  padding-top: 0.75rem;
}

.modal-comments-list {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.modal-comments-list.is-empty {
  display: none;
}

.modal-comment-item {
  font-size: 0.82rem;
  color: #334155;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
  word-break: break-word;
}

.comment-add-form {
  margin: 0;
}

code {
  background: #f1f5f9;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.85em;
}

/* --- Mobile --- */
@media (max-width: 640px) {
  header {
    padding: 0.85rem 1rem;
    padding-top: max(0.85rem, env(safe-area-inset-top));
  }

  header h1 {
    font-size: 1.25rem;
  }

  .subtitle {
    font-size: 0.8rem;
  }

  main {
    padding: 0.75rem;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }

  .card {
    padding: 1rem;
    border-radius: 10px;
  }

  .card h2 {
    font-size: 1rem;
  }

  .hint {
    font-size: 0.75rem;
  }

  .record-body {
    padding: 0.65rem 1.85rem 0.4rem 0.65rem;
  }

  .record-text {
    font-size: 1rem;
  }

  .record-comment {
    font-size: 0.75rem;
  }

  .record-footer {
    padding: 0.25rem 0.55rem;
    font-size: 0.65rem;
  }

  .record .record-manage-btn {
    top: 0.3rem;
    right: 0.25rem;
    width: 1.65rem;
    height: 1.65rem;
  }

  .btn-icon-save {
    width: 2.25rem;
    min-width: 2.25rem;
    min-height: 2.25rem;
  }

  .header-actions .btn-icon {
    width: 2.25rem;
    height: 2.25rem;
  }

  .field-row:not(.field-row-stack) {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }

  .field-label {
    font-size: 0.68rem;
    padding-top: 0;
  }

  .field-body-action {
    flex-direction: row;
    align-items: center;
  }

  .btn-compact {
    align-self: auto;
    min-height: auto;
    padding: 0.35rem 0.55rem;
    font-size: 0.72rem;
  }

  .settings-form > .btn-compact {
    width: auto;
    align-self: flex-start;
  }

  input[type="text"],
  input[type="password"],
  input[type="number"],
  textarea {
    font-size: 16px;
  }

  textarea {
    min-height: 4.5rem;
  }

  .modal {
    align-items: flex-end;
    padding: 0;
  }

  .modal-dialog {
    max-width: none;
    width: 100%;
    max-height: min(92vh, 100dvh);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 14px 14px 0 0;
    padding: 0.85rem 0.85rem max(0.85rem, env(safe-area-inset-bottom));
    margin: 0;
  }

  .modal-close {
    width: 2.25rem;
    height: 2.25rem;
  }

  .settings-section {
    padding: 0.65rem 0.75rem;
  }

  .login-page {
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .login-card {
    padding: 1.25rem;
  }
}

@media (max-width: 380px) {
  .subtitle {
    display: none;
  }
}
