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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --text: #e8eaf6;
  --text-muted: #8890b0;
  --accent: #f97316;
  --accent-hover: #ea6800;
  --danger: #ef4444;
  --green: #22c55e;
  --radius: 12px;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── AUTH / INVITE SCREEN ── */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at center, #1a1d27 0%, #0f1117 70%);
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 380px;
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.auth-icon { font-size: 3rem; }
.auth-card h1, .auth-card h2 { font-size: 1.4rem; text-align: center; }
.auth-sub { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.25rem; text-align: center; line-height: 1.5; }
.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.auth-form input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  padding: 0.65rem 1rem;
  transition: border-color 0.2s;
  width: 100%;
}
.auth-form input:focus { border-color: var(--accent); }
.btn-auth {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  margin-top: 0.25rem;
  padding: 0.65rem;
  transition: background 0.2s;
  width: 100%;
}
.btn-auth:hover { background: var(--accent-hover); }
.auth-switch { color: var(--text-muted); font-size: 0.82rem; text-align: center; }
.auth-switch a { color: var(--accent); text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.error { color: var(--danger); font-size: 0.82rem; text-align: center; min-height: 1em; }

/* ── APP LAYOUT ── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── SIDEBAR ── */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0 0 1rem;
  overflow-y: auto;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.9rem 1rem 0.8rem;
  border-bottom: 1px solid var(--border);
}
.logo { font-size: 1.4rem; }
.logo-text { font-weight: 700; font-size: 1rem; }

.user-info {
  padding: 0.5rem 1rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

.sidebar-section { padding: 0.5rem 0; }
.sidebar-label {
  padding: 0.3rem 1rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  cursor: pointer;
  font-size: 0.88rem;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  color: var(--text);
  text-align: left;
  width: 100%;
  transition: background 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-item:hover { background: var(--surface2); }
.nav-item.active { background: var(--surface2); border-left-color: var(--accent); font-weight: 600; }

.btn-add {
  display: block;
  margin: 0.4rem 0.75rem;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.82rem;
  padding: 0.45rem 0.5rem;
  text-align: center;
  transition: all 0.2s;
  width: calc(100% - 1.5rem);
}
.btn-add:hover { border-color: var(--accent); color: var(--accent); }

.btn-logout {
  margin: auto 0.75rem 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.78rem;
  padding: 0.5rem 0.25rem;
  text-align: left;
  transition: color 0.2s;
  width: calc(100% - 1.5rem);
}
.btn-logout:hover { color: var(--danger); }

/* ── MAIN ── */
.main { flex: 1; overflow-y: auto; padding: 1.75rem 2rem; }

.view { display: flex; flex-direction: column; gap: 1.25rem; }
.view-title { font-size: 1.35rem; font-weight: 700; }
.view-header { display: flex; align-items: center; justify-content: space-between; }

.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; gap: 0.75rem;
  color: var(--text-muted); text-align: center;
}
.empty-icon { font-size: 3rem; }
.empty-state h2 { color: var(--text); }

/* ── PET HEADER ── */
.pet-header { display: flex; align-items: center; gap: 1rem; }
.pet-avatar { font-size: 2.5rem; line-height: 1; }
.pet-header-info { flex: 1; min-width: 0; }
.pet-header-info h1 { font-size: 1.5rem; }
.pet-subtitle { font-size: 0.85rem; color: var(--text-muted); }
.pet-header-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.35rem 0.55rem;
  transition: all 0.2s;
}
.btn-icon:hover { border-color: var(--text); color: var(--text); }
.btn-icon-danger:hover { border-color: var(--danger); color: var(--danger); }

/* ── TAB BAR ── */
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.tab-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.82rem;
  padding: 0.35rem 0.9rem;
  transition: all 0.2s;
  white-space: nowrap;
}
.tab-btn:hover { border-color: var(--text-muted); color: var(--text); }
.tab-btn.active { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }

/* ── TAB CONTENT ── */
.tab-content { display: flex; flex-direction: column; gap: 1.25rem; }

/* ── CHART CARD ── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  height: 260px;
  position: relative;
}
.chart-card canvas { width: 100% !important; height: 100% !important; }

/* ── ENTRIES CARD ── */
.entries-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.entries-header {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 1rem;
}
.entries-header h2 { font-size: 0.95rem; font-weight: 600; }

/* ── TABLE ── */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 0.5rem 0.5rem;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }
.empty-row { color: var(--text-muted); text-align: center; padding: 1.5rem; font-style: italic; }
td a { color: var(--accent); text-decoration: none; }
td a:hover { text-decoration: underline; }

.row-actions { white-space: nowrap; }
.status-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  white-space: nowrap;
}
.status-open {
  background: #1e3a5f;
  color: #60a5fa;
}
.status-done {
  background: #14532d;
  color: #4ade80;
}
.done-record-btn, .copy-record-btn {
  background: none; border: none; cursor: pointer;
  font-size: 1rem; padding: 0.1rem 0.3rem; border-radius: 4px;
  opacity: 0; transition: opacity 0.15s;
}
.done-record-btn.is-done { opacity: 1 !important; }
tr:hover .done-record-btn,
tr:hover .copy-record-btn { opacity: 1; }
.edit-record-btn, .del-record-btn {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 0.85rem; padding: 0.15rem 0.3rem;
  border-radius: 4px; opacity: 0; transition: opacity 0.15s, color 0.15s;
}
tr:hover .edit-record-btn,
tr:hover .del-record-btn { opacity: 1; }
.edit-record-btn:hover { color: var(--accent); }
.del-record-btn:hover { color: var(--danger); }

/* ── SHARED BUTTONS ── */
.btn-primary {
  background: var(--accent); border: none; border-radius: 8px;
  color: white; cursor: pointer; font-size: 0.82rem; font-weight: 600;
  padding: 0.45rem 1rem; transition: background 0.2s;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: transparent; border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-muted); cursor: pointer;
  font-size: 0.82rem; padding: 0.45rem 1rem; transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--text-muted); color: var(--text); }

.btn-sm {
  background: transparent; border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-muted); cursor: pointer;
  font-size: 0.75rem; padding: 0.25rem 0.6rem; transition: all 0.2s;
}
.btn-sm:hover { border-color: var(--text); color: var(--text); }
.btn-sm-danger:hover { border-color: var(--danger); color: var(--danger); }

/* ── VET CARDS ── */
.vet-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.65rem;
}
.vet-card:last-child { margin-bottom: 0; }
.vet-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.vet-card-header strong { font-size: 0.95rem; }
.vet-actions { display: flex; gap: 0.35rem; }
.vet-detail { font-size: 0.82rem; color: var(--text-muted); margin-top: 0.25rem; }
.vet-detail a { color: var(--accent); text-decoration: none; }
.vet-detail a:hover { text-decoration: underline; }
.vet-role {
  font-size: 0.72rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  color: var(--text-muted);
}

/* ── PROFILE TABLE ── */
.profile-table td { font-size: 0.88rem; }
.profile-label { color: var(--text-muted); white-space: nowrap; padding-right: 1.5rem; width: 40%; }

/* ── MEMBER ROW ── */
.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.member-row:last-child { border-bottom: none; }
.badge {
  font-size: 0.7rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  color: var(--text-muted);
  margin-left: 0.4rem;
}

/* ── INVITE LINK BOX ── */
.invite-link-box {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
}
.invite-link-box input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 0.45rem 0.75rem;
  outline: none;
}

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 420px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.modal-wide { width: 680px; }
.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.modal-grid .full-width { grid-column: 1 / -1; }

.modal h2 { font-size: 1.05rem; font-weight: 700; }
.modal-desc { font-size: 0.82rem; color: var(--text-muted); line-height: 1.5; }

.modal label {
  display: flex; flex-direction: column; gap: 0.35rem;
  font-size: 0.82rem; color: var(--text-muted);
}
.modal input[type="text"],
.modal input[type="number"],
.modal input[type="date"],
.modal input[type="email"],
.modal input[type="password"],
.modal input[type="url"],
.modal select,
.modal textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  padding: 0.5rem 0.75rem;
  transition: border-color 0.2s;
  width: 100%;
}
.modal input:focus,
.modal select:focus,
.modal textarea:focus { border-color: var(--accent); }
.modal textarea { resize: vertical; }
.modal select { cursor: pointer; }
.modal input[type="color"] {
  height: 38px; width: 60px;
  border: 1px solid var(--border);
  border-radius: 6px; cursor: pointer;
  background: none; padding: 2px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.25rem; }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── MOBILE TOPBAR (hidden on desktop) ── */
.mobile-topbar { display: none; }
.sidebar-close { display: none; }
.sidebar-backdrop { display: none; }

/* ── RESPONSIVE ── */
@media (max-width: 680px) {
  body { overflow: auto; }
  .app { flex-direction: column; height: auto; min-height: 100vh; overflow: visible; }

  /* Mobile topbar */
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
  }
  .mobile-topbar .logo-text { font-weight: 700; font-size: 1rem; flex: 1; }
  .sidebar-toggle {
    background: none; border: none; color: var(--text);
    font-size: 1.3rem; cursor: pointer; padding: 0.2rem 0.4rem;
    border-radius: 6px;
  }
  .sidebar-toggle:hover { background: var(--surface2); }

  /* Sidebar as drawer */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 260px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    padding-top: 0;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-header { justify-content: space-between; }
  .sidebar-close {
    display: block;
    background: none; border: none;
    color: var(--text-muted); font-size: 1.1rem;
    cursor: pointer; padding: 0.2rem 0.4rem;
  }

  /* Backdrop */
  .sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
  }
  .sidebar-backdrop.hidden { display: none; }

  /* Main */
  .main { padding: 1rem; overflow: visible; }

  /* Pet header stacked */
  .pet-header { flex-wrap: wrap; gap: 0.75rem; }
  .pet-header-actions { width: 100%; justify-content: flex-start; }

  /* Tab bar: horizontal scroll */
  .tab-bar { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0.25rem; }
  .tab-bar::-webkit-scrollbar { height: 3px; }
  .tab-btn { flex-shrink: 0; }

  /* Tables: horizontal scroll */
  .entries-card { padding: 1rem 0.75rem; overflow-x: auto; }
  table { min-width: 420px; }

  /* Chart smaller */
  .chart-card { height: 200px; }

  /* Modal full screen */
  .modal-overlay { align-items: flex-end; }
  .modal, .modal-wide {
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .modal-grid { grid-template-columns: 1fr; }
  .modal-grid .full-width { grid-column: 1; }

  /* Auth card */
  .auth-card { width: 100%; max-width: 100%; border-radius: 0; border: none; height: 100vh; justify-content: center; }
}
