* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #999999);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f1f1f1);
  --radius: 12px;
  --gap: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* Layout */
#app {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 0 80px;
}

.screen { display: none; }
.screen.active { display: block; }

/* Header */
.header {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--secondary-bg);
  z-index: 10;
}

.header h1 {
  font-size: 17px;
  font-weight: 600;
  flex: 1;
}

.back-btn {
  background: none;
  border: none;
  color: var(--link);
  font-size: 15px;
  cursor: pointer;
  padding: 4px 0;
}

/* Cards */
.card-list { padding: 12px 16px; display: flex; flex-direction: column; gap: var(--gap); }

.card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.card:active { opacity: 0.7; }

.card-title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.card-meta { color: var(--hint); font-size: 13px; }

/* Status badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.badge-open { background: #e8f4fd; color: #2481cc; }
.badge-in_progress { background: #fff3cd; color: #856404; }
.badge-done { background: #d4edda; color: #155724; }
.badge-resolved { background: #d4edda; color: #155724; }

/* Buttons */
.btn {
  display: block;
  width: 100%;
  padding: 13px;
  border-radius: var(--radius);
  border: none;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: opacity 0.15s;
}

.btn:active { opacity: 0.8; }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-primary { background: var(--button); color: var(--button-text); }
.btn-secondary { background: var(--secondary-bg); color: var(--text); }
.btn-danger { background: #dc3545; color: #fff; }

.btn-row { display: flex; gap: 8px; padding: 0 16px; }
.btn-row .btn { flex: 1; }

/* Forms */
.form { padding: 16px; display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--hint); font-weight: 500; }

input, textarea, select {
  background: var(--secondary-bg);
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  color: var(--text);
  width: 100%;
  font-family: inherit;
  outline: none;
}

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

/* Detail view */
.detail-body { padding: 16px; }

.detail-section {
  margin-bottom: 20px;
}

.detail-section h3 {
  font-size: 13px;
  color: var(--hint);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.description-text {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 15px;
}

/* Comments */
.comment {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
}

.comment-author { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.comment-text { font-size: 14px; }
.comment-time { font-size: 12px; color: var(--hint); margin-top: 4px; }

/* Tickets */
.ticket-card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 8px;
}

.ticket-worker { font-weight: 600; font-size: 14px; }
.ticket-notes { font-size: 14px; color: var(--hint); margin-top: 4px; }

/* FAB */
.fab {
  position: fixed;
  bottom: 24px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
  border: none;
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60vh;
  color: var(--hint);
  font-size: 15px;
}

.empty {
  text-align: center;
  color: var(--hint);
  padding: 40px 20px;
  font-size: 15px;
}

/* Photo upload button (create ticket form) */
.photo-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--secondary-bg);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  color: var(--link);
}

/* Internal comment */
.comment-internal {
  border-left: 3px solid #856404;
  background: #fffbea;
}

.comment-internal-badge {
  font-size: 10px;
  font-weight: 600;
  background: #fff3cd;
  color: #856404;
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: middle;
}

/* Comment photos */
.comment-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.comment-photo {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
}

.comment-photo-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 6px;
  background: var(--bg);
}

/* Comment input */
.comment-input-area {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--secondary-bg);
}

.comment-internal-toggle {
  padding: 6px 16px 0;
  font-size: 13px;
  color: var(--hint);
}

.comment-internal-toggle label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.comment-input-row {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
}

.comment-input-row input {
  flex: 1;
  border-radius: 20px;
}

.comment-photo-btn {
  background: var(--secondary-bg);
  color: var(--text);
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.comment-input-row button {
  background: var(--button);
  color: var(--button-text);
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
