/* ===== Portal PWA — Mobile First ===== */
:root {
  --blue: #0071e3;
  --blue-light: #00c7ff;
  --blue-bg: #ebf5ff;
  --dark: #1d1d1f;
  --gray-bg: #f5f5f7;
  --gray-text: #86868b;
  --gray-border: rgba(0,0,0,0.06);
  --white: #ffffff;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --radius: 12px;
  --radius-lg: 20px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', Roboto, sans-serif;
  color: var(--dark);
  background: var(--gray-bg);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { text-decoration: none; color: inherit; }
button, input, select, textarea { font-family: inherit; font-size: inherit; border: none; outline: none; }

/* ===== App Shell ===== */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ===== Top Bar ===== */
.topbar {
  background: var(--white);
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--gray-border);
  flex-shrink: 0;
  z-index: 10;
}
.topbar-title {
  font-size: 17px;
  font-weight: 600;
}
.topbar-subtitle {
  font-size: 12px;
  color: var(--gray-text);
}
.topbar-action {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--gray-bg);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.2s;
}
.topbar-action:hover { background: #e8e8ed; }
.topbar-action svg { width: 18px; height: 18px; color: var(--dark); }

/* ===== Content Area ===== */
.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: calc(80px + var(--safe-bottom));
}

/* ===== Bottom Tabs ===== */
.bottom-tabs {
  background: var(--white);
  border-top: 1px solid var(--gray-border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
  z-index: 10;
}
.tab {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 8px 0;
  color: var(--gray-text);
  font-size: 10px; font-weight: 500;
  cursor: pointer; transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.tab svg { width: 24px; height: 24px; margin-bottom: 2px; }
.tab.active { color: var(--blue); }
.tab.active svg { stroke-width: 2.5; }

/* ===== Views ===== */
.view { display: none; }
.view.active { display: block; }

/* ===== Welcome Card ===== */
.welcome-card {
  background: linear-gradient(135deg, var(--blue), var(--blue-light));
  color: white;
  padding: 24px;
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
}
.welcome-card h2 {
  font-size: 22px; font-weight: 700;
  margin-bottom: 4px;
}
.welcome-card p {
  font-size: 14px; opacity: 0.85;
}
.welcome-card .date {
  font-size: 12px; opacity: 0.7;
  margin-top: 8px;
}

/* ===== Quick Actions ===== */
.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
.quick-action {
  background: var(--white);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  align-items: center; gap: 8px;
  cursor: pointer; transition: transform 0.2s;
  text-align: center;
}
.quick-action:active { transform: scale(0.97); }
.quick-action-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: white;
}
.quick-action-icon.blue { background: linear-gradient(135deg, var(--blue), var(--blue-light)); }
.quick-action-icon.green { background: linear-gradient(135deg, var(--green), #30d158); }
.quick-action-icon.orange { background: linear-gradient(135deg, var(--orange), #ffb340); }
.quick-action-icon.purple { background: linear-gradient(135deg, #af52de, #da8fff); }
.quick-action span { font-size: 13px; font-weight: 500; }

/* ===== Section Headers ===== */
.section-title {
  font-size: 18px; font-weight: 700;
  margin-bottom: 12px;
}
.section-title-row {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 12px;
}
.section-title-row h3 { font-size: 18px; font-weight: 700; }
.see-all { font-size: 13px; color: var(--blue); font-weight: 500; }

/* ===== Entry Cards ===== */
.entry-card {
  background: var(--white);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  transition: transform 0.2s;
}
.entry-card:active { transform: scale(0.99); }
.entry-header {
  display: flex; justify-content: space-between;
  align-items: flex-start; margin-bottom: 8px;
}
.entry-date { font-size: 12px; color: var(--gray-text); }
.entry-mood {
  font-size: 20px; line-height: 1;
}
.entry-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.entry-text {
  font-size: 14px; color: #444;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.entry-tags {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 8px;
}
.entry-tag {
  background: var(--blue-bg);
  color: var(--blue);
  padding: 3px 10px;
  border-radius: 50px;
  font-size: 11px; font-weight: 500;
}
.entry-private {
  background: #fff3e0; color: var(--orange);
}

/* ===== Appointment Cards ===== */
.cita-card {
  background: var(--white);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  display: flex; gap: 14px; align-items: center;
}
.cita-date-box {
  width: 52px; height: 52px;
  background: var(--blue-bg);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  flex-shrink: 0;
}
.cita-date-box .day { font-size: 20px; font-weight: 700; color: var(--blue); line-height: 1; }
.cita-date-box .month { font-size: 11px; color: var(--blue); text-transform: uppercase; font-weight: 600; }
.cita-info { flex: 1; }
.cita-info .time { font-size: 15px; font-weight: 600; }
.cita-info .type { font-size: 13px; color: var(--gray-text); }
.cita-status {
  padding: 4px 10px;
  border-radius: 50px;
  font-size: 11px; font-weight: 600;
}
.cita-status.programada { background: var(--blue-bg); color: var(--blue); }
.cita-status.confirmada { background: #e6ffed; color: #22863a; }
.cita-status.completada { background: #f0f0f0; color: #666; }
.cita-status.cancelada { background: #ffeef0; color: var(--red); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center; padding: 48px 20px;
  color: var(--gray-text);
}
.empty-state svg {
  width: 64px; height: 64px;
  color: #ccc; margin-bottom: 16px;
}
.empty-state h3 { font-size: 17px; color: var(--dark); margin-bottom: 4px; }
.empty-state p { font-size: 14px; }

/* ===== New Entry Page ===== */
.page-overlay {
  position: fixed; inset: 0;
  background: var(--gray-bg);
  z-index: 50;
  display: none;
  flex-direction: column;
}
.page-overlay.active { display: flex; }
.page-header {
  background: var(--white);
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  display: flex; justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--gray-border);
}
.page-header .back {
  font-size: 15px; color: var(--blue);
  font-weight: 500; cursor: pointer;
  display: flex; align-items: center; gap: 4px;
}
.page-header .save {
  background: var(--blue); color: white;
  padding: 8px 20px; border-radius: 50px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.page-header .save:disabled { opacity: 0.5; }
.page-body {
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}

/* ===== Form Elements ===== */
.form-section {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.form-label {
  font-size: 13px; font-weight: 600;
  color: var(--gray-text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  display: block;
}
.form-input {
  width: 100%; padding: 12px;
  background: var(--gray-bg);
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 16px; /* prevents zoom on iOS */
  transition: border-color 0.2s;
}
.form-input:focus { border-color: var(--blue); background: white; }
textarea.form-input { resize: none; min-height: 120px; line-height: 1.6; }

/* ===== Mood Picker ===== */
.mood-picker {
  display: flex; justify-content: space-between;
  padding: 4px 0;
}
.mood-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--gray-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  cursor: pointer; transition: all 0.2s;
  border: 2px solid transparent;
}
.mood-btn:active { transform: scale(0.9); }
.mood-btn.selected {
  border-color: var(--blue);
  background: var(--blue-bg);
  transform: scale(1.15);
}

/* ===== Emotion Chips ===== */
.emotion-chips {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.emotion-chip {
  padding: 8px 14px;
  border-radius: 50px;
  background: var(--gray-bg);
  font-size: 13px;
  cursor: pointer; transition: all 0.2s;
  border: 1px solid transparent;
}
.emotion-chip:active { transform: scale(0.95); }
.emotion-chip.selected {
  background: var(--blue-bg);
  color: var(--blue);
  border-color: var(--blue);
}

/* ===== Toggle ===== */
.toggle-row {
  display: flex; justify-content: space-between;
  align-items: center; padding: 4px 0;
}
.toggle-row span { font-size: 15px; }
.toggle {
  width: 50px; height: 30px;
  background: #e0e0e0;
  border-radius: 15px;
  position: relative;
  cursor: pointer; transition: background 0.3s;
}
.toggle.on { background: var(--blue); }
.toggle::after {
  content: '';
  width: 26px; height: 26px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 2px; left: 2px;
  transition: transform 0.3s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle.on::after { transform: translateX(20px); }

/* ===== Profile ===== */
.profile-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.profile-header {
  background: linear-gradient(135deg, var(--blue), var(--blue-light));
  color: white;
  padding: 32px 20px;
  text-align: center;
}
.profile-avatar {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
  font-size: 28px; font-weight: 700;
}
.profile-header h2 { font-size: 20px; font-weight: 700; }
.profile-header p { font-size: 13px; opacity: 0.8; }
.profile-menu { padding: 8px 0; }
.profile-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  font-size: 15px; cursor: pointer;
  transition: background 0.2s;
}
.profile-item:hover { background: var(--gray-bg); }
.profile-item svg { width: 20px; height: 20px; color: var(--gray-text); }
.profile-item .label { flex: 1; }
.profile-item .chevron { color: #ccc; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: calc(90px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--dark); color: white;
  padding: 12px 24px; border-radius: 50px;
  font-size: 14px; font-weight: 500;
  z-index: 200; opacity: 0;
  transition: all 0.3s;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ===== Offline Banner ===== */
.offline-banner {
  background: var(--orange);
  color: white;
  text-align: center;
  padding: 6px;
  font-size: 12px; font-weight: 600;
  display: none;
}
.offline-banner.show { display: block; }

/* ===== Login ===== */
.login-screen {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px;
  background: var(--white);
}
.login-logo {
  width: 72px; height: 72px;
  border-radius: 18px;
  overflow: hidden;
  margin-bottom: 24px;
}
.login-logo img { width: 100%; height: 100%; }
.login-screen h1 {
  font-size: 24px; font-weight: 700;
  margin-bottom: 4px;
}
.login-screen .sub {
  color: var(--gray-text);
  font-size: 14px; margin-bottom: 32px;
}
.login-form { width: 100%; max-width: 340px; }
.login-error {
  background: #ffeef0; color: var(--red);
  padding: 10px 14px; border-radius: 10px;
  font-size: 13px; margin-bottom: 12px;
  display: none; text-align: center;
}
.login-btn {
  width: 100%; padding: 14px;
  background: var(--blue); color: white;
  border-radius: var(--radius);
  font-weight: 600; font-size: 16px;
  cursor: pointer; transition: background 0.2s;
  margin-top: 8px;
}
.login-btn:hover { background: #005bb5; }
.login-back {
  text-align: center; margin-top: 20px;
  font-size: 13px;
}
.login-back a { color: var(--blue); }

/* ===== Scrollbar ===== */
.content::-webkit-scrollbar { width: 0; }

/* ===== Desktop: wider layout ===== */
@media (min-width: 768px) {
  .app { max-width: 480px; margin: 0 auto; box-shadow: var(--shadow-lg); }
  .bottom-tabs { border-radius: 0; }
}
