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

:root {
  --primary: #4a90a4;
  --primary-dark: #3a7a94;
  --secondary: #6c757d;
  --danger: #dc3545;
  --success: #28a745;
  --background: #f5f7fa;
  --card-bg: #ffffff;
  --text: #333333;
  --text-light: #666666;
  --border: #e0e0e0;
  --shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #5ba8c0;
    --primary-dark: #4a90a4;
    --secondary: #8a939b;
    --danger: #e85464;
    --success: #3cb55c;
    --background: #1a1a2e;
    --card-bg: #252540;
    --text: #e8e8e8;
    --text-light: #a0a0a0;
    --border: #3a3a5a;
    --shadow: 0 2px 15px rgba(0,0,0,0.4);
  }
}

/* Manual dark mode toggle */
[data-theme="dark"] {
  --primary: #5ba8c0;
  --primary-dark: #4a90a4;
  --secondary: #8a939b;
  --danger: #e85464;
  --success: #3cb55c;
  --background: #1a1a2e;
  --card-bg: #252540;
  --text: #e8e8e8;
  --text-light: #a0a0a0;
  --border: #3a3a5a;
  --shadow: 0 2px 15px rgba(0,0,0,0.4);
}

[data-theme="light"] {
  --primary: #4a90a4;
  --primary-dark: #3a7a94;
  --secondary: #6c757d;
  --danger: #dc3545;
  --success: #28a745;
  --background: #f5f7fa;
  --card-bg: #ffffff;
  --text: #333333;
  --text-light: #666666;
  --border: #e0e0e0;
  --shadow: 0 2px 10px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--background);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background-color 0.3s, color 0.3s;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

.hidden {
  display: none !important;
}

/* Login Screen */
#login-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 80vh;
}

.login-box {
  background: var(--card-bg);
  padding: 40px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 400px;
  width: 100%;
  position: relative;
}

.login-box h1 {
  margin-bottom: 10px;
  font-size: 2rem;
}

.login-box > p {
  color: var(--text-light);
  margin-bottom: 30px;
}

/* Form Elements */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s, background-color 0.2s;
  background: var(--card-bg);
  color: var(--text);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
}

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

/* Buttons */
button {
  cursor: pointer;
  font-size: 1rem;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  transition: all 0.2s;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
}

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

.btn-secondary:hover {
  opacity: 0.9;
}

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

.btn-danger:hover {
  opacity: 0.9;
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-back {
  background: transparent;
  color: var(--primary);
  padding: 8px 0;
  margin-bottom: 20px;
}

.btn-back:hover {
  text-decoration: underline;
}

.btn-icon {
  background: var(--card-bg);
  border: 2px solid var(--border);
  padding: 8px 12px;
  font-size: 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--border);
}

.theme-toggle-login {
  position: absolute;
  top: 15px;
  right: 15px;
}

#login-btn {
  margin-top: 10px;
  width: 100%;
}

/* Error/Info Messages */
.error {
  color: var(--danger);
  margin-top: 15px;
}

.info {
  color: var(--primary);
  margin-top: 10px;
  font-size: 0.9rem;
}

/* Header */
header {
  background: var(--card-bg);
  padding: 20px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 30px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

.header-content h1 {
  font-size: 1.5rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
}

.badge.reader {
  background: #e3f2fd;
  color: #1976d2;
}

.badge.editor {
  background: #e8f5e9;
  color: #388e3c;
}

/* Posts List */
.posts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.post-card {
  background: var(--card-bg);
  padding: 25px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 15px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

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

.post-card h3 {
  margin-bottom: 8px;
  color: var(--primary);
}

.post-card .meta {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 10px;
}

.post-card .preview {
  color: var(--text);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

/* Single Post View */
article {
  background: var(--card-bg);
  padding: 40px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

article h1 {
  margin-bottom: 10px;
  font-size: 2rem;
}

article .meta {
  color: var(--text-light);
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

article .content {
  white-space: pre-wrap;
  line-height: 1.8;
}

#post-actions {
  margin-top: 20px;
  display: flex;
  gap: 10px;
}

/* Post Editor */
#post-editor form {
  background: var(--card-bg);
  padding: 30px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* Admin Panel */
.admin-section {
  background: var(--card-bg);
  padding: 25px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.admin-section h3 {
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.code-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  background: var(--background);
  border-radius: 8px;
  margin-bottom: 10px;
}

.code-info strong {
  display: block;
  margin-bottom: 5px;
}

.code-info span {
  font-size: 0.9rem;
  color: var(--text-light);
}

.code-stats {
  text-align: right;
}

.code-stats .usage {
  font-size: 1.2rem;
  font-weight: bold;
}

.code-stats .label {
  font-size: 0.8rem;
  color: var(--text-light);
}

.form-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 15px;
  margin-bottom: 20px;
}

/* Device/IP Logger */
.device-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  background: var(--background);
  border-radius: 8px;
  margin-bottom: 8px;
  border-left: 3px solid var(--accent);
}

.device-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.device-ip {
  font-size: 1rem;
  color: var(--text);
}

.device-code {
  font-size: 0.85rem;
  color: var(--text-light);
}

.device-dates {
  text-align: right;
  font-size: 0.8rem;
  color: var(--text-light);
}

.device-date {
  margin-bottom: 2px;
}

/* Image Upload */
.image-upload-area {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  transition: border-color 0.2s;
}

.image-upload-area:hover {
  border-color: var(--primary);
}

.image-upload-area input[type="file"] {
  display: none;
}

.upload-label {
  display: block;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--primary);
  margin-bottom: 5px;
}

.upload-hint {
  font-size: 0.85rem;
  color: var(--text-light);
  margin: 0;
}

.uploaded-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 15px;
}

.uploaded-image-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
}

.uploaded-image-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.remove-image-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.remove-image-btn:hover {
  opacity: 0.9;
}

/* Post Images */
.post-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 15px;
  margin: 20px 0;
}

.post-image {
  width: 100%;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.2s;
}

.post-image:hover {
  transform: scale(1.02);
}

/* Image Modal */
.image-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.image-modal-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
}

.image-modal-content img {
  max-width: 100%;
  max-height: 85vh;
  border-radius: 8px;
}

.image-modal-close {
  position: absolute;
  top: -15px;
  right: -15px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: white;
  color: #333;
  border: none;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Gallery */
.gallery-info {
  color: var(--text-light);
  margin-bottom: 25px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.gallery-item {
  background: var(--card-bg);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.gallery-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}

.gallery-item img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
}

.gallery-item-info {
  padding: 12px 15px;
}

.gallery-post-title {
  display: block;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-date {
  font-size: 0.85rem;
  color: var(--text-light);
}

/* Responsive */
@media (max-width: 600px) {
  .container {
    padding: 15px;
  }
  
  .login-box {
    padding: 30px 20px;
  }
  
  .header-content {
    flex-direction: column;
    text-align: center;
  }
  
  .posts-header {
    flex-direction: column;
    gap: 15px;
  }
  
  article {
    padding: 25px;
  }
  
  .form-row {
    grid-template-columns: 1fr;
  }
  
  .post-images {
    grid-template-columns: 1fr;
  }
  
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
  }
  
  .header-actions {
    flex-wrap: wrap;
    justify-content: center;
  }
}
