/* ── RESET & VARS ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       var(--tg-theme-bg-color,            #ffffff);
  --bg2:      var(--tg-theme-secondary-bg-color,  #f2f2f7);
  --text:     var(--tg-theme-text-color,          #000000);
  --hint:     var(--tg-theme-hint-color,          #8e8e93);
  --link:     var(--tg-theme-link-color,          #007aff);
  --btn:      var(--tg-theme-button-color,        #007aff);
  --btn-text: var(--tg-theme-button-text-color,   #ffffff);
  --sep:      rgba(142,142,147,0.2);
  --radius:   12px;
  --radius-sm: 8px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-height: 100dvh;
  overflow-x: hidden;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: 88px;
}

/* ── TABS ── */
#header {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--sep);
}
#nav-tabs { display: flex; gap: 4px; padding: 8px 12px; }
.tab {
  flex: 1; border: none; background: transparent;
  color: var(--hint); font-size: 12px; font-weight: 500;
  padding: 7px 4px; border-radius: var(--radius-sm); cursor: pointer;
  transition: all .18s; white-space: nowrap;
}
.tab.active { background: var(--btn); color: var(--btn-text); font-weight: 600; }

/* ── VIEWS ── */
.view { display: none; padding: 12px; }
.view.active { display: block; }

/* ── CALENDAR NAV ── */
#cal-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0 14px;
}
#cal-nav button {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; background: var(--bg2);
  color: var(--text); font-size: 24px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
#cal-month-label {
  font-size: 17px; font-weight: 700;
  text-transform: capitalize;
}

/* ── CALENDAR GRID ── */
#cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  width: 100%;
}
.cal-dow {
  text-align: center;
  font-size: 11px; font-weight: 600;
  color: var(--hint);
  padding: 4px 0 6px;
}
.cal-day {
  position: relative;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 36px;
  transition: background .15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.cal-day.empty { cursor: default; pointer-events: none; }
.cal-day:not(.empty):hover,
.cal-day:not(.empty):active { background: var(--bg2); }
.cal-day.today .cal-num { color: var(--btn); font-weight: 800; }
.cal-day.selected {
  background: var(--btn) !important;
  border-radius: var(--radius-sm);
}
.cal-day.selected .cal-num { color: var(--btn-text) !important; font-weight: 700; }
.cal-day.selected .cal-dot { background: rgba(255,255,255,0.9) !important; }

.cal-num { font-size: 13px; line-height: 1; }

.cal-dots {
  display: flex; gap: 2px; margin-top: 3px;
  justify-content: center; flex-wrap: wrap;
  max-width: 24px;
}
.cal-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Spinner calendario */
.cal-spinner {
  text-align: center; padding: 12px; font-size: 18px;
  color: var(--hint);
}

/* ── DAY SECTION ── */
#day-section {
  margin-top: 14px;
  border-top: 1px solid var(--sep);
  padding-top: 12px;
}
#day-header {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 10px;
}
#day-title {
  font-size: 14px; font-weight: 700;
  text-transform: capitalize;
  flex: 1; margin-right: 8px;
}

/* ── MEETING CARD ── */
.meeting-card {
  display: flex;
  background: var(--bg2);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  overflow: hidden;
  transition: opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.meeting-card:active { opacity: .75; }
.card-left {
  width: 4px;
  flex-shrink: 0;
  border-radius: 4px 0 0 4px;
}
.card-body {
  flex: 1;
  padding: 10px 12px;
  min-width: 0;
}
.card-title {
  font-weight: 600; font-size: 14px;
  margin-bottom: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-time { font-size: 12px; color: var(--hint); margin-bottom: 5px; }
.card-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip {
  font-size: 11px; padding: 2px 8px;
  border-radius: 20px; font-weight: 600;
}
.card-node { font-size: 12px; color: var(--hint); }

/* ── EMPTY STATES ── */
.empty-day, .empty-state {
  text-align: center;
  padding: 28px 16px;
  color: var(--hint);
}
.empty-ico { font-size: 36px; margin-bottom: 8px; }
.btn-link {
  margin-top: 10px;
  background: none; border: none;
  color: var(--btn); cursor: pointer;
  font-size: 14px; font-weight: 600;
  padding: 6px 12px;
}

/* ── DATE SEPARATOR (upcoming) ── */
.date-sep {
  font-size: 12px; font-weight: 700;
  color: var(--hint);
  padding: 8px 4px 4px;
  text-transform: capitalize;
}

/* ── UPCOMING / NODES ── */
#upcoming-list, #nodes-list {
  display: flex; flex-direction: column;
}
.loading { text-align: center; padding: 28px; color: var(--hint); }

/* ── NODE CARD ── */
.node-card {
  background: var(--bg2); border-radius: var(--radius);
  padding: 14px; margin-bottom: 8px;
}
.node-header {
  display: flex; justify-content: space-between;
  align-items: baseline; margin-bottom: 6px;
}
.node-title { font-weight: 700; font-size: 15px; }
.node-host  { font-size: 12px; color: var(--hint); }
.node-row   { font-size: 13px; color: var(--hint); margin-top: 3px; }
.node-row.rec { color: #ff3b30; font-weight: 600; }

/* ── FAB ── */
#fab {
  position: fixed; bottom: 24px; right: 18px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--btn); color: var(--btn-text);
  font-size: 28px; border: none; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.28);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

/* ── MODALS ── */
#modal-overlay, #detail-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex; align-items: flex-end;
}
#modal-overlay.hidden, #detail-overlay.hidden { display: none !important; }

#modal, #detail-modal {
  background: var(--bg);
  width: 100%;
  max-height: 92dvh;
  border-radius: var(--radius) var(--radius) 0 0;
  overflow-y: auto;
  padding: 18px 16px 40px;
  overscroll-behavior: contain;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 16px; gap: 8px;
}
.btn-close {
  width: 30px; height: 30px; border-radius: 50%;
  border: none; background: var(--bg2); cursor: pointer;
  color: var(--hint); font-size: 14px; flex-shrink: 0;
}

/* ── FORM ── */
.fgroup { margin-bottom: 14px; }
.fgroup label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--hint); margin-bottom: 6px;
  letter-spacing: .4px; text-transform: uppercase;
}
.fgroup input,
.fgroup select,
.fgroup textarea {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--bg2); color: var(--text);
  font-size: 14px; outline: none;
  transition: border-color .15s;
  -webkit-appearance: none;
}
.fgroup input:focus,
.fgroup select:focus,
.fgroup textarea:focus { border-color: var(--btn); }
.frow { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.factions { display: flex; gap: 8px; margin-top: 20px; }

/* ── BUTTONS ── */
.btn, .btn-sm {
  border: none; cursor: pointer; font-weight: 600;
  border-radius: var(--radius-sm);
  transition: opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn    { flex: 1; padding: 12px 8px; font-size: 14px; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-pri  { background: var(--btn);   color: var(--btn-text); }
.btn-sec  { background: var(--bg2);   color: var(--text); }
.btn-red  { background: #ff3b30;      color: #fff; }
.btn-ora  { background: #ff9500;      color: #fff; }
.btn:active, .btn-sm:active { opacity: .75; }
.hidden { display: none !important; }

/* ── DETAIL ── */
#detail-body { margin-bottom: 16px; }
.drow {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 9px 0;
  border-bottom: 1px solid var(--sep);
  gap: 12px;
}
.dlabel { color: var(--hint); font-size: 13px; flex-shrink: 0; }
.dvalue { font-size: 13px; font-weight: 500; text-align: right; word-break: break-all; }
#detail-actions { display: flex; flex-direction: column; gap: 8px; }
.act-row { display: flex; gap: 8px; }

/* ── DELETE CONFIRM ── */
.delete-confirm {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
  border: 1.5px solid #ff3b30;
}
.delete-confirm-msg {
  font-size: 14px;
  margin-bottom: 12px;
  line-height: 1.5;
}
.delete-confirm-msg small {
  font-size: 12px;
  color: var(--hint);
}

/* ── TOAST ── */
#toast {
  position: fixed; bottom: 88px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.80); color: #fff;
  padding: 10px 20px; border-radius: 20px;
  font-size: 13px; z-index: 400;
  white-space: nowrap; max-width: 90vw;
  text-overflow: ellipsis; overflow: hidden;
  transition: opacity .25s;
}
#toast.hidden { opacity: 0; pointer-events: none; }
