/* --- Core Design System & Tokens --- */
:root {
  --bg-color: hsl(222, 25%, 8%);
  --card-bg: hsla(222, 25%, 12%, 0.6);
  --card-border: hsla(222, 25%, 20%, 0.5);
  
  --primary-color: hsl(142, 72%, 43%);
  --primary-hover: hsl(142, 72%, 35%);
  --primary-glow: hsla(142, 72%, 43%, 0.25);
  
  --danger-color: hsl(354, 70%, 54%);
  --danger-hover: hsl(354, 70%, 45%);
  
  --text-primary: hsl(210, 20%, 98%);
  --text-secondary: hsl(210, 14%, 66%);
  --text-muted: hsl(210, 10%, 44%);
  
  --terminal-bg: hsl(222, 35%, 6%);
  
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
}

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

body {
  background-color: var(--bg-color);
  background-image: 
    radial-gradient(at 10% 20%, hsla(142, 72%, 43%, 0.08) 0px, transparent 50%),
    radial-gradient(at 90% 80%, hsla(222, 25%, 20%, 0.2) 0px, transparent 50%);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

h1, h2, h3, .auth-card h2 {
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* Glassmorphism utility */
.glass-card {
  background-color: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

/* --- Authentication (Login) --- */
.auth-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 40px 30px;
  text-align: center;
  animation: cardFadeIn 0.5s ease;
}

.auth-card h2 {
  font-size: 1.8rem;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 30px;
}

/* --- Forms & Inputs --- */
.form-group {
  margin-bottom: 20px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  background-color: hsla(222, 25%, 6%, 0.7);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 12px 16px;
  transition: var(--transition-smooth);
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

textarea {
  resize: vertical;
}

.form-row {
  display: flex;
  gap: 15px;
  flex-wrap: wrap;
}

.flex-1 { flex: 1; }
.width-100 { width: 120px; }

.form-tip {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 5px;
}

/* File Input Custom Styling */
.file-input-wrapper {
  position: relative;
  overflow: hidden;
  display: inline-block;
  width: 100%;
}

.file-input-wrapper input[type=file] {
  font-size: 100px;
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  cursor: pointer;
}

.file-input-btn {
  display: block;
  text-align: center;
  border: 1px dashed var(--card-border);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  background-color: hsla(222, 25%, 6%, 0.3);
  transition: var(--transition-smooth);
  cursor: pointer;
}

.file-input-wrapper:hover .file-input-btn {
  border-color: var(--primary-color);
  background-color: var(--primary-glow);
  color: var(--text-primary);
}

.file-name-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 5px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger {
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  transition: var(--transition-smooth);
}

.btn-primary {
  background-color: var(--primary-color);
  color: var(--bg-color);
  box-shadow: 0 4px 14px var(--primary-glow);
}

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

.btn-secondary {
  background-color: hsla(222, 25%, 20%, 0.6);
  border: 1px solid var(--card-border);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background-color: hsla(222, 25%, 25%, 0.8);
  border-color: var(--text-secondary);
}

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

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

.w-full { width: 100%; }
.hidden { display: none !important; }

.error-text {
  color: var(--danger-color);
  font-size: 0.8rem;
  margin-top: 15px;
}

/* --- Dashboard Wrapper & Layout --- */
.dashboard-wrapper {
  max-width: 1400px;
  margin: 0 auto;
  padding: 30px 20px;
  animation: fadeIn 0.4s ease;
}

/* Header */
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
  margin-bottom: 30px;
}

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

.logo-icon {
  width: 28px;
  height: 28px;
  color: var(--primary-color);
}

.header-logo h1 {
  font-size: 1.4rem;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 20px;
}

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 50px;
  background-color: hsla(222, 25%, 6%, 0.5);
  border: 1px solid var(--card-border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-online .status-dot {
  background-color: var(--primary-color);
  box-shadow: 0 0 8px var(--primary-color);
  animation: pulse 1.8s infinite;
}

.status-offline .status-dot {
  background-color: var(--danger-color);
  box-shadow: 0 0 8px var(--danger-color);
}

.status-online { border-color: hsla(142, 72%, 43%, 0.3); color: var(--primary-color); }
.status-offline { border-color: hsla(354, 70%, 54%, 0.3); color: var(--danger-color); }

/* Grid Layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1.1fr 1.2fr;
  gap: 30px;
}

.grid-col-form, .grid-col-monitor {
  padding: 30px;
  min-height: 520px;
}

.grid-col-history {
  grid-column: span 2;
  padding: 30px;
}

.section-title {
  font-size: 1.2rem;
  margin-bottom: 25px;
  color: var(--text-primary);
  border-left: 3px solid var(--primary-color);
  padding-left: 12px;
}

.action-buttons {
  display: flex;
  gap: 15px;
  margin-top: 10px;
}

/* --- Progress & Stats --- */
.progress-container {
  background-color: hsla(222, 25%, 6%, 0.4);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 25px;
  animation: slideDown 0.3s ease;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 10px;
}

.progress-title { color: var(--text-secondary); }
#progress-ratio { color: var(--text-primary); font-family: 'JetBrains Mono', monospace; }

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background-color: hsla(222, 25%, 6%, 0.8);
  border-radius: 50px;
  overflow: hidden;
  margin-bottom: 20px;
}

.progress-bar-fill {
  height: 100%;
  background-color: var(--primary-color);
  box-shadow: 0 0 10px var(--primary-glow);
  width: 0%;
  transition: width 0.4s cubic-bezier(0.1, 0.8, 0.3, 1);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
  border-radius: var(--radius-sm);
  background-color: hsla(222, 25%, 6%, 0.3);
  border: 1px solid var(--card-border);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-value {
  font-family: 'Outfit', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
}

.stat-item.success { border-color: hsla(142, 72%, 43%, 0.2); color: var(--primary-color); }
.stat-item.failed { border-color: hsla(354, 70%, 54%, 0.2); color: var(--danger-color); }
.stat-item.remaining { color: var(--text-secondary); }

/* --- Terminal Logs Console --- */
.terminal-container {
  display: flex;
  flex-direction: column;
  height: calc(100% - 145px);
  min-height: 280px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--card-border);
}

/* If stats box is hidden, adjust terminal size */
.progress-container.hidden ~ .terminal-container {
  height: 100%;
}

.terminal-header {
  background-color: hsla(222, 25%, 5%, 0.9);
  padding: 10px 15px;
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--card-border);
}

.terminal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.terminal-dot.red { background-color: #ff5f56; }
.terminal-dot.yellow { background-color: #ffbd2e; }
.terminal-dot.green { background-color: #27c93f; }

.terminal-title {
  margin-left: 8px;
  font-size: 0.7rem;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.1em;
}

.terminal-body {
  flex: 1;
  background-color: var(--terminal-bg);
  padding: 15px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: hsl(210, 10%, 80%);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-line {
  line-height: 1.4;
  word-break: break-all;
}

.log-line.system-msg { color: var(--text-muted); }
.log-line.sending-msg { color: hsl(200, 80%, 65%); }
.log-line.success-msg { color: var(--primary-color); }
.log-line.failed-msg { color: var(--danger-color); }

/* --- Table Styles (History & Modal) --- */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
  background-color: hsla(222, 25%, 6%, 0.3);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

th, td {
  padding: 12px 18px;
  border-bottom: 1px solid var(--card-border);
}

th {
  background-color: hsla(222, 25%, 5%, 0.8);
  font-weight: 600;
  color: var(--text-secondary);
  font-family: 'Outfit', sans-serif;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background-color: hsla(222, 25%, 15%, 0.4);
}

.text-center { text-align: center; }
.text-success { color: var(--primary-color); }
.text-danger { color: var(--danger-color); }

/* Badges */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge.completed { background-color: hsla(142, 72%, 43%, 0.15); color: var(--primary-color); }
.badge.processing { background-color: hsla(200, 80%, 65%, 0.15); color: hsl(200, 80%, 65%); }
.badge.stopped { background-color: hsla(45, 90%, 55%, 0.15); color: hsl(45, 90%, 55%); }

.msg-preview {
  max-width: 250px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  color: var(--text-secondary);
}

/* --- Modal View Detail Logs --- */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.modal-card {
  width: 90%;
  max-width: 800px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 30px;
  animation: slideUp 0.3s cubic-bezier(0.1, 0.8, 0.3, 1);
}

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

.modal-header h3 {
  font-size: 1.3rem;
  color: var(--text-primary);
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  transition: var(--transition-smooth);
}

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

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 15px;
  overflow: hidden;
}

.modal-summary {
  background-color: hsla(222, 25%, 5%, 0.5);
  border-radius: var(--radius-md);
  padding: 15px 20px;
  border: 1px solid var(--card-border);
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.modal-table {
  max-height: 45vh;
  overflow-y: auto;
}

/* --- Keyframe Animations --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

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

@keyframes pulse {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.6; }
  100% { transform: scale(1); opacity: 1; }
}

/* --- Responsive Adjustments --- */
@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
  .grid-col-form, .grid-col-monitor {
    min-height: auto;
  }
  .grid-col-history {
    grid-column: span 1;
  }
  .terminal-container {
    height: 350px;
  }
}

@media (max-width: 600px) {
  .dashboard-wrapper {
    padding: 15px 10px;
  }
  .main-header {
    flex-direction: column;
    gap: 15px;
    padding: 20px;
    align-items: flex-start;
  }
  .header-status {
    width: 100%;
    justify-content: space-between;
  }
  .modal-summary {
    flex-direction: column;
    gap: 5px;
  }
}

/* --- Slider (Range input) styling --- */
.slider {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: var(--radius-sm);
  background: hsla(222, 25%, 6%, 0.8);
  outline: none;
  transition: opacity .2s;
  border: none !important;
  padding: 0 !important;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
  box-shadow: 0 0 10px var(--primary-glow);
  transition: var(--transition-smooth);
}

.slider::-webkit-slider-thumb:hover {
  background: var(--primary-hover);
  transform: scale(1.2);
}

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
  box-shadow: 0 0 10px var(--primary-glow);
  transition: var(--transition-smooth);
}

.slider::-moz-range-thumb:hover {
  background: var(--primary-hover);
  transform: scale(1.2);
}
