:root {
  --blue: #1b4f72;
  --blue-2: #2874a6;
  --blue-light: #eaf2f8;
  --green: #1e8449;
  --green-light: #e8f6ee;
  --amber: #b9770e;
  --amber-light: #fdf2e0;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1c2833;
  --muted: #7b8794;
  --border: #e2e8ee;
  --shadow: 0 1px 3px rgba(27,79,114,.08), 0 4px 16px rgba(27,79,114,.06);
  --radius: 12px;
  --header-h: 60px;
  --sidebar-w: 240px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 700; color: var(--blue); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.hidden { display: none !important; }

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  background: var(--blue);
  color: #fff;
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { font-size: 1.5rem; line-height: 1; }
.brand-text { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-text h1 {
  color: #fff; font-size: 1.02rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-badge {
  background: #f39c12; color: #fff; font-size: .68rem; font-weight: 700;
  padding: 2px 8px; border-radius: 20px; letter-spacing: .5px;
}
.header-right { margin-left: auto; }
.conn-pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(255,255,255,.12); padding: 6px 12px; border-radius: 20px;
  font-size: .82rem;
}
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.online { background: #2ecc71; box-shadow: 0 0 0 3px rgba(46,204,113,.25); }
.dot.offline { background: #e74c3c; box-shadow: 0 0 0 3px rgba(231,76,60,.25); }

.burger {
  display: none; flex-direction: column; gap: 4px; background: none;
  border: none; cursor: pointer; padding: 6px;
}
.burger span { width: 22px; height: 2px; background: #fff; border-radius: 2px; }

/* Layout */
.layout { display: flex; min-height: calc(100vh - var(--header-h)); }

.sidebar {
  width: var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex; flex-direction: column;
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
}
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 9px;
  color: var(--text); text-decoration: none; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--blue-light); }
.nav-item.active { background: var(--blue); color: #fff; }
.nav-ico { font-size: 1.1rem; }
.sidebar-foot { margin-top: auto; padding: 12px 14px; }
.sidebar-foot p { font-size: .75rem; color: var(--muted); }

.scrim {
  display: none; position: fixed; inset: var(--header-h) 0 0 0;
  background: rgba(0,0,0,.4); z-index: 25;
}

.content { flex: 1; padding: 26px; max-width: 1200px; width: 100%; }

.view-head { margin-bottom: 20px; }
.view-head h2 { font-size: 1.5rem; }
.view-head .muted { margin-top: 2px; }

/* Stat cards */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 22px;
}
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
}
.stat-ico {
  width: 48px; height: 48px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 1.5rem;
}
.stat-ico.blue { background: var(--blue-light); }
.stat-ico.green { background: var(--green-light); }
.stat-ico.amber { background: var(--amber-light); }
.stat-num { font-size: 1.75rem; font-weight: 700; color: var(--text); line-height: 1.1; }
.stat-label { font-size: .85rem; color: var(--muted); }

/* Panels */
.panel {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
  padding: 20px; margin-bottom: 18px;
}
.panel.no-pad { padding: 0; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 16px; flex-wrap: wrap; gap: 6px; }
.panel-head.pad { padding: 18px 20px 0; }
.panel-head h3 { font-size: 1.1rem; }

/* Chart */
.chart { display: flex; flex-direction: column; gap: 14px; padding-top: 4px; }
.chart-row { display: grid; grid-template-columns: 90px 1fr 46px; align-items: center; gap: 12px; }
.chart-label { font-size: .9rem; font-weight: 500; }
.chart-track { background: var(--bg); border-radius: 20px; height: 20px; overflow: hidden; }
.chart-bar { height: 100%; border-radius: 20px; width: 0; transition: width .8s cubic-bezier(.2,.7,.3,1); }
.chart-val { font-size: .9rem; font-weight: 600; text-align: right; color: var(--muted); }

/* Toolbar */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  padding: 10px 14px; border: 1px solid var(--border); border-radius: 9px;
  font-size: .9rem; background: #fff; color: var(--text);
}
.toolbar input { flex: 1; min-width: 220px; }
.toolbar input:focus, .toolbar select:focus { outline: 2px solid var(--blue-2); outline-offset: -1px; }

/* Table */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th {
  text-align: left; padding: 13px 16px; background: #f8fafb;
  color: var(--muted); font-weight: 600; font-size: .78rem;
  text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table tbody tr { cursor: pointer; transition: background .12s; }
.data-table tbody tr:hover { background: var(--blue-light); }
.data-table tbody tr:last-child td { border-bottom: none; }
.mono { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .84rem; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; }
.badge.synced { background: var(--green-light); color: var(--green); }
.badge.synced::before { background: var(--green); }
.badge.pending { background: var(--amber-light); color: var(--amber); }
.badge.pending::before { background: var(--amber); }
.species-tag { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }

.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Detail view */
.back-link {
  display: inline-flex; align-items: center; gap: 6px; color: var(--blue-2);
  text-decoration: none; font-weight: 500; margin-bottom: 14px; cursor: pointer;
  background: none; border: none; font-size: .92rem;
}
.detail-top { display: flex; gap: 22px; flex-wrap: wrap; align-items: flex-start; }
.photo-ph {
  width: 160px; height: 160px; border-radius: 14px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--blue-light), #d6e6f2);
  display: grid; place-items: center; font-size: 3.5rem;
  border: 1px solid var(--border);
}
.detail-id { flex: 1; min-width: 240px; }
.detail-id h2 { font-size: 1.6rem; margin-bottom: 4px; }
.detail-sub { color: var(--muted); margin-bottom: 12px; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-top: 10px; }
.info-item .k { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.info-item .v { font-weight: 600; margin-top: 2px; }

/* Vet timeline */
.timeline { list-style: none; }
.timeline li { position: relative; padding: 0 0 18px 26px; border-left: 2px solid var(--border); }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: -7px; top: 2px;
  width: 12px; height: 12px; border-radius: 50%; background: var(--blue-2);
  border: 2px solid #fff; box-shadow: 0 0 0 2px var(--blue-light);
}
.tl-date { font-size: .78rem; color: var(--muted); font-weight: 600; }
.tl-title { font-weight: 600; }
.tl-desc { font-size: .88rem; color: var(--muted); }

/* Buttons */
.btn {
  border: none; border-radius: 9px; padding: 11px 18px; font-size: .9rem;
  font-weight: 600; cursor: pointer; transition: background .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: #196f3d; }
.btn-primary:disabled { background: #a9c9b6; cursor: not-allowed; }

/* Offline banner */
.offline-banner {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--amber-light); border: 1px solid #f0d9a8;
  border-left: 5px solid var(--amber);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px;
  transition: background .3s, border-color .3s;
}
.offline-banner.online {
  background: var(--green-light); border-color: #bfe6ce; border-left-color: var(--green);
}
.ob-ico { font-size: 1.6rem; }
.ob-text { display: flex; flex-direction: column; }
.offline-banner .btn { margin-left: auto; }

/* Sync list */
.sync-list { padding: 6px 0 10px; }
.sync-item {
  display: flex; align-items: center; gap: 14px; padding: 13px 20px;
  border-bottom: 1px solid var(--border);
}
.sync-item:last-child { border-bottom: none; }
.sync-status-ico {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: .85rem; font-weight: 700;
  background: var(--amber-light); color: var(--amber);
  transition: background .3s, color .3s;
}
.sync-item.done .sync-status-ico { background: var(--green-light); color: var(--green); }
.sync-item.syncing .sync-status-ico { background: var(--blue-light); color: var(--blue-2); }
.spinner {
  width: 16px; height: 16px; border: 2px solid var(--blue-light);
  border-top-color: var(--blue-2); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sync-main { flex: 1; min-width: 0; }
.sync-main .name { font-weight: 600; }
.sync-main .meta { font-size: .82rem; color: var(--muted); }
.sync-state-txt { font-size: .82rem; font-weight: 600; color: var(--amber); white-space: nowrap; }
.sync-item.syncing .sync-state-txt { color: var(--blue-2); }
.sync-item.done .sync-state-txt { color: var(--green); }

@keyframes pop { 0% { transform: scale(.8); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
.pop { animation: pop .35s ease; }

/* Responsive */
@media (max-width: 860px) {
  .brand-text h1 { font-size: .9rem; white-space: normal; }
  .burger { display: flex; }
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; z-index: 30;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.open + .scrim { display: block; }
  .content { padding: 18px 14px; }
  .header-right { display: none; }
}
