:root {
  --cyan: #29BDE0;
  --cyan-light: #E8F7FC;
  --cyan-mid: #7DD4ED;
  --cyan-dark: #0E7A9C;
  --cyan-darker: #085568;
  --dark: #2D2D2D;
  --dark-soft: #555;
  --gray-bg: #F8FAFB;
  --white: #fff;
  --green: #3B6D11;
  --green-bg: #EAF3DE;
  --amber: #854F0B;
  --amber-bg: #FAEEDA;
  --red: #A32D2D;
  --red-bg: #FCEBEB;
  --blue-bg: #E6F1FB;
  --blue: #0C447C;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --bottom-nav-h: 60px;
  --nav-h: 52px;
}

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

body {
  font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
  color: var(--dark); background: var(--gray-bg); line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
body.drawer-open { overflow: hidden; }
a { color: var(--cyan-dark); text-decoration: none; }

/* === NAV === */
.nav {
  background: var(--white); border-bottom: 1px solid rgba(0,0,0,0.06);
  position: sticky; top: 0; z-index: 50;
}
.nav-inner {
  max-width: 1140px; margin: 0 auto; padding: 0 16px;
  height: var(--nav-h); display: flex; align-items: center; justify-content: space-between;
}
.nav-logo { font-size: 20px; font-weight: 800; color: var(--dark); }
.nav-logo span { color: var(--cyan); }
.nav-hamburger {
  display: none; background: none; border: none; font-size: 20px;
  color: var(--dark); cursor: pointer; padding: 4px 8px;
}
.nav-links-desktop { display: flex; gap: 24px; }
.nav-links-desktop a { font-size: 13px; font-weight: 500; color: var(--dark-soft); transition: color .15s; }
.nav-links-desktop a:hover, .nav-links-desktop a.active { color: var(--cyan); }
.nav-user-desktop { display: flex; align-items: center; gap: 12px; }
.nav-user-name { font-size: 13px; font-weight: 500; color: var(--dark-soft); }
.nav-logout { font-size: 14px; color: var(--dark-soft); opacity: 0.5; }
.nav-logout:hover { opacity: 1; }
.nav-cta { display: flex; gap: 8px; }

/* === BUTTONS === */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--radius);
  font-weight: 600; font-size: 14px; border: none; cursor: pointer;
  font-family: inherit; transition: all .15s; text-align: center;
  justify-content: center;
}
.btn-sm { padding: 8px 14px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 15px; }
.btn-primary { background: var(--cyan); color: var(--white); }
.btn-primary:hover { background: var(--cyan-dark); }
.btn-outline { background: transparent; color: var(--cyan-dark); border: 1.5px solid var(--cyan-mid); }
.btn-outline:hover { background: var(--cyan-light); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn-danger:hover { background: var(--red-bg); }
.btn-success { background: var(--green); color: var(--white); }
.btn-block { width: 100%; }

/* === MAIN CONTENT === */
.main-content { max-width: 1140px; margin: 0 auto; padding: 20px 16px; }

/* === PANEL LAYOUT (DESKTOP: sidebar + main) === */
.panel-main { padding: 20px 16px; max-width: 900px; margin: 0 auto; }

/* === DRAWER (mobile slide-out menu) === */
.drawer-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 998; opacity: 0; transition: opacity .25s;
}
.drawer-overlay.open { display: block; opacity: 1; }

.drawer {
  position: fixed; top: 0; left: -280px; width: 280px; height: 100%;
  background: var(--white); z-index: 999; transition: left .25s ease;
  display: flex; flex-direction: column; box-shadow: 4px 0 20px rgba(0,0,0,0.1);
}
.drawer.open { left: 0; }
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid rgba(0,0,0,0.06);
}
.drawer-close {
  background: none; border: none; font-size: 20px; color: var(--dark-soft);
  cursor: pointer; padding: 4px;
}
.drawer .sidebar-section { padding: 8px 12px; }
.drawer .sidebar-title {
  font-size: 10px; font-weight: 700; color: var(--dark-soft);
  text-transform: uppercase; letter-spacing: 0.5px; padding: 12px 12px 4px;
}
.drawer .sidebar-link {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: var(--radius); font-size: 14px;
  color: var(--dark-soft); transition: all .15s;
}
.drawer .sidebar-link:hover { background: var(--gray-bg); }
.drawer .sidebar-link.active { background: var(--cyan-light); color: var(--cyan-dark); font-weight: 600; }
.drawer .sidebar-link i { width: 20px; text-align: center; font-size: 16px; }
.drawer-footer {
  margin-top: auto; padding: 16px 20px; border-top: 1px solid rgba(0,0,0,0.06);
  display: flex; align-items: center; justify-content: space-between;
}
.drawer-user { display: flex; align-items: center; gap: 10px; color: var(--dark); text-decoration: none; }
.drawer-user i { font-size: 28px; color: var(--cyan); }

/* === BOTTOM NAV (app-like) === */
.bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--white); border-top: 1px solid rgba(0,0,0,0.06);
  z-index: 50; padding: 4px 0 env(safe-area-inset-bottom, 8px);
}
.bottom-nav { display: flex; }
.bnav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 8px 4px; font-size: 10px; color: var(--dark-soft);
  text-decoration: none; transition: color .15s; -webkit-tap-highlight-color: transparent;
}
.bnav-item i { font-size: 20px; }
.bnav-item.active { color: var(--cyan); }
.bnav-item:active { transform: scale(0.95); }

/* === CARDS === */
.card {
  background: var(--white); border-radius: var(--radius-lg);
  border: 1px solid rgba(0,0,0,0.04); padding: 16px;
  margin-bottom: 12px;
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-title { font-size: 16px; font-weight: 700; }

/* === METRICS === */
.metrics-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 10px; margin-bottom: 20px;
}
.metric {
  background: var(--white); border-radius: var(--radius-lg);
  padding: 14px 16px; border: 1px solid rgba(0,0,0,0.04);
}
.metric-label { font-size: 11px; color: var(--dark-soft); margin-bottom: 2px; }
.metric-value { font-size: 22px; font-weight: 800; }
.metric-sub { font-size: 11px; color: var(--dark-soft); margin-top: 1px; }

/* === BADGES === */
.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-ok { background: var(--green-bg); color: var(--green); }
.badge-warn { background: var(--amber-bg); color: var(--amber); }
.badge-danger { background: var(--red-bg); color: var(--red); }
.badge-info { background: var(--blue-bg); color: var(--blue); }
.badge-neutral { background: var(--gray-bg); color: var(--dark-soft); }
.badge-cyan { background: var(--cyan-light); color: var(--cyan-darker); }

/* === TABS === */
.tabs {
  display: flex; gap: 0; border-bottom: 1px solid rgba(0,0,0,0.06);
  margin-bottom: 20px; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tab {
  padding: 10px 16px; font-size: 13px; font-weight: 500;
  color: var(--dark-soft); cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent; transition: all .15s;
}
.tab:hover { color: var(--dark); }
.tab.active { color: var(--cyan-dark); border-bottom-color: var(--cyan); }

/* === FORMS === */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--dark-soft); margin-bottom: 4px; }
.form-control {
  width: 100%; padding: 12px 14px; border: 1px solid rgba(0,0,0,0.12);
  border-radius: var(--radius); font-size: 16px; font-family: inherit;
  transition: border-color .15s; -webkit-appearance: none;
}
.form-control:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(41,189,224,0.1); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-help { font-size: 12px; color: var(--dark-soft); margin-top: 4px; }
.form-errors { list-style: none; }
.form-errors li { font-size: 13px; color: var(--red); margin-bottom: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* === AUTH PAGES === */
.auth-container { max-width: 400px; margin: 40px auto; padding: 0 16px; }
.auth-card {
  background: var(--white); border-radius: var(--radius-xl);
  padding: 32px 24px; border: 1px solid rgba(0,0,0,0.04); box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 24px; font-weight: 800; margin-bottom: 4px; text-align: center; }
.auth-card .subtitle { font-size: 14px; color: var(--dark-soft); text-align: center; margin-bottom: 24px; }
.auth-card .auth-footer { text-align: center; margin-top: 20px; font-size: 13px; color: var(--dark-soft); }

/* === TABLES === */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; font-weight: 600; color: var(--dark-soft); border-bottom: 1px solid rgba(0,0,0,0.06); font-size: 12px; white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid rgba(0,0,0,0.03); }
tr:hover td { background: var(--gray-bg); }

/* === ALERTS === */
.messages-container { max-width: 1140px; margin: 0 auto; padding: 12px 16px 0; }
.alert {
  padding: 12px 16px; border-radius: var(--radius); margin-bottom: 8px;
  font-size: 14px; display: flex; align-items: center; gap: 10px; position: relative;
}
.alert-success { background: var(--green-bg); color: var(--green); }
.alert-error { background: var(--red-bg); color: var(--red); }
.alert-warning { background: var(--amber-bg); color: var(--amber); }
.alert-info { background: var(--blue-bg); color: var(--blue); }
.alert-close {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; font-size: 18px; cursor: pointer; color: inherit; opacity: 0.5;
}

/* === PET PROFILE === */
.pet-hero { display: flex; gap: 14px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.pet-avatar {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--cyan-light); display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; border: 2.5px solid var(--cyan-mid);
}
.pet-avatar i { font-size: 24px; color: var(--cyan); }
.pet-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.pet-name { font-size: 20px; font-weight: 800; }
.pet-details { font-size: 13px; color: var(--dark-soft); line-height: 1.5; }
.plan-badge {
  display: inline-block; padding: 3px 12px; border-radius: 20px;
  font-size: 11px; font-weight: 600; background: var(--cyan-light); color: var(--cyan-darker); margin-top: 4px;
}

/* === EMPTY STATE === */
.empty-state { text-align: center; padding: 40px 20px; color: var(--dark-soft); }
.empty-state i { font-size: 40px; color: var(--cyan-mid); margin-bottom: 12px; }
.empty-state h3 { font-size: 17px; font-weight: 700; color: var(--dark); margin-bottom: 6px; }
.empty-state p { font-size: 14px; margin-bottom: 16px; }

/* === LIST ITEMS === */
.list-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid rgba(0,0,0,0.04);
}
.list-item:last-child { border-bottom: none; }
.list-item-title { font-size: 14px; font-weight: 600; }
.list-item-sub { font-size: 12px; color: var(--dark-soft); margin-top: 1px; }

/* === HTMX === */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--cyan-light); border-top-color: var(--cyan); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================
   RESPONSIVE — MOBILE FIRST
   ================================================================ */

/* Panels get bottom padding for bottom nav */
.panel-main { padding-bottom: calc(var(--bottom-nav-h) + 20px); }

/* Mobile: show hamburger + bottom nav, hide desktop nav */
@media (max-width: 768px) {
  .nav-hamburger { display: block; }
  .nav-links-desktop { display: none; }
  .nav-user-desktop { display: none; }
  .nav-inner { padding: 0 12px; }

  .main-content { padding: 16px 12px; }
  .panel-main { padding: 16px 12px calc(var(--bottom-nav-h) + 16px); }

  .form-row { grid-template-columns: 1fr; }
  .form-control { font-size: 16px; padding: 14px; }

  .card { padding: 14px; border-radius: var(--radius); }
  .metrics-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric { padding: 12px; }
  .metric-value { font-size: 20px; }

  .pet-hero { gap: 12px; }
  .pet-avatar { width: 56px; height: 56px; }
  .pet-name { font-size: 18px; }

  table { font-size: 12px; }
  th, td { padding: 8px 10px; }

  .auth-container { margin: 20px auto; }
  .auth-card { padding: 24px 20px; }

  h1 { font-size: 22px !important; }

  .tabs { margin-left: -12px; margin-right: -12px; padding: 0 12px; }
}

/* Desktop: hide hamburger + bottom nav, show sidebar as persistent */
@media (min-width: 769px) {
  .nav-hamburger { display: none; }
  .bottom-nav { display: none !important; }
  .drawer { display: none; }
  .drawer-overlay { display: none !important; }
  .panel-main { padding-bottom: 20px; }

  /* Desktop panel layout with sidebar */
  .panel-main {
    max-width: 1140px; margin: 0 auto;
    display: grid; grid-template-columns: 220px 1fr; gap: 24px;
    padding: 24px;
  }
}

/* === MODAL BOTTOM SHEET === */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s;
}
.modal-overlay.open {
  display: block;
  opacity: 1;
}
.modal-sheet {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-radius: 16px 16px 0 0;
  max-height: 80vh;
  z-index: 1001;
  transform: translateY(100%);
  transition: transform 0.3s ease-out;
  display: flex;
  flex-direction: column;
}
.modal-sheet.open {
  transform: translateY(0);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #F2F3F5;
  flex-shrink: 0;
}
.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: #F2F3F5;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #888;
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid #F2F3F5;
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.modal-footer .btn-primary {
  flex: 1;
}
.modal-footer .btn-cancel {
  padding: 10px 20px;
  background: transparent;
  color: #888;
  border: 1.5px solid #ddd;
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.modal-footer .btn-cancel:hover {
  border-color: #aaa;
  color: var(--dark);
}

/* Modal form fields */
.modal-body .sf-field { margin-bottom: 14px; }
.modal-body .sf-field label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--dark-soft); margin-bottom: 4px;
}
.modal-body .sf-field input[type="text"],
.modal-body .sf-field input[type="number"],
.modal-body .sf-field input[type="email"],
.modal-body .sf-field input[type="tel"],
.modal-body .sf-field input[type="date"],
.modal-body .sf-field input[type="datetime-local"],
.modal-body .sf-field input[type="file"],
.modal-body .sf-field select,
.modal-body .sf-field textarea {
  width: 100%; padding: 11px 12px; border: 1.5px solid #ddd;
  border-radius: 8px; font-size: 15px; font-family: inherit;
  background: #fff; color: var(--dark); box-sizing: border-box;
  transition: border-color .2s; -webkit-appearance: none; appearance: none;
}
.modal-body .sf-field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23999' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px;
}
.modal-body .sf-field textarea { min-height: 70px; resize: vertical; }
.modal-body .sf-field input:focus,
.modal-body .sf-field select:focus,
.modal-body .sf-field textarea:focus { outline: none; border-color: var(--cyan); }
.modal-body .sf-field input[type="checkbox"] { width: auto; margin-right: 8px; }
.modal-body .sf-field .helptext { font-size: 11px; color: #aaa; margin-top: 4px; }
.modal-body .sf-field .errorlist { list-style: none; padding: 0; margin: 4px 0 0; font-size: 12px; color: var(--red); }

/* Small phones */
@media (max-width: 380px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .bnav-item { font-size: 9px; }
  .bnav-item i { font-size: 18px; }
}

/* === DESKTOP PANEL LAYOUT FIX === */
@media (min-width: 769px) {
  .panel-wrapper {
    max-width: 1140px; margin: 0 auto; padding: 24px;
    display: grid; grid-template-columns: 240px 1fr; gap: 24px;
  }
  .panel-main {
    display: block; max-width: none; margin: 0; padding: 0;
    grid-template-columns: none;
  }
  .drawer {
    display: flex !important; position: static !important;
    width: auto !important; left: auto !important;
    height: auto !important; box-shadow: none !important;
    background: var(--white); border-radius: var(--radius-lg);
    border: 1px solid rgba(0,0,0,0.04);
  }
  .drawer-header { display: none; }
  .drawer-close { display: none; }
  .drawer-footer { display: none; }
}
.modal-sheet form {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

@media (min-width: 769px) {
  .drawer-mobile { display: none !important; }
  .drawer-mobile + .drawer-overlay { display: none !important; }
}
