:root {
  color-scheme: light;
  --bg: #d9dde2; /* silver grey */
  --surface: #f4f6f8;
  --surface-strong: #ffffff;
  --surface-soft: #e9edf1;
  --border: #c5ccd4;
  --text: #1d2a3a;
  --muted: #5f6f82;
  --primary: #233a5a; /* midnight blue */
  --primary-hover: #1d314d;
  --primary-soft: #d8e1ed;
  --accent: #c6d7a4; /* pistachio */
  --accent-strong: #9eb875;
  --danger: #c2464a;
  --ok: #1f6d46;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 400px at 0% -10%, #edf1f5 0%, transparent 60%),
    radial-gradient(1200px 500px at 100% 110%, #cdd5de 0%, transparent 65%),
    var(--bg);
  min-height: 100vh;
}

.app-shell {
  width: min(1180px, calc(100vw - 2rem));
  margin: 1rem auto 2.2rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  background: linear-gradient(145deg, #2b4368 0%, #233a5a 100%);
  border: 1px solid #1a2b44;
  border-radius: 24px;
  padding: 0.9rem 1.1rem;
  box-shadow: 0 8px 20px #18263729;
}

.brand-wrap {
  display: flex;
  gap: 0.95rem;
  align-items: center;
  min-width: 0;
}

.brand-logo {
  width: 58px;
  height: 58px;
  object-fit: cover;
  border-radius: 14px;
  border: 2px solid #f5f7fa;
  box-shadow: 0 4px 10px #0f1b2b66;
}

.topbar h1 {
  margin: 0;
  color: #f7fbff;
  letter-spacing: 0.2px;
  font-size: clamp(1.2rem, 3.3vw, 1.7rem);
}

.topbar p {
  margin: 0.18rem 0 0;
  color: #d7e2ee;
  font-size: 0.92rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.nav-tabs {
  display: flex;
  gap: 0.5rem;
}

.tab {
  border: 1px solid #c2d0df70;
  background: #ffffff17;
  color: #e8eef5;
  border-radius: 999px;
  padding: 0.46rem 0.98rem;
  cursor: pointer;
}

.tab.active {
  background: var(--accent);
  color: #213047;
  border-color: #a7b98b;
  font-weight: 700;
}

.card {
  background: linear-gradient(180deg, var(--surface-strong) 0%, var(--surface) 100%);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.1rem;
  margin-bottom: 1rem;
  box-shadow: 0 5px 14px #233a5a12;
}

.card h2 {
  margin: 0 0 0.95rem;
  color: var(--primary);
  font-size: 1.16rem;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.7rem;
  margin-bottom: 0.8rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.form-grid label:has(textarea),
.form-grid label:has(#url) {
  grid-column: 1 / -1;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fbfdff;
  color: var(--text);
  padding: 0.68rem 0.8rem;
}

textarea {
  resize: vertical;
  min-height: 90px;
}

.btn-row {
  grid-column: 1 / -1;
  display: flex;
  gap: 0.7rem;
  align-items: center;
}

.btn {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.64rem 1rem;
  cursor: pointer;
  color: var(--text);
  background: #fff;
}

.btn.primary {
  border-color: #182c47;
  background: linear-gradient(135deg, #2a456b, var(--primary));
  color: #fff;
  font-weight: 700;
}

.btn.primary:hover {
  background: linear-gradient(135deg, #1f3655, var(--primary-hover));
}

.btn.ghost {
  background: #f0f3f6;
}

.btn.mini {
  font-size: 0.82rem;
  padding: 0.32rem 0.62rem;
}

.btn.danger {
  color: var(--danger);
  border-color: #e7c7cd;
  background: #fbf4f5;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.badge {
  min-width: 2rem;
  text-align: center;
  border-radius: 999px;
  padding: 0.22rem 0.7rem;
  background: #dde6f0;
  color: #304762;
  font-weight: 700;
}

.empty {
  background: #edf1f4;
  border: 1px dashed #b8c2ce;
  border-radius: 12px;
  padding: 1rem;
  color: var(--muted);
}

.category-sections {
  display: grid;
  gap: 1rem;
}

.category-section {
  border: 1px solid #cfd6df;
  border-radius: 16px;
  padding: 0.9rem;
  background: #eff3f7;
}

.category-title {
  margin: 0 0 0.7rem;
  font-size: 1.05rem;
  color: #2f4765;
}

.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem;
}

.link-card {
  border: 1px solid #d0d8e1;
  background: #fff;
  border-radius: 14px;
  padding: 0.82rem;
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 0.75rem;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.link-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 14px #2a42661a;
}

.icon-box {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  border: 1px solid #ccd6e2;
  background: #e6edf5;
  display: grid;
  place-items: center;
  font-size: 1.45rem;
  overflow: hidden;
}

.icon-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.content {
  min-width: 0;
}

.title {
  margin: 0;
  font-size: 1rem;
}

.description {
  margin: 0.3rem 0 0.52rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.target {
  color: var(--ok);
  text-decoration: none;
  word-break: break-all;
  font-size: 0.86rem;
}

.target:hover {
  text-decoration: underline;
}

.stack-list {
  display: grid;
  gap: 0.55rem;
}

.manage-row {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 14px;
  padding: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.manage-main {
  min-width: 0;
}

.manage-sub {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  word-break: break-all;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

#settingsView {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(340px, 1.2fr);
  gap: 1rem;
}

#settingsView > .card:nth-child(3) {
  grid-column: 1 / -1;
}

@media (max-width: 880px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions {
    justify-content: space-between;
  }

  #settingsView {
    grid-template-columns: 1fr;
  }

  #settingsView > .card:nth-child(3) {
    grid-column: auto;
  }
}

@media (max-width: 780px) {
  .app-shell {
    width: calc(100vw - 1rem);
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

  .manage-row {
    flex-direction: column;
    align-items: stretch;
  }
}
