/* ============================================================================
   RESPONSIVE BREAKPOINTS & UTILITIES
   ============================================================================ */

@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  .bottom-nav {
    height: 55px;
  }

  .app-content {
    padding-bottom: 55px;
  }
}

@media (min-width: 641px) {
  body {
    font-size: 15px;
  }
}

/* ============================================================================
   FORM ELEMENTS
   ============================================================================ */

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="time"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--tg-theme-hint-color);
  border-radius: 6px;
  background-color: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.2s, background-color 0.2s;
  box-sizing: border-box;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--tg-theme-button-color);
  background-color: var(--tg-theme-bg-color);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

button,
.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  font-family: inherit;
}

button:active,
.btn:active {
  transform: scale(0.98);
}

button:hover,
.btn:hover {
  opacity: 0.9;
}

button:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
}

.btn-secondary {
  background-color: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
  border: 1px solid var(--tg-theme-hint-color);
}

.btn-danger {
  background-color: #dc2626;
  color: white;
}

/* ============================================================================
   CARDS & CONTAINERS
   ============================================================================ */

.card {
  padding: 12px;
  background-color: var(--tg-theme-secondary-bg-color);
  border-radius: 8px;
  margin-bottom: 12px;
  border-right: 3px solid var(--tg-theme-button-color);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.card-title {
  font-weight: bold;
  margin: 0 0 4px 0;
  font-size: 15px;
}

.card-subtitle {
  font-size: 12px;
  color: var(--tg-theme-hint-color);
  margin: 0;
}

/* ============================================================================
   MODALS & OVERLAYS
   ============================================================================ */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--tg-theme-bg-color);
  border-radius: 12px;
  padding: 20px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 18px;
  font-weight: bold;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================================
   TABLES
   ============================================================================ */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}

th, td {
  padding: 10px;
  text-align: right;
  border-bottom: 1px solid var(--tg-theme-secondary-bg-color);
}

th {
  background-color: var(--tg-theme-secondary-bg-color);
  font-weight: bold;
  font-size: 13px;
}

tr:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

/* ============================================================================
   BADGES & TAGS
   ============================================================================ */

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-success {
  background-color: #d1fae5;
  color: #065f46;
}

.badge-warning {
  background-color: #fef3c7;
  color: #92400e;
}

.badge-danger {
  background-color: #fee2e2;
  color: #991b1b;
}

.badge-info {
  background-color: #dbeafe;
  color: #0c2d6b;
}

/* ============================================================================
   ANIMATIONS
   ============================================================================ */

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.fade-in {
  animation: fadeIn 0.3s ease-in-out;
}

.spinner {
  animation: spin 1s linear infinite;
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid var(--tg-theme-hint-color);
  border-top-color: var(--tg-theme-button-color);
  border-radius: 50%;
}

/* ============================================================================
   TYPOGRAPHY
   ============================================================================ */

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  line-height: 1.4;
  font-weight: 600;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 16px;
}

p {
  margin: 0 0 8px 0;
  line-height: 1.5;
}

a {
  color: var(--tg-theme-link-color);
  text-decoration: none;
  transition: opacity 0.2s;
}

a:hover {
  opacity: 0.7;
}

/* ============================================================================
   LAYOUT UTILITIES
   ============================================================================ */

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.justify-between {
  justify-content: space-between;
}

.justify-center {
  justify-content: center;
}

.align-center {
  align-items: center;
}

.w-full {
  width: 100%;
}

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }

.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }

.p-2 { padding: 8px; }
.p-3 { padding: 12px; }
.p-4 { padding: 16px; }

.px-2 { padding-left: 8px; padding-right: 8px; }
.px-3 { padding-left: 12px; padding-right: 12px; }

.py-2 { padding-top: 8px; padding-bottom: 8px; }
.py-3 { padding-top: 12px; padding-bottom: 12px; }

.rounded { border-radius: 4px; }
.rounded-lg { border-radius: 8px; }
.rounded-xl { border-radius: 12px; }

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

.text-xs { font-size: 12px; }
.text-sm { font-size: 13px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }

.font-bold { font-weight: bold; }
.font-semibold { font-weight: 600; }

.text-muted {
  color: var(--tg-theme-hint-color);
}

/* ============================================================================
   DARK MODE SUPPORT
   ============================================================================ */

@media (prefers-color-scheme: dark) {
  body.dark {
    --tg-theme-bg-color: #1f2937;
    --tg-theme-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #2d3748;
    --tg-theme-hint-color: #9ca3af;
  }
}

/* ============================================================================
   CALENDAR SPECIFIC
   ============================================================================ */

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.calendar-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background-color: var(--tg-theme-secondary-bg-color);
  cursor: pointer;
  transition: transform 0.2s, background-color 0.2s;
  font-weight: 600;
}

.calendar-cell:hover {
  transform: scale(1.05);
}

.calendar-cell.today {
  background-color: var(--tg-theme-button-color);
  color: white;
}

.calendar-cell.other-month {
  opacity: 0.3;
}

/* ============================================================================
   POSTS & CONTENT
   ============================================================================ */

.post-item {
  padding: 12px;
  background-color: var(--tg-theme-secondary-bg-color);
  border-radius: 8px;
  margin-bottom: 8px;
  border-right: 3px solid var(--tg-theme-button-color);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.post-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.post-title {
  font-weight: bold;
  margin: 0 0 4px 0;
  word-break: break-word;
}

.post-meta {
  font-size: 12px;
  color: var(--tg-theme-hint-color);
  margin: 0;
}

.post-status {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background-color: var(--tg-theme-button-color);
  color: white;
}

/* ============================================================================
   RESPONSIVE GRID
   ============================================================================ */

.grid {
  display: grid;
  gap: 12px;
}

.grid-cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 640px) {
  .grid-cols-2,
  .grid-cols-3 {
    grid-template-columns: 1fr;
  }
}

/* ============================================================================
   STAT CARDS
   ============================================================================ */

.stat-card {
  padding: 16px;
  background-color: var(--tg-theme-secondary-bg-color);
  border-radius: 8px;
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: bold;
  color: var(--tg-theme-button-color);
  margin: 0 0 4px 0;
}

.stat-label {
  font-size: 12px;
  color: var(--tg-theme-hint-color);
  margin: 0;
}

/* ============================================================================
   TABS
   ============================================================================ */

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--tg-theme-secondary-bg-color);
  margin: 0 0 16px 0;
  overflow-x: auto;
}

.tab {
  flex: 1;
  min-width: 80px;
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  transition: border-color 0.2s, color 0.2s;
  white-space: nowrap;
}

.tab:hover {
  color: var(--tg-theme-button-color);
}

.tab.active {
  border-bottom-color: var(--tg-theme-button-color);
  color: var(--tg-theme-button-color);
}

/* ============================================================================
   EMPTY STATES
   ============================================================================ */

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--tg-theme-hint-color);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state-title {
  font-size: 16px;
  font-weight: bold;
  margin: 0 0 8px 0;
  color: var(--tg-theme-text-color);
}

.empty-state-message {
  font-size: 13px;
  margin: 0;
}

/* ============================================================================
   LOADING & TRANSITIONS
   ============================================================================ */

.loading {
  display: flex;
  justify-content: center;
  align-items: center;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--tg-theme-hint-color);
  border-top-color: var(--tg-theme-button-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* ============================================================================
   ALERTS
   ============================================================================ */

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 12px;
  border-left: 4px solid;
}

.alert-success {
  background-color: #d1fae5;
  border-color: #10b981;
  color: #065f46;
}

.alert-warning {
  background-color: #fef3c7;
  border-color: #f59e0b;
  color: #92400e;
}

.alert-error {
  background-color: #fee2e2;
  border-color: #dc2626;
  color: #991b1b;
}

.alert-info {
  background-color: #dbeafe;
  border-color: #3b82f6;
  color: #0c2d6b;
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
  .bottom-nav,
  .modal,
  button:not(.print) {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }
}
