:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --text: #1e293b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --sidebar-width: 260px;
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --panel: #1e293b;
  --text: #f1f5f9;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --muted: #94a3b8;
  --border: #334155;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* App Layout */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  transition: transform 0.3s ease;
  z-index: 50;
}

.sidebar-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 1.25rem;
  margin: 0;
  color: var(--accent);
}

.user-info {
  margin-bottom: 1.5rem;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted);
  word-break: break-all;
}

.nav-links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 0.5rem;
  cursor: pointer;
  text-align: left;
  font-size: 0.95rem;
  transition: all 0.2s;
  text-decoration: none;
}

.nav-btn:hover {
  background: var(--bg);
}

.nav-btn.active {
  background: var(--accent);
  color: white;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* Main Content */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  position: relative;
}

.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.menu-toggle {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text);
  cursor: pointer;
}

/* Tab Content */
.tab-pane {
  display: none;
  animation: fadeIn 0.3s ease-out;
}

.tab-pane.active {
  display: block;
}

/* Existing Components Adjustments */
.panel {
  background: var(--panel);
  border-radius: 1rem;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

input, textarea, select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  margin-top: 0.25rem;
}

label {
  display: block;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: white;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s;
}

.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: #ef4444; }
.btn.full-width { width: 100%; }
.actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.hidden { display: none; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    padding: 1rem;
  }

  .mobile-header {
    display: flex;
  }
  
  /* Overlay for mobile sidebar */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 45;
  }
  
  .sidebar-overlay.active {
    display: block;
  }
}

/* Utility for hiding text on small screens if needed, but we used drawer */

/* Restored Utilities */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Homepage Styles */
.hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem 1rem;
    background-color: var(--panel);
    min-height: 100vh;
    animation: fadeIn 1s ease-out;
}

.hero h1 {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 1rem;
    background: linear-gradient(45deg, var(--accent), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 3s ease infinite;
}

@keyframes gradientShift {
    0% { filter: hue-rotate(0deg); }
    50% { filter: hue-rotate(30deg); }
    100% { filter: hue-rotate(0deg); }
}

.hero p {
    font-size: 1.25rem;
    color: var(--muted);
    margin-bottom: 2rem;
    animation: fadeIn 1.2s ease-out;
}

.hero .actions {
    animation: fadeIn 1.4s ease-out;
}

/* Auth Pages */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.auth-panel {
  background: var(--panel);
  padding: 2.5rem;
  border-radius: 1rem;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
  border: 1px solid var(--border);
}

.auth-panel h2 {
  margin-top: 0;
  margin-bottom: 1.5rem;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text);
}

.auth-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.auth-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

/* Loading Spinner */
.spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 1s ease-in-out infinite;
  margin-right: 0.5rem;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Responsive Table */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px; /* Ensure table doesn't squish too much */
}

/* Responsive Text Toggling */
.text-mobile { display: none; }
.text-desktop { display: inline; }

/* Responsive Table to Cards on Mobile */
@media (max-width: 768px) {
  .text-mobile { display: inline; }
  .text-desktop { display: none; }

  .table-responsive {
    overflow: visible; /* Disable scroll, use cards */
  }

  table {
    display: block;
    min-width: 0;
  }

  thead {
    display: none; /* Hide headers */
  }

  tbody {
    display: block;
  }

  tr {
    display: block;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    margin-bottom: 1rem;
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  }

  td {
    display: block;
    text-align: left;
    padding: 0.25rem 0;
    border: none;
    font-size: 0.95rem;
  }

  /* Specific Column Styling based on order */
  
  /* English (1st column) */
  td:nth-of-type(1) {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 0.25rem;
  }

  /* Chinese (2nd column) */
  td:nth-of-type(2) {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
  }

  /* POS (3rd column) */
  td:nth-of-type(3)::before {
    content: "词性: ";
    color: var(--muted);
    font-size: 0.85rem;
  }
  td:nth-of-type(3) {
    display: inline-block;
    margin-right: 1rem;
    background: rgba(0,0,0,0.05);
    padding: 0.1rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
  }

  /* Definition (4th column) */
  td:nth-of-type(4) {
    margin-top: 0.5rem;
    color: var(--muted);
    font-size: 0.9rem;
    border-top: 1px dashed var(--border);
    padding-top: 0.5rem;
  }

  /* Examples (5th column) */
  td:nth-of-type(5) {
    margin-top: 0.5rem;
    text-align: right; /* Move button to right */
    position: absolute; /* Position relative to card */
    top: 1rem;
    right: 1rem;
  }
  
  /* Reset position for actions */
  tr {
    position: relative;
  }

  /* Actions (6th column) */
  td:nth-of-type(6) {
    margin-top: 1rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
  }
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal {
    background: var(--panel);
    border-radius: 1rem;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--muted);
}

.modal-body {
    white-space: pre-wrap;
    line-height: 1.6;
}