:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: #f4f6f8;
  color: #18202a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

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

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

h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: 0;
}

p {
  margin: 4px 0 0;
  color: #67717f;
}

.status {
  min-width: 150px;
  padding: 9px 12px;
  border: 1px solid #cfd7df;
  border-radius: 8px;
  background: #ffffff;
  text-align: center;
  color: #526071;
}

.status.ok {
  border-color: #87c8a2;
  color: #17693c;
}

.status.warn {
  border-color: #e4ba7d;
  color: #8b5100;
}

.ghost-link {
  display: inline-flex;
  height: 40px;
  align-items: center;
  border: 1px solid #d7dee6;
  border-radius: 7px;
  padding: 0 13px;
  background: #ffffff;
  color: #526071;
  text-decoration: none;
}

.ghost-link:hover {
  border-color: #9bb7df;
  color: #234a84;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid #dce3ea;
  border-radius: 8px;
  background: #ffffff;
  padding: 24px;
  box-shadow: 0 18px 50px rgba(24, 32, 42, 0.08);
}

.login-panel h1 {
  margin-bottom: 4px;
}

.login-panel form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.summary > div,
.panel,
.table-wrap {
  border: 1px solid #dce3ea;
  border-radius: 8px;
  background: #ffffff;
}

.summary > div {
  padding: 16px;
}

.summary span {
  display: block;
  margin-bottom: 8px;
  color: #66717e;
  font-size: 13px;
}

.summary strong {
  font-size: 24px;
}

.panel {
  padding: 16px;
  margin-bottom: 16px;
}

.portfolio-form {
  display: grid;
  grid-template-columns: minmax(220px, 360px) auto;
  gap: 12px;
  align-items: end;
}

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

.portfolio-card {
  border: 1px solid #dce3ea;
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.portfolio-card:hover {
  border-color: #9bb7df;
  box-shadow: 0 8px 24px rgba(24, 32, 42, 0.08);
}

.portfolio-open {
  display: block;
  padding: 18px;
  text-decoration: none;
}

.portfolio-card strong {
  display: block;
  font-size: 22px;
  margin-bottom: 4px;
}

.portfolio-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.portfolio-title b {
  align-self: flex-start;
  border: 1px solid #cfd7df;
  border-radius: 999px;
  padding: 4px 9px;
  color: #234a84;
  font-size: 13px;
}

.portfolio-card span {
  color: #66717e;
  font-size: 13px;
}

.portfolio-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0 0;
}

.portfolio-card dt {
  color: #66717e;
  font-size: 12px;
}

.portfolio-card dd {
  margin: 5px 0 0;
  font-weight: 700;
}

.rename-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #e8edf2;
  background: #fbfcfd;
}

.rename-form input,
.rename-form button {
  height: 36px;
}

.portfolio-delete-form {
  padding: 0 12px 12px;
  background: #fbfcfd;
}

.danger-button {
  width: 100%;
  height: 36px;
  border: 1px solid #e5b4b4;
  background: #fff7f7;
  color: #a92828;
}

.danger-button:hover {
  background: #ffecec;
}

.back-link {
  display: inline-block;
  margin-bottom: 8px;
  color: #526071;
  font-size: 14px;
  text-decoration: none;
}

.back-link:hover {
  color: #234a84;
}

.entry-form {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.4fr auto;
  gap: 12px;
  align-items: end;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: #5d6875;
  font-size: 13px;
}

input {
  width: 100%;
  height: 42px;
  border: 1px solid #ccd5df;
  border-radius: 7px;
  padding: 0 11px;
  outline: none;
}

input:focus {
  border-color: #2f6fed;
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.12);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.check-row span {
  margin: 0;
}

button {
  height: 42px;
  border: 0;
  border-radius: 7px;
  padding: 0 16px;
  background: #234a84;
  color: #ffffff;
  cursor: pointer;
}

button:hover {
  background: #193b6d;
}

button.ghost {
  height: 34px;
  border: 1px solid #d7dee6;
  background: #ffffff;
  color: #526071;
}

.sort-button {
  display: inline-flex;
  height: 28px;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 6px;
  padding: 0 8px;
  background: transparent;
  color: inherit;
  font-weight: 600;
}

.sort-button:hover {
  background: transparent;
  color: #234a84;
}

.sort-icon {
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
}

.sort-desc {
  border-top: 7px solid #234a84;
}

.sort-asc {
  border-bottom: 7px solid #234a84;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 12px;
  border-bottom: 1px solid #e8edf2;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: #67717f;
  font-size: 13px;
  font-weight: 600;
}

td small {
  display: block;
  margin-top: 3px;
  color: #778291;
}

.empty {
  padding: 28px;
  text-align: center;
  color: #717b88;
}

.gain {
  color: #0c7a43;
}

.loss {
  color: #bd2e2e;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 32, 42, 0.38);
  z-index: 20;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(420px, 100%);
  border: 1px solid #dce3ea;
  border-radius: 8px;
  background: #ffffff;
  padding: 20px;
  box-shadow: 0 18px 50px rgba(24, 32, 42, 0.22);
}

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

.modal p {
  margin-bottom: 16px;
}

.form-error {
  min-height: 22px;
  margin-top: 8px;
  color: #bd2e2e;
  font-size: 13px;
}

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

@media (max-width: 840px) {
  .summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .portfolio-form,
  .portfolio-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
