:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-soft: #f0f3f7;
  --text: #1f2329;
  --muted: #646a73;
  --line: #dee3eb;
  --primary: #1456f0;
  --primary-weak: #e8efff;
  --danger: #d92d20;
  --danger-weak: #fff0ed;
  --success: #12805c;
  --warning: #9a6700;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px 16px;
  border-right: 1px solid var(--line);
  background: #fbfcfe;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
}

.brand-subtitle,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-weight: 600;
}

.nav-item.active {
  background: var(--primary-weak);
  color: var(--primary);
}

.user-panel {
  margin-top: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.user-name {
  font-weight: 700;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

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

h2 {
  font-size: 18px;
  letter-spacing: 0;
}

.topbar p,
.auth-panel p,
.empty-state p,
.detail-empty p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.55;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.primary-button,
.ghost-button,
.danger-button {
  min-height: 38px;
  padding: 0 15px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 700;
}

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

.ghost-button {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
}

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

.auth-panel {
  max-width: 540px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.auth-panel button {
  margin-top: 18px;
}

.content-grid {
  display: grid;
  gap: 14px;
}

.filters {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) repeat(4, minmax(130px, 180px));
  gap: 10px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input,
select {
  height: 38px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  padding: 10px 11px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20, 86, 240, 0.12);
}

.library-layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
  gap: 14px;
  min-height: calc(100vh - 150px);
}

.clip-list {
  display: grid;
  align-content: start;
  gap: 10px;
  max-height: calc(100vh - 154px);
  overflow: auto;
}

.clip-item {
  display: grid;
  gap: 9px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  text-align: left;
}

.clip-item.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20, 86, 240, 0.12);
}

.clip-title {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clip-excerpt {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  line-height: 1.5;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.clip-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.pill.synced {
  background: #e8f5ef;
  color: var(--success);
}

.pill.failed {
  background: var(--danger-weak);
  color: var(--danger);
}

.pill.disabled {
  background: #fff8e6;
  color: var(--warning);
}

.detail-panel,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.empty-state {
  display: none;
  padding: 26px;
}

.detail-panel {
  min-width: 0;
  padding: 18px;
}

.detail-empty {
  display: grid;
  min-height: 320px;
  place-content: center;
  text-align: center;
}

.detail-form {
  display: grid;
  gap: 14px;
}

.detail-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.title-input {
  height: auto;
  min-height: 44px;
  padding: 6px 0;
  border-color: transparent;
  border-radius: 0;
  font-size: 22px;
  font-weight: 800;
}

.open-link {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 160px;
  gap: 10px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.meta-grid div {
  display: grid;
  gap: 5px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.meta-grid span {
  color: var(--muted);
  font-size: 12px;
}

.meta-grid strong {
  overflow-wrap: anywhere;
  font-size: 13px;
}

.detail-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-top: 4px;
}

.error-text {
  color: var(--danger);
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 11px 14px;
  border-radius: 8px;
  background: #1f2329;
  color: #fff;
  box-shadow: 0 10px 30px rgba(31, 35, 41, 0.22);
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
  }

  .nav-list {
    display: flex;
  }

  .user-panel {
    display: none;
  }

  .filters,
  .library-layout {
    grid-template-columns: 1fr;
  }

  .clip-list {
    max-height: none;
  }
}

@media (max-width: 620px) {
  .workspace {
    padding: 16px;
  }

  .topbar,
  .detail-header,
  .form-row,
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions button {
    flex: 1;
  }
}
