/* Postcard Penpal PWA Design System */

:root {
  --font-ui: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-handwritten: 'Caveat', cursive;

  /* Harmonious warm-neutral palette */
  --bg-app: #fbf8f5;
  --color-text: #2d2a26;
  --color-text-muted: #726b63;
  --color-border: #ead5c3;
  --color-border-hover: #d7c0ad;
  --color-white: #ffffff;
  
  /* Styling accents */
  --ink-color: #1e3a5f; /* Classic dark blue ink for postcards */
  --stamp-red: #b24c43;  /* Vintage postmark stamp red */
  
  --shadow-sm: 0 2px 8px rgba(45, 42, 38, 0.05);
  --shadow-md: 0 8px 24px rgba(45, 42, 38, 0.08);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --border-radius: 12px;
}

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

body {
  font-family: var(--font-ui);
  background-color: var(--bg-app);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

input, button, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

/* App Containers */
#app {
  width: 100%;
  max-width: 600px; /* Mobile first, centered card container */
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-white);
  box-shadow: 0 0 40px rgba(45, 42, 38, 0.04);
  position: relative;
}

header {
  padding: 16px 20px;
  border-bottom: 2px dashed var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--color-white);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  border: 2px dashed var(--color-text-muted);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
}

h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

main {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

/* Auth Screens */
.auth-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 80vh;
  padding: 10px;
}

.auth-card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 30px 24px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.auth-card h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

.auth-card p {
  color: var(--color-text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 18px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--color-text);
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background-color: var(--bg-app);
  color: var(--color-text);
  transition: var(--transition);
}

.form-input:focus {
  outline: none;
  border-color: var(--color-border-hover);
  background-color: var(--color-white);
  box-shadow: 0 0 0 3px rgba(234, 213, 195, 0.3);
}

.btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background-color: var(--color-text);
  color: var(--color-white);
}

.btn-primary:hover {
  background-color: #423d37;
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background-color: var(--bg-app);
}

.btn-link {
  background: none;
  border: none;
  color: var(--color-text-muted);
  text-decoration: underline;
  cursor: pointer;
  font-size: 13px;
}

.btn-link:hover {
  color: var(--color-text);
}

.error-banner {
  background-color: #fdf2f2;
  border: 1px solid #fde2e2;
  color: #c81e1e;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
  display: none;
  text-align: left;
}

/* Profile Picker / Netflix Style */
.profile-picker {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.profile-avatar-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.avatar-circle {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 28px;
  color: #333333;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  border: 3px solid transparent;
}

.profile-avatar-btn:hover .avatar-circle {
  transform: scale(1.08);
  box-shadow: var(--shadow-md);
  border-color: var(--color-border-hover);
}

.profile-avatar-btn span {
  font-weight: 600;
  font-size: 15px;
}

/* PIN Screen Input Dots */
.pin-dots-container {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 20px 0;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  transition: var(--transition);
}

.pin-dot.filled {
  background-color: var(--color-text);
  border-color: var(--color-text);
  transform: scale(1.2);
}

.pin-keyboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 280px;
  margin: 0 auto;
}

.pin-key {
  background: var(--bg-app);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 20px;
  cursor: pointer;
  transition: var(--transition);
  margin: 0 auto;
}

.pin-key:hover {
  background-color: var(--color-white);
  border-color: var(--color-border-hover);
}

.pin-key:active {
  transform: scale(0.95);
}

/* Dashboard tiles / Grid */
.dashboard-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.dashboard-title-row h2 {
  font-size: 20px;
  font-weight: 700;
}

.correspondence-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Postcard Tile Layout */
.postcard-tile {
  background-color: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Apply light background tint using dynamic custom CSS color variables */
.postcard-tile::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--tile-bg, transparent);
  opacity: 0.15;
  pointer-events: none;
  z-index: 1;
}

.postcard-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-border-hover);
}

.postcard-tile-header {
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 2;
  position: relative;
}

.postcard-tile-info {
  flex: 1;
}

.postcard-tile-name {
  font-weight: 600;
  font-size: 16px;
}

.postcard-tile-meta {
  font-size: 12px;
  color: var(--color-text-muted);
}

/* Ruled notebook line look for dashboard snippet */
.postcard-tile-snippet {
  font-family: var(--font-handwritten);
  font-size: 19px;
  color: var(--ink-color);
  background: repeating-linear-gradient(transparent, transparent 23px, #e8dfd5 23px, #e8dfd5 24px);
  line-height: 24px;
  padding: 2px 4px;
  min-height: 48px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  z-index: 2;
  position: relative;
}

/* Postmark stamp style */
.postmark-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 2px dashed var(--stamp-red);
  border-radius: 50%;
  width: 65px;
  height: 65px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transform: rotate(8deg);
  opacity: 0.75;
  color: var(--stamp-red);
  pointer-events: none;
  z-index: 2;
  font-weight: 700;
  text-transform: uppercase;
}

.postmark-date {
  font-size: 9px;
  line-height: 1.1;
}
.postmark-location {
  font-size: 8px;
  letter-spacing: 0.5px;
  line-height: 1.1;
  text-align: center;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stamp-box {
  width: 32px;
  height: 38px;
  border: 1.5px dashed var(--color-text-muted);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 12px;
  margin-left: auto;
}

/* "+ New correspondence" tile */
.new-correspondence-tile {
  border: 2px dashed var(--color-border);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--border-radius);
  transition: var(--transition);
}

.new-correspondence-tile:hover {
  background-color: var(--color-white);
  border-color: var(--color-border-hover);
  color: var(--color-text);
}

/* Thread screen (stack of postcards) */
.thread-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding-bottom: 80px; /* Space for compose footer */
}

/* Individual Postcard Card */
.postcard-card {
  background-color: var(--color-white);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--border-radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.postcard-card-front {
  position: relative;
  background-color: #efeae4;
  aspect-ratio: 16/10;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.postcard-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.postcard-card-back {
  padding: 20px;
  border-top: 1px dashed var(--color-border);
  position: relative;
  background: linear-gradient(to bottom, #fff 0%, #fff 8px, #fdfbfa 8px, #fdfbfa 100%);
}

.postcard-message-body {
  font-family: var(--font-handwritten);
  font-size: 21px;
  color: var(--ink-color);
  line-height: 28px;
  background: repeating-linear-gradient(transparent, transparent 27px, #e8dfd5 27px, #e8dfd5 28px);
  min-height: 112px;
  padding-bottom: 12px;
  word-wrap: break-word;
}

.postcard-meta-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  font-size: 12px;
  color: var(--color-text-muted);
  border-top: 1px dashed #ead5c3;
  padding-top: 8px;
}

/* Floating Compose Button */
.compose-footer {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  padding: 16px 20px;
  background-color: var(--color-white);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 12px;
  box-shadow: 0 -4px 12px rgba(45, 42, 38, 0.04);
  z-index: 5;
}

/* Compose Screen styling */
.compose-postcard {
  display: flex;
  flex-direction: column;
  gap: 20px;
  background-color: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.compose-photo-target {
  width: 100%;
  aspect-ratio: 16/10;
  border: 2px dashed var(--color-border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  background-color: var(--bg-app);
  color: var(--color-text-muted);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.compose-photo-target:hover {
  background-color: var(--color-white);
  border-color: var(--color-border-hover);
  color: var(--color-text);
}

.photo-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.remove-photo-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background-color: rgba(45, 42, 38, 0.8);
  color: white;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 3;
}

.compose-back {
  border-top: 1px dashed var(--color-border);
  padding-top: 16px;
  position: relative;
}

.compose-textarea {
  width: 100%;
  min-height: 140px;
  border: none;
  resize: none;
  outline: none;
  background: repeating-linear-gradient(transparent, transparent 27px, #e8dfd5 27px, #e8dfd5 28px);
  line-height: 28px;
  padding: 0 4px;
  color: var(--color-text);
  font-size: 15px; /* Clean sans-serif during composition */
}

.char-counter {
  text-align: right;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 6px;
}

.recipient-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.recipient-chip {
  background-color: var(--bg-app);
  border: 1px solid var(--color-border);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition);
}

.recipient-chip.selected {
  background-color: var(--color-text);
  color: var(--color-white);
  border-color: var(--color-text);
}

.pending-label {
  font-size: 10px;
  background-color: #ffefdb;
  color: #b25e00;
  padding: 1px 6px;
  border-radius: 4px;
}

/* Parent Panel Layout */
.parent-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.parent-section {
  background-color: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.parent-section h3 {
  margin-bottom: 16px;
  font-size: 16px;
  border-bottom: 1px dashed var(--color-border);
  padding-bottom: 8px;
}

/* Pending Requests rows */
.request-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--bg-app);
}

.request-row:last-child {
  border-bottom: none;
}

.request-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.request-names {
  font-weight: 600;
  font-size: 14px;
}

.request-date {
  font-size: 11px;
  color: var(--color-text-muted);
}

.request-actions {
  display: flex;
  gap: 8px;
}

.btn-sm {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  cursor: pointer;
}

.btn-approve {
  background-color: #10b981;
  color: white;
}

.btn-deny {
  background-color: #ef4444;
  color: white;
}

/* Child Card overview */
.child-cards-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.child-card {
  border: 1px solid var(--color-border);
  background-color: var(--bg-app);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.child-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.child-card-name {
  font-weight: 600;
}

.child-card-username {
  font-size: 12px;
  color: var(--color-text-muted);
}

.child-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

/* Toggle Switches */
.toggle-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.toggle-group:last-child {
  margin-bottom: 0;
}

.toggle-group span {
  font-size: 13px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: #10b981;
}

input:checked + .slider:before {
  transform: translateX(20px);
}

/* Badge count */
.badge-count {
  background-color: var(--stamp-red);
  color: white;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 700;
}

/* Utility layout helpers */
.text-center { text-align: center; }
.hidden { display: none !important; }
.spinner {
  border: 3px solid rgba(45, 42, 38, 0.1);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border-left-color: var(--color-text);
  animation: spin 1s linear infinite;
  margin: 20px auto;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Postcard torn-edge dividers */
.torn-divider {
  height: 6px;
  background-image: radial-gradient(circle, transparent, transparent 50%, var(--bg-app) 50%, var(--bg-app) 100%),
                    radial-gradient(circle, transparent, transparent 50%, var(--bg-app) 50%, var(--bg-app) 100%);
  background-size: 12px 12px;
  background-position: 0 0, 6px 6px;
  background-repeat: repeat-x;
  width: 100%;
  margin: 12px 0;
}
