/* --- Global & Root --- */
:root {
  --bg-color: #1a1a1a;
  --bg-light: #2c2c2c;
  --card-color: #242424;
  --border-color: #444;
  --text-color: #f0f0f0;
  --text-muted: #aaa;
  --primary: #007bff;
  --primary-hover: #0056b3;
  --success: #28a745;
  --warning: #ffc107;
  --danger: #dc3545;
  --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --sidebar-width: 250px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font-main);
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  /* Prevent horizontal scroll on mobile when sidebar slides */
  overflow-x: hidden;
}
.hidden { display: none !important; }

/* --- Login Container --- */
#login-container {
  max-width: 400px;
  margin: 10vh auto;
  padding: 2.5rem;
  background-color: var(--card-color);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  text-align: center;
}
#login-container h2 { margin-bottom: 1.5rem; }

/* --- App Layout --- */
#app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
  /* Sidebar transition */
  transition: transform 0.3s ease-in-out;
}
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--card-color);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: left 0.3s ease-in-out;
}
.sidebar-header { padding: 1.5rem; border-bottom: 1px solid var(--border-color); }
.sidebar-header h2 { text-align: center; font-size: 1.5rem; }
.sidebar ul { list-style: none; flex-grow: 1; padding-top: 1rem; }
.sidebar ul li a {
  display: block;
  padding: 1rem 1.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all 0.2s ease;
}
.sidebar ul li a:hover {
  background-color: var(--bg-light);
  color: var(--text-color);
}
.sidebar ul li a.active {
  color: var(--text-color);
  border-left-color: var(--primary);
  background-color: var(--bg-light);
}
.sidebar-footer { padding: 1.5rem; border-top: 1px solid var(--border-color); }

.main-content {
  flex-grow: 1;
  padding: 2rem 3rem;
  overflow-y: auto;
  /* Add overlay for when menu is open */
  position: relative;
}
.main-content::before {
  content: '';
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background-color: rgba(0,0,0,0.5);
  opacity: 0;
  visibility: hidden;
  z-index: 998;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* NEW Main Header & Burger */
.main-header {
  display: flex;
  align-items: center;
  margin-bottom: 1.5rem;
}
.nav-toggle-button {
  display: none; /* Hidden on desktop */
  background: none;
  border: none;
  padding: 0.5rem;
  margin-right: 1rem;
  cursor: pointer;
  z-index: 1001;
}
.nav-toggle-button span {
  display: block;
  width: 25px;
  height: 3px;
  background-color: var(--text-color);
  margin: 5px 0;
  border-radius: 3px;
  transition: all 0.3s ease;
}
h1 { font-size: 2.2rem; }

.page { display: none; }
.page.active { display: block; }

/* --- Buttons & Forms --- */
button {
  font-family: var(--font-main);
  border: none;
  border-radius: 5px;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.button-primary { background-color: var(--primary); color: #fff; }
.button-primary:hover { background-color: var(--primary-hover); }
.button-secondary { background-color: var(--bg-light); color: var(--text-color); }
.button-secondary:hover { background-color: #444; }
#login-button, #logout-button { width: 100%; }
#logout-button { background-color: var(--danger); color: #fff; }
#logout-button:hover { background-color: #b02a37; }

input[type="text"], input[type="password"], textarea {
  width: 100%;
  padding: 0.75rem;
  background-color: var(--bg-light);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  font-family: var(--font-main);
  font-size: 1rem;
}
textarea { font-family: "Courier New", Courier, monospace; margin-top: 1rem; margin-bottom: 1rem; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1rem;
}

/* --- Cards --- */
.card {
  background-color: var(--card-color);
  border-radius: 8px;
  padding: 1.5rem 2rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border-color);
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}
.stat-card {
  background-color: var(--bg-light);
  border-radius: 8px;
  padding: 1.5rem;
  border: 1px solid var(--border-color);
}
.stat-card h3 { color: var(--text-muted); font-size: 1rem; margin-bottom: 0.5rem; }
.stat-card p { font-size: 2.5rem; font-weight: 600; }
.stat-card p.success { color: var(--success); }
.stat-card p.warning { color: var(--warning); }

/* --- Subscriber List & Table --- */
.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 1rem;
}
#search-bar { max-width: 300px; }
.sub-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}
.sub-table th, .sub-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}
.sub-table th { color: var(--text-muted); font-size: 0.9rem; }
.sub-table td .sub-name { font-weight: 600; display: block; }
.sub-table td .sub-notes { font-size: 0.9rem; color: var(--text-muted); }
.status-badge {
  padding: 0.25rem 0.6rem;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.8rem;
  display: inline-block;
}
.status-active { background-color: var(--success); color: #fff; }
.status-paused { background-color: var(--warning); color: #111; }
.action-button {
  background-color: var(--bg-light);
  color: var(--text-color);
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
  margin-right: 0.5rem;
  margin-top: 0.25rem;
}
.action-button.pause { background-color: var(--warning); color: #111; }
.action-button.activate { background-color: var(--success); color: #fff; }
.action-button.edit { background-color: var(--primary); color: #fff; }
.action-button.delete { background-color: var(--danger); color: #fff; }
.copy-box { display: flex; }
.copy-box input { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-bottom: 0; }
.copy-button {
  background-color: var(--primary);
  color: #fff;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
#new-sub-url-container {
  background-color: var(--bg-light);
  border-radius: 5px;
  padding: 1rem;
  margin-top: 1rem;
}

/* --- Config Page --- */
.config-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
#config-status { font-style: italic; color: var(--text-muted); }
#config-status.empty { color: var(--warning); }
#config-status.ok { color: var(--success); }
#save-status { text-align: center; margin-top: 1rem; font-weight: bold; }
#save-status.success { color: var(--success); }
#save-status.error { color: var(--danger); }

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background-color: rgba(0,0,0,0.7);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 1rem;
}
.modal {
  background-color: var(--card-color);
  border-radius: 8px;
  padding: 2rem;
  width: 100%;
  max-width: 500px;
}
.modal h2 { margin-bottom: 1.5rem; }
.modal label { display: block; margin-bottom: 0.5rem; color: var(--text-muted); }
.modal input { margin-bottom: 1rem; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* --- MOBILE RESPONSIVE STYLES --- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: calc(var(--sidebar-width) * -1 - 10px); /* Hide off-screen */
    height: 100%;
    z-index: 1000;
    border-right: 2px solid var(--border-color);
  }
  .main-content {
    margin-left: 0;
    padding: 1rem;
    transition: transform 0.3s ease-in-out;
  }
  .nav-toggle-button {
    display: block;
  }
  
  /* Sidebar Open State */
  #app-container.sidebar-open .sidebar {
    left: 0;
  }
  #app-container.sidebar-open .main-content::before {
    opacity: 1;
    visibility: visible;
  }
  /* Animate burger icon */
  #app-container.sidebar-open .nav-toggle-button span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
  }
  #app-container.sidebar-open .nav-toggle-button span:nth-child(2) {
    opacity: 0;
  }
  #app-container.sidebar-open .nav-toggle-button span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
  }

  h1 { font-size: 1.8rem; }
  .main-content { padding: 1rem; }
  .card { padding: 1rem; }
  .stats-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .list-header { flex-direction: column; align-items: stretch; }
  #search-bar { max-width: 100%; }

  /* Responsive Table */
  .sub-table {
    border: 0;
  }
  .sub-table thead {
    display: none;
  }
  .sub-table tr {
    display: block;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: 5px;
  }
  .sub-table td {
    display: block;
    padding: 0.75rem 1rem;
    padding-left: 50%;
    text-align: right;
    position: relative;
    border-bottom: 1px dotted var(--border-color);
  }
  .sub-table tr td:last-child {
    border-bottom: 0;
  }
  .sub-table td::before {
    content: attr(data-label);
    position: absolute;
    left: 1rem;
    width: 40%;
    text-align: left;
    font-weight: bold;
    color: var(--text-muted);
  }
  /* Adjust copy box for mobile table */
  .copy-box {
    flex-direction: column;
  }
  .copy-box input {
    border-radius: 5px 5px 0 0;
    text-align: center;
  }
  .copy-button {
    border-radius: 0 0 5px 5px;
  }
}