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

:root {
  --bg:        #F2F2F7;
  --card:      #FFFFFF;
  --primary:   #007AFF;
  --danger:    #FF3B30;
  --archive:   #FF9500;
  --restore:   #34C759;
  --text:      #1C1C1E;
  --secondary: #8E8E93;
  --border:    #E5E5EA;
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, sans-serif;
  --radius:    12px;
  --sat:       env(safe-area-inset-top, 0px);
  --sab:       env(safe-area-inset-bottom, 0px);
  --sal:       env(safe-area-inset-left, 0px);
  --sar:       env(safe-area-inset-right, 0px);
}

html { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ── Header ────────────────────────────────────────────────────────────────── */

header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(242, 242, 247, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--border);
  padding: calc(12px + var(--sat)) 16px 12px calc(16px + var(--sal));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
}

h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.4px;
  color: var(--text);
}

.header-btn {
  background: none;
  border: 1px solid var(--primary);
  color: var(--primary);
  font-size: 14px;
  font-family: var(--font);
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

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

/* ── Category Tabs ─────────────────────────────────────────────────────────── */

#category-tabs {
  position: sticky;
  top: calc(44px + var(--sat));
  z-index: 99;
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
}

#category-tabs::-webkit-scrollbar { display: none; }

.cat-chip {
  flex-shrink: 0;
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 14px;
  font-family: var(--font);
  color: var(--secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}

.cat-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.cat-chip:active:not(.active) {
  background: rgba(0,0,0,0.06);
}

/* ── Link list ─────────────────────────────────────────────────────────────── */

main {
  padding: 14px 16px calc(88px + var(--sab)) calc(16px + var(--sal));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Link card ─────────────────────────────────────────────────────────────── */

.link-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 12px 14px 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: transform 0.1s;
}

.link-card:active { transform: scale(0.985); }

.link-body {
  flex: 1;
  min-width: 0;
}

.link-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  margin-bottom: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.link-domain {
  font-size: 12px;
  color: var(--secondary);
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.link-cat {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(0, 122, 255, 0.12);
  color: var(--primary);
}

.link-date {
  font-size: 11px;
  color: var(--secondary);
}

.link-actions {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* ── Action buttons ────────────────────────────────────────────────────────── */

.act-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  font-size: 15px;
  transition: transform 0.1s, opacity 0.15s;
  flex-shrink: 0;
}

.act-btn:active { transform: scale(0.88); opacity: 0.7; }

.act-open    { background: rgba(0, 122, 255, 0.12); color: var(--primary); }
.act-archive { background: rgba(255, 149, 0, 0.12); color: var(--archive); }
.act-restore { background: rgba(52, 199, 89, 0.12); color: var(--restore); }
.act-delete  { background: rgba(255, 59, 48, 0.12);  color: var(--danger);  }

/* ── Empty state ───────────────────────────────────────────────────────────── */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 64px 24px;
  color: var(--secondary);
  text-align: center;
}

.empty svg { opacity: 0.35; }
.empty p { font-size: 16px; }

/* ── FAB ───────────────────────────────────────────────────────────────────── */

#fab {
  position: fixed;
  bottom: calc(24px + var(--sab));
  right: calc(20px + var(--sar));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 122, 255, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: transform 0.15s;
}

#fab:active { transform: scale(0.9); }

/* ── Modal overlay ─────────────────────────────────────────────────────────── */

#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 300;
  display: flex;
  align-items: flex-end;
  animation: fade-in 0.2s ease;
}

#modal-overlay[hidden] { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

#modal {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(24px + var(--sab));
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
  animation: slide-up 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0 20px;
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--secondary);
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active { background: rgba(0,0,0,0.08); }

/* ── Form ──────────────────────────────────────────────────────────────────── */

.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
}

input[type="text"],
input[type="url"],
select {
  width: 100%;
  padding: 13px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 16px;
  font-family: var(--font);
  color: var(--text);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}

input:focus, select:focus { border-color: var(--primary); }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238E8E93' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-row input { flex: 1; }

.inline-btn {
  padding: 13px 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.inline-btn:active { opacity: 0.72; }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn-primary, .btn-secondary {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius);
  border: none;
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--bg); color: var(--secondary); border: 1px solid var(--border); }
.btn-primary:active, .btn-secondary:active { opacity: 0.7; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */

#toast {
  position: fixed;
  bottom: calc(96px + var(--sab));
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: rgba(28, 28, 30, 0.88);
  color: #fff;
  padding: 10px 20px;
  border-radius: 22px;
  font-size: 14px;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 500;
  white-space: nowrap;
  max-width: calc(100vw - 40px);
  overflow: hidden;
  text-overflow: ellipsis;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Loading skeleton ──────────────────────────────────────────────────────── */

.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, #F0F0F5 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 6px;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
