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

:root {
  --primary: #1C1C1E;
  --primary-light: #F2F2F7;
  --primary-dark: #000000;
  --bg: #F2F2F7;
  --surface: #ffffff;
  --text: #1C1C1E;
  --text-secondary: #636366;
  --text-tertiary: #AEAEB2;
  --border: #E5E5EA;
  --success: #248A3D;
  --success-bg: #E8F5EC;
  --danger: #D70015;
  --danger-bg: #FFF0F0;
  --warning: #B25000;
  --warning-bg: #FFF4E0;
  --info: #0055D4;
  --info-bg: #EEF4FF;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Loading */
.loading-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Offline bar */
.offline-bar {
  position: fixed; top: env(safe-area-inset-top); left: 0; right: 0;
  background: var(--warning);
  color: white;
  padding: 8px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  z-index: 100;
}
.offline-bar.hidden { display: none; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #2C2C2E 0%, #1C1C1E 50%, #000000 100%);
}
.login-box {
  background: white;
  border-radius: 20px;
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo-img {
  width: 72px;
  height: auto;
  display: block;
  margin: 0 auto 10px;
}
@media (min-width: 600px) {
  .login-logo-img { width: 68px; }
}
.login-logo h1 { font-size: 24px; font-weight: 700; }
.login-logo p { color: var(--text-secondary); font-size: 14px; }
.login-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 16px;
}

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: white;
  color: var(--text);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.form-group textarea { resize: vertical; min-height: 60px; }

.error-msg {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}

.success-msg {
  background: var(--success-bg);
  color: var(--success);
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* Buttons */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary:active { opacity: 0.85; }
.btn-secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
}
.btn-secondary:active { background: var(--bg); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-danger { background: var(--danger); color: white; border: none; padding: 12px 20px; border-radius: 10px; font-size: 15px; font-weight: 500; cursor: pointer; font-family: inherit; }

/* Install banner */
.install-banner {
  background: var(--primary);
  color: white;
  padding: 10px 16px;
}
.install-banner-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 800px;
  margin: 0 auto;
}
.install-banner-icon { width: 32px; height: 32px; border-radius: 8px; }
.install-banner-text { flex: 1; min-width: 0; }
.install-banner-text strong { display: block; font-size: 13px; font-weight: 600; }
.install-banner-text span { font-size: 11px; opacity: 0.85; }
.install-banner-btn {
  background: white;
  color: var(--primary);
  border: none;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}
.install-banner-close {
  background: transparent;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  opacity: 0.8;
  line-height: 1;
}
.ios-hint {
  font-size: 12px;
  opacity: 0.9;
  text-align: center;
  padding-top: 8px;
  max-width: 800px;
  margin: 0 auto;
}

/* Header */
.app-header {
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 50;
}
.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  max-width: 800px;
  margin: 0 auto;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-logo-img {
  height: 36px;
  width: auto;
}
.header-title { font-weight: 600; font-size: 16px; }
.header-subtitle { font-size: 12px; color: var(--text-secondary); }

.icon-btn {
  background: transparent;
  border: none;
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 24px;
}
.icon-btn:active { background: var(--bg); }

/* Content */
#content {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px 16px 100px;
  min-height: 50vh;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.page-header h2 { font-size: 18px; font-weight: 600; }

/* Filter tabs */
.filter-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.filter-tab {
  background: white;
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-secondary);
}
.filter-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Event card */
.events-list { display: flex; flex-direction: column; gap: 8px; }
.event-date-group {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 8px 0 4px 4px;
}
.event-card {
  background: white;
  border-radius: 12px;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  cursor: pointer;
  border-left: 4px solid var(--primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.event-card.type-grojimas    { border-left-color: #3A86C8; }
.event-card.type-vedimas     { border-left-color: #1A9465; }
.event-card.type-tik_vedimas { border-left-color: #7C5CBF; }
.event-card.type-full        { border-left-color: #C07A00; }
.event-card.status-atsauktas  { opacity: 0.45; border-left-color: var(--text-tertiary); }
.event-card.status-planuojamas { border-left-color: #C07A00; }
.event-card:active { background: var(--bg); }
.event-name { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.event-meta { font-size: 12px; color: var(--text-secondary); line-height: 1.5; }
.event-tags { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.tag {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}
.tag-grojimas    { background: #EAF3FB; color: #1A4E78; }
.tag-vedimas     { background: #E4F4EE; color: #0A4530; }
.tag-tik_vedimas { background: #F0EBFA; color: #4A2D8A; }
.tag-full        { background: #FBF0D9; color: #5C3800; }
.tag-planuojamas { background: #FBF0D9; color: #5C3800; }
.tag-atsauktas   { background: var(--bg); color: var(--text-tertiary); }
.event-price {
  font-weight: 600;
  font-size: 14px;
  text-align: right;
  white-space: nowrap;
  margin-left: 12px;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
  font-size: 14px;
}
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.3; }

/* Calendar */
.cal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.cal-header h2 { font-size: 17px; font-weight: 600; }
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
}
.cal-weekdays div {
  text-align: center;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 6px 0;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  background: white;
  border-radius: 12px;
  padding: 8px;
}
.cal-day {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 4px 2px;
  font-size: 12px;
  cursor: pointer;
  position: relative;
  background: transparent;
}
.cal-day:active { background: var(--bg); }
.cal-day.other-month { color: var(--text-tertiary); opacity: 0.4; }
.cal-day.today { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.cal-day-num { font-weight: 500; }
.cal-day-dots { display: flex; gap: 2px; margin-top: 2px; }
.cal-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--primary); }
.cal-dot.grojimas    { background: #3A86C8; }
.cal-dot.vedimas     { background: #1A9465; }
.cal-dot.tik_vedimas { background: #7C5CBF; }
.cal-dot.full        { background: #C07A00; }
.cal-dot.planuojamas { background: #C07A00; }

/* Equipment */
.equipment-list { display: flex; flex-direction: column; gap: 8px; }
.equipment-card {
  background: white;
  border-radius: 12px;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.equipment-card:active { background: var(--bg); }
.equipment-info h3 { font-weight: 600; font-size: 15px; margin-bottom: 2px; }
.equipment-info p { font-size: 12px; color: var(--text-secondary); }
.equipment-qty {
  background: var(--primary-light);
  color: var(--primary);
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 500;
}

/* Profile */
.profile-card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  margin-bottom: 16px;
}
.profile-avatar {
  width: 72px; height: 72px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 600;
  margin: 0 auto 12px;
}
.profile-name { font-size: 18px; font-weight: 600; margin-bottom: 2px; }
.profile-username { font-size: 13px; color: var(--text-secondary); }
.profile-section {
  background: white;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 8px;
}

.info-card {
  background: var(--info-bg);
  border-radius: 12px;
  padding: 14px;
  font-size: 13px;
  color: var(--info);
  margin-top: 16px;
}
.info-card ol { margin: 8px 0 0 18px; line-height: 1.7; }

/* FAB */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 28px;
  font-weight: 300;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  z-index: 40;
}
.fab:active { transform: scale(0.95); }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: white;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 50;
}
.nav-item {
  background: transparent;
  border: none;
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
}
.nav-item.active { color: var(--primary); font-weight: 500; }
.nav-item:active { background: var(--bg); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.2s;
}
@media (min-width: 600px) {
  .modal { align-items: center; justify-content: center; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-content {
  background: var(--bg);
  width: 100%;
  max-width: 500px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  animation: slideUp 0.25s;
}
@media (min-width: 600px) {
  .modal-content { border-radius: 16px; max-height: 90vh; }
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-header h2 { font-size: 18px; font-weight: 600; }
.modal-close {
  background: var(--surface);
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-secondary);
}

.modal-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.modal-row:last-child { border: none; }
.modal-row .label { color: var(--text-secondary); }
.modal-row .value { font-weight: 500; text-align: right; }
.modal-row .value a { color: var(--info); text-decoration: none; }

.modal-section {
  background: white;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 12px;
}
.modal-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}
.modal-actions.three { grid-template-columns: 1fr 1fr 1fr; }

/* Form rows */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.cat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border-radius: 10px;
  padding: 10px 12px;
}
.cat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
}
.cat-input:focus { outline: none; border-color: var(--primary); }

.equipment-checks {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}
.eq-check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: white;
  border-radius: 8px;
  font-size: 14px;
}
.eq-check input[type="checkbox"] { width: 18px; height: 18px; }
.eq-check input[type="number"] { width: 50px; padding: 4px; font-size: 13px; }
.eq-check .eq-meta { margin-left: auto; font-size: 11px; color: var(--text-secondary); }
.eq-check.unavailable { opacity: 0.6; }

.conflict-msg {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-top: 10px;
}
.conflict-ok {
  background: var(--success-bg);
  color: var(--success);
  padding: 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-top: 10px;
}

/* Type toggle */
.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.type-toggle button { font-size: 12px; padding: 9px 6px; }
.type-toggle button {
  background: white;
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.type-toggle button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: white;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  z-index: 300;
  animation: toastIn 0.25s;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 20px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Action buttons in event modal */
.action-btn {
  background: white;
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 10px;
  text-align: center;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  display: block;
  font-family: inherit;
}
.action-btn:active { background: var(--bg); }
.action-btn.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
