/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #F8F6F3;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #F0EDE8;
  --bg-elevated: #E8E5DF;
  --border: #D8D4CD;
  --border-light: #C8C4BD;
  --accent: #C49A3C;
  --accent-dim: #A07D2A;
  --accent-glow: rgba(196, 154, 60, 0.08);
  --cyan: #3D7B8A;
  --cyan-dim: #2D5B6A;
  --green: #3D8A5A;
  --green-dim: #2D6A4A;
  --red: #B84A4A;
  --red-dim: #8A3A3A;
  --orange: #B88A3A;
  --text-primary: #1C1C1C;
  --text-secondary: #6B6B6B;
  --text-muted: #999999;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.1);
  --sidebar-w: 220px;
  --font-display: Georgia, 'Noto Serif SC', serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', Consolas, 'Courier New', monospace;
}

html { font-size: 15px; }

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; transition: color .2s; }
a:hover { color: var(--accent-dim); }

::selection { background: var(--accent); color: var(--bg-primary); }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ===== Layout ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  animation: slideIn .5s ease-out;
}

@keyframes slideIn {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo a {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: .02em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo .logo-mark {
  display: inline-flex;
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: .8rem;
  font-weight: 700;
  color: var(--bg-primary);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: .88rem;
  font-weight: 450;
  transition: all .2s;
  position: relative;
}

.sidebar-nav a .nav-icon {
  width: 20px;
  text-align: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.sidebar-nav a:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.sidebar-nav a.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.sidebar-nav a.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}

.sidebar-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  color: var(--bg-primary);
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }

.sidebar-user-name {
  font-size: .82rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: .7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ===== Main Content ===== */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px 40px;
  animation: fadeIn .6s ease-out;
}

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

/* ===== Top Bar ===== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -.01em;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ===== Alerts ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: .85rem;
  margin-bottom: 20px;
  animation: fadeIn .3s ease-out;
}

.alert-error {
  background: rgba(196, 90, 90, .12);
  border: 1px solid rgba(196, 90, 90, .25);
  color: var(--red);
}

.alert-success {
  background: rgba(91, 154, 111, .12);
  border: 1px solid rgba(91, 154, 111, .25);
  color: var(--green);
}

/* ===== Cards ===== */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: all .25s;
  margin-bottom: 24px;
}

.card:hover { border-color: var(--border-light); }

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .08em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-body { padding: 20px; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }

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

.form-input,
.form-select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: .88rem;
  transition: all .2s;
  outline: none;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input::placeholder { color: var(--text-muted); }

.form-row-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-row-2col .form-group { margin-bottom: 0; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg-primary);
}
.btn-primary:hover {
  background: var(--accent-dim);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(212, 168, 83, .25);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.btn-sm {
  padding: 6px 12px;
  font-size: .8rem;
}

.btn-cyan {
  background: var(--cyan);
  color: #fff;
}
.btn-cyan:hover {
  background: var(--cyan-dim);
  transform: translateY(-1px);
}

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(196, 90, 90, .3);
}
.btn-danger:hover {
  background: rgba(196, 90, 90, .1);
  border-color: var(--red);
}

.btn-delete {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
}
.btn-delete:hover {
  background: var(--red);
  color: #fff;
  transform: translateY(-1px);
}

/* ===== Table ===== */
.table-wrap {
  overflow-x: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}

thead th {
  padding: 12px 14px;
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
}

tbody td {
  padding: 12px 14px;
  font-size: .83rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  transition: background .15s;
}

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

tbody tr:hover td { background: rgba(212, 168, 83, .03); }

/* inline editable inputs in table */
td .form-input {
  width: 110px;
  padding: 6px 10px;
  font-size: .8rem;
}

/* port badge */
.port-badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: .75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* project tag */
.project-tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--accent-glow);
  border: 1px solid rgba(196, 154, 60, .2);
  border-radius: var(--radius-sm);
  font-size: .75rem;
  color: var(--accent-dim);
  margin: 2px 2px;
}

/* path cell */
.path-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
}

.path-cell code {
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 3px 8px;
  border-radius: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.copy-btn {
  flex-shrink: 0;
  padding: 3px 8px;
  font-size: .72rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all .15s;
}

.copy-btn:hover {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: var(--accent);
}

/* checkbox */
.ws-checkbox,
.archive-checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* action buttons cell */
.action-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.action-group form { display: inline; }

/* ===== Archive List ===== */
.archive-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.archive-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: .82rem;
  transition: all .2s;
}

.archive-item:hover {
  border-color: var(--border-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.archive-item .archive-name {
  color: var(--text-primary);
  font-weight: 500;
}

.archive-item .archive-version {
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 1px 6px;
  border-radius: 3px;
}

/* ===== Upgrade Panel ===== */
.upgrade-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
}

.upgrade-panel h3 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 14px;
}

.upgrade-archives {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.upgrade-archives label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: background .15s;
}

.upgrade-archives label:hover { background: var(--bg-tertiary); }

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  animation: fadeIn .2s ease-out;
}

.modal-overlay.open { display: flex; }

.modal {
  width: auto;
  min-width: 520px;
  max-width: 90vw;
  max-height: 85vh;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  animation: modalIn .3s ease-out;
  overflow-y: auto;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-header h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}

.modal-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.modal-body { padding: 20px 24px; }

.modal-body .form-group { margin-bottom: 16px; }
.modal-body .form-group:last-child { margin-bottom: 0; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: .4;
}

.empty-state-text { font-size: .9rem; }

/* ===== Login Page ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: glowPulse 4s ease-in-out infinite;
}

@keyframes glowPulse {
  0%, 100% { opacity: .5; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
}

.login-card {
  position: relative;
  width: 380px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 36px;
  animation: fadeIn .6s ease-out;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .logo-mark {
  display: inline-flex;
  width: 40px;
  height: 40px;
  background: var(--accent);
  border-radius: var(--radius-md);
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--bg-primary);
  margin-bottom: 12px;
}

.login-logo h1 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
}

.login-logo p {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar-logo a span:not(.logo-mark),
  .sidebar-nav a span:not(.nav-icon),
  .sidebar-user-info { display: none; }
  .sidebar-logo a { justify-content: center; }
  .sidebar-nav a { justify-content: center; padding: 12px; }
  .sidebar-user { justify-content: center; }
  .main-content { margin-left: 60px; padding: 20px; }
  .top-bar { flex-direction: column; align-items: flex-start; }
  .form-row-2col { grid-template-columns: 1fr; }
}
