/* Second Brain — Telegram Mini App v2 */

:root {
  --bg: var(--tg-theme-bg-color, #0d0d11);
  --text: var(--tg-theme-text-color, #e4e4e7);
  --hint: var(--tg-theme-hint-color, #71717a);
  --link: var(--tg-theme-link-color, #818cf8);
  --btn: var(--tg-theme-button-color, #6366f1);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #18181b);

  --card-bg: rgba(28, 28, 36, 0.8);
  --card-border: rgba(99, 102, 241, 0.1);
  --glass: rgba(255, 255, 255, 0.04);
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --radius: 16px;
  --radius-sm: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, 'SF Pro Display', 'Helvetica Neue', sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100vh; overflow-x: hidden;
}

/* ===== Screens ===== */
.screen { display: none; min-height: 100vh; }
.screen.active { display: block; animation: screenIn 0.3s ease; }
@keyframes screenIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Hero ===== */
.hero {
  text-align: center; padding: 24px 16px 16px;
  background: radial-gradient(ellipse at center top, rgba(99,102,241,0.12) 0%, transparent 70%);
}
.hero-icon { font-size: 48px; margin-bottom: 4px; }
.hero h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }
.hero-sub { font-size: 13px; color: var(--hint); margin-top: 4px; }

/* ===== Status Row ===== */
.status-row {
  display: flex; gap: 8px; padding: 0 16px; margin-bottom: 16px;
  overflow-x: auto; scrollbar-width: none;
}
.status-row::-webkit-scrollbar { display: none; }
.status-pill {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 12px; background: var(--card-bg);
  border: 1px solid var(--card-border); border-radius: 20px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  flex-shrink: 0;
}
.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot.green { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.red { background: var(--red); box-shadow: 0 0 6px var(--red); }
.dot.yellow { background: var(--yellow); }

/* ===== Mini Stats ===== */
.mini-stats {
  display: flex; gap: 8px; padding: 0 16px; margin-bottom: 20px;
}
.mini-stat {
  flex: 1; background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); padding: 12px; text-align: center;
}
.mini-stat-value {
  font-size: 20px; font-weight: 800;
  background: linear-gradient(135deg, var(--btn), #a78bfa);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.mini-stat-label { font-size: 10px; color: var(--hint); text-transform: uppercase; margin-top: 2px; }

/* ===== Section Grid ===== */
.section-title {
  font-size: 13px; font-weight: 700; color: var(--hint);
  letter-spacing: 1px; padding: 0 16px; margin-bottom: 10px;
}
.sections-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; padding: 0 16px 24px;
}
.section-card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 16px 8px;
  text-align: center; cursor: pointer; position: relative;
  transition: all 0.2s ease;
}
.section-card:active { transform: scale(0.93); }
.section-emoji { font-size: 30px; margin-bottom: 6px; }
.section-label { font-size: 12px; font-weight: 600; }
.section-badge {
  position: absolute; top: 8px; right: 8px;
  background: var(--red); color: #fff; font-size: 10px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  display: none; align-items: center; justify-content: center; padding: 0 5px;
}

/* ===== Screen Header ===== */
.screen-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; position: sticky; top: 0;
  background: rgba(13,13,17,0.92); backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px); z-index: 50;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.screen-header h2 { font-size: 18px; font-weight: 700; }
.back-btn {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  color: var(--text); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.screen-body { padding: 12px 16px 24px; }

/* ===== Cards ===== */
.card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
}
.card h3 {
  font-size: 12px; color: var(--hint); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 10px;
}

/* ===== Action Card ===== */
.action-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 10px;
  cursor: pointer; transition: all 0.2s;
}
.action-card:active { transform: scale(0.98); }
.action-card.loading { opacity: 0.6; pointer-events: none; }
.action-icon { font-size: 28px; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: var(--glass); border-radius: 12px; flex-shrink: 0;
}
.action-info { flex: 1; }
.action-title { font-size: 15px; font-weight: 600; }
.action-desc { font-size: 12px; color: var(--hint); margin-top: 2px; }
.action-arrow { font-size: 16px; color: var(--hint); }

/* ===== Date Picker ===== */
.date-picker {
  display: flex; align-items: center; gap: 8px; margin-bottom: 14px;
}
.date-picker input {
  flex: 1; padding: 10px; text-align: center;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 14px; outline: none;
}
.date-nav {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  color: var(--text); font-size: 14px; cursor: pointer;
}

/* ===== Search ===== */
.search-box { margin-bottom: 14px; }
.search-box input {
  width: 100%; padding: 12px 14px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 15px;
  outline: none; transition: border-color 0.2s;
}
.search-box input:focus { border-color: var(--btn); }
.search-box input::placeholder { color: var(--hint); }
.search-filters { display: flex; gap: 6px; margin-top: 8px; }
.search-filters select {
  flex: 1; padding: 8px 10px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 12px; outline: none;
}

/* ===== Results ===== */
.result-card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); padding: 12px; margin-bottom: 8px;
}
.result-card:active { transform: scale(0.98); }
.result-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.result-meta { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--hint); }
.result-score {
  font-size: 11px; font-weight: 700; color: var(--btn);
  background: rgba(99,102,241,0.12); padding: 2px 7px; border-radius: 6px;
}
.result-text { font-size: 13px; line-height: 1.45; opacity: 0.9; }
.result-source {
  display: inline-block; font-size: 10px; color: var(--hint);
  background: var(--glass); padding: 2px 7px; border-radius: 5px; margin-top: 6px;
}

/* ===== Daily Entry ===== */
.daily-entry {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); padding: 12px; margin-bottom: 8px;
}
.daily-time {
  font-size: 12px; font-weight: 700; color: var(--btn);
  display: inline-block; margin-bottom: 4px;
}
.daily-type {
  display: inline-block; font-size: 10px; color: var(--hint);
  background: var(--glass); padding: 1px 6px; border-radius: 4px; margin-left: 6px;
}
.daily-text { font-size: 13px; line-height: 1.45; }

/* ===== Tasks ===== */
.task-add { display: flex; gap: 8px; margin-bottom: 12px; }
.task-add input {
  flex: 1; padding: 11px 14px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 14px; outline: none;
}
.task-add button {
  padding: 11px 18px; background: var(--btn); color: var(--btn-text);
  border: none; border-radius: var(--radius-sm); font-size: 16px;
  font-weight: 700; cursor: pointer;
}
.task-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; margin-bottom: 6px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
}
.task-check {
  width: 22px; height: 22px; border-radius: 7px; flex-shrink: 0; margin-top: 1px;
  border: 2px solid var(--card-border); background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: transparent; font-size: 12px; transition: all 0.2s;
}
.task-check.done { background: var(--green); border-color: var(--green); color: #fff; }
.task-text { font-size: 13px; line-height: 1.4; flex: 1; }
.task-text.done { text-decoration: line-through; opacity: 0.4; }

/* ===== Agents ===== */
.agents-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.agent-card {
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius); padding: 14px 8px; text-align: center;
  cursor: pointer; transition: all 0.2s;
}
.agent-card:active { transform: scale(0.93); }
.agent-emoji { font-size: 30px; margin-bottom: 4px; }
.agent-name { font-size: 12px; font-weight: 600; }
.agent-count { font-size: 11px; color: var(--hint); }

/* ===== Health ===== */
.health-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; margin-bottom: 6px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
}
.health-left { display: flex; align-items: center; gap: 8px; }
.health-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.health-dot.ok { background: var(--green); }
.health-dot.fail { background: var(--red); }
.health-label { font-size: 14px; font-weight: 500; }
.health-value { font-size: 13px; color: var(--hint); text-align: right; max-width: 55%; }

/* ===== Reminder ===== */
.reminder-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 6px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
}
.reminder-time { font-size: 14px; font-weight: 700; color: var(--btn); min-width: 44px; }
.reminder-text { font-size: 13px; flex: 1; }
.reminder-date { font-size: 11px; color: var(--hint); }

/* ===== Source Row ===== */
.source-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.source-row:last-child { border-bottom: none; }
.source-info { display: flex; align-items: center; gap: 8px; }
.source-icon {
  font-size: 18px; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: var(--glass); border-radius: 8px;
}
.source-name { font-size: 13px; font-weight: 600; }
.source-count { font-size: 13px; color: var(--hint); font-weight: 500; }

/* ===== Empty & Loading ===== */
.empty-state { text-align: center; padding: 30px 16px; color: var(--hint); }
.empty-state .emoji { font-size: 40px; margin-bottom: 8px; }
.empty-state p { font-size: 13px; }
.loading { text-align: center; padding: 24px; color: var(--hint); }
.spinner {
  display: inline-block; width: 20px; height: 20px;
  border: 2px solid var(--glass); border-top-color: var(--btn);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: rgba(30,30,40,0.95); border: 1px solid var(--card-border);
  color: var(--text); padding: 10px 20px; border-radius: 12px;
  font-size: 13px; font-weight: 500; z-index: 200;
  backdrop-filter: blur(20px); transition: transform 0.3s ease;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ===== Progress ===== */
.progress-bar {
  height: 4px; background: var(--glass); border-radius: 2px;
  overflow: hidden; margin-top: 8px;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--btn), #a78bfa);
  border-radius: 2px; animation: progress 2s ease-in-out infinite;
  width: 30%;
}
@keyframes progress {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}
