/* ═══════════════════════════════════════
   VARIABLES
═══════════════════════════════════════ */
:root {
  --bg:           #0d1117;
  --bg-card:      #161b22;
  --bg-card-2:    #1c2128;
  --bg-input:     #0d1117;
  --border:       #30363d;
  --border-focus: #58a6ff;
  --text:         #e6edf3;
  --text-muted:   #8b949e;
  --text-dim:     #6e7681;
  --accent:       #58a6ff;
  --green:        #3fb950;
  --green-glow:   rgba(63,185,80,.35);
  --red:          #f85149;
  --yellow:       #d29922;
  --btn-primary-bg:    #238636;
  --btn-primary-hover: #2ea043;
  --btn-danger-bg:     #6e1c1c;
  --btn-danger-hover:  #8f2727;
  --btn-success-bg:    #1b4721;
  --btn-success-hover: #238636;
  --btn-neutral-bg:    #21262d;
  --btn-neutral-hover: #30363d;
  --radius:    6px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,.5);
  --trans:     .15s ease;
}

/* ═══════════════════════════════════════
   RESET / BASE
═══════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color:       var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  font-size:   14px;
  line-height: 1.5;
  min-height:  100vh;
}

a { color: var(--accent); text-decoration: none; }

/* ═══════════════════════════════════════
   HEADER
═══════════════════════════════════════ */
.header {
  background:    var(--bg-card);
  border-bottom: 1px solid var(--border);
  height:        56px;
  padding:       0 24px;
  display:       flex;
  align-items:   center;
  justify-content: space-between;
  position:      sticky;
  top:           0;
  z-index:       50;
}

.header-left  { display: flex; align-items: center; gap: 10px; }
.header-right { display: flex; align-items: center; gap: 8px; }

.header-icon  { width: 22px; height: 22px; color: var(--accent); }
.header-title { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }

.header-time {
  font-size:   12px;
  font-family: 'SF Mono', Consolas, monospace;
  color:       var(--text-muted);
  min-width:   62px;
  text-align:  right;
}

/* ═══════════════════════════════════════
   MAIN LAYOUT
═══════════════════════════════════════ */
.main {
  max-width: 1300px;
  margin:    0 auto;
  padding:   24px 20px 48px;
  display:   flex;
  flex-direction: column;
  gap: 28px;
}

.section { display: flex; flex-direction: column; gap: 14px; }

.section-header {
  display:     flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  font-size:   16px;
  font-weight: 600;
}

/* ═══════════════════════════════════════
   CADDY CARD
═══════════════════════════════════════ */
.caddy-card {
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       18px 22px;
  display:       flex;
  align-items:   center;
  justify-content: space-between;
  gap:           16px;
  flex-wrap:     wrap;
  transition:    border-color var(--trans);
}

.caddy-card.is-running { border-color: rgba(63,185,80,.4); }

.caddy-left   { display: flex; align-items: center; gap: 14px; }
.caddy-actions{ display: flex; gap: 8px; flex-wrap: wrap; }

.caddy-title    { font-size: 15px; font-weight: 600; }
.caddy-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Status Dot */
.caddy-status-dot {
  width:         14px;
  height:        14px;
  border-radius: 50%;
  background:    var(--text-dim);
  flex-shrink:   0;
  transition:    background var(--trans);
}
.caddy-status-dot.running {
  background:  var(--green);
  box-shadow:  0 0 0 3px var(--green-glow);
  animation:   pulse-glow 2s ease-in-out infinite;
}
.caddy-status-dot.stopped { background: var(--red); box-shadow: none; }

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 3px var(--green-glow); }
  50%       { box-shadow: 0 0 0 6px rgba(63,185,80,.15); }
}

/* ═══════════════════════════════════════
   PROJECTS GRID
═══════════════════════════════════════ */
.projects-grid {
  display:               grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap:                   14px;
}

.project-card {
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       16px 18px;
  display:       flex;
  flex-direction: column;
  gap:           10px;
  transition:    border-color var(--trans), box-shadow var(--trans);
}

.project-card:hover { border-color: var(--border-focus); }
.project-card.is-running { border-color: rgba(63,185,80,.35); }

.project-card-top {
  display:     flex;
  align-items: flex-start;
  gap:         10px;
}

.project-dot {
  width:         10px;
  height:        10px;
  border-radius: 50%;
  background:    var(--text-dim);
  flex-shrink:   0;
  margin-top:    4px;
  transition:    background var(--trans), box-shadow var(--trans);
}
.project-dot.running {
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-glow);
  animation:  pulse-glow 2s ease-in-out infinite;
}
.project-dot.stopped { background: var(--red); box-shadow: none; }

.project-info   { flex: 1; min-width: 0; }
.project-name   { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-meta   { font-size: 11px; color: var(--text-muted); margin-top: 3px; display: flex; flex-direction: column; gap: 2px; }
.project-path   { font-family: 'SF Mono', Consolas, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.project-pid    { color: var(--accent); }

.project-status-badge {
  font-size:     10px;
  font-weight:   600;
  padding:       2px 7px;
  border-radius: 20px;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space:   nowrap;
  align-self:    flex-start;
}
.project-status-badge.running { background: rgba(63,185,80,.15); color: var(--green); }
.project-status-badge.stopped { background: rgba(248,81,73,.1);  color: var(--red); }

.project-actions {
  display:   flex;
  gap:       6px;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════
   SYSTEM PROCESSES TABLE
═══════════════════════════════════════ */
.sys-table-wrap {
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  overflow:      hidden;
}

.sys-table {
  width:           100%;
  border-collapse: collapse;
  font-size:       13px;
}

.sys-table th {
  background: var(--bg-card-2);
  padding:    8px 14px;
  text-align: left;
  font-weight: 500;
  color:       var(--text-muted);
  font-size:   11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
}

.sys-table td {
  padding:       8px 14px;
  border-bottom: 1px solid rgba(48,54,61,.5);
  font-family:   'SF Mono', Consolas, monospace;
  font-size:     12px;
}

.sys-table tr:last-child td { border-bottom: none; }
.sys-table tr:hover td      { background: var(--bg-card-2); }

/* ═══════════════════════════════════════
   EMPTY STATE
═══════════════════════════════════════ */
.empty-state {
  grid-column: 1 / -1;
  padding:     40px 20px;
  text-align:  center;
  color:       var(--text-muted);
  display:     flex;
  flex-direction: column;
  align-items: center;
  gap:         10px;
  background:  var(--bg-card);
  border:      1px dashed var(--border);
  border-radius: var(--radius-lg);
}
.empty-state svg  { color: var(--text-dim); }
.empty-state p    { font-size: 14px; }
.empty-state .text-muted { font-size: 12px; }

/* ═══════════════════════════════════════
   BUTTONS
═══════════════════════════════════════ */
.btn {
  display:       inline-flex;
  align-items:   center;
  gap:           5px;
  border:        1px solid transparent;
  border-radius: var(--radius);
  cursor:        pointer;
  font-size:     13px;
  font-weight:   500;
  padding:       6px 14px;
  transition:    background var(--trans), border-color var(--trans), opacity var(--trans);
  white-space:   nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

.btn-primary {
  background: var(--btn-primary-bg);
  color:      #fff;
  border-color: rgba(240,246,252,.1);
}
.btn-primary:not(:disabled):hover { background: var(--btn-primary-hover); }

.btn-danger {
  background: var(--btn-danger-bg);
  color:      var(--red);
  border-color: rgba(248,81,73,.2);
}
.btn-danger:not(:disabled):hover { background: var(--btn-danger-hover); }

.btn-success {
  background: var(--btn-success-bg);
  color:      var(--green);
  border-color: rgba(63,185,80,.2);
}
.btn-success:not(:disabled):hover { background: var(--btn-success-hover); color: #fff; }

.btn-neutral {
  background: var(--btn-neutral-bg);
  color:      var(--text);
  border-color: var(--border);
}
.btn-neutral:not(:disabled):hover { background: var(--btn-neutral-hover); }

.btn-ghost {
  background: transparent;
  color:      var(--text-muted);
  border-color: transparent;
}
.btn-ghost:not(:disabled):hover { background: var(--btn-neutral-bg); color: var(--text); }

/* ═══════════════════════════════════════
   MODALS
═══════════════════════════════════════ */
.modal-overlay {
  position:    fixed;
  inset:       0;
  background:  rgba(1,4,9,.75);
  backdrop-filter: blur(4px);
  z-index:     200;
  display:     flex;
  align-items: center;
  justify-content: center;
  padding:     16px;
  animation:   fade-in .15s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  width:         100%;
  max-width:     500px;
  max-height:    90vh;
  display:       flex;
  flex-direction: column;
  box-shadow:    var(--shadow-md);
  animation:     slide-up .15s ease;
}

.modal-wide { max-width: 780px; }

@keyframes slide-up {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display:       flex;
  align-items:   center;
  justify-content: space-between;
  padding:       16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink:   0;
}

.modal-header h3 { font-size: 15px; font-weight: 600; }

.modal-close {
  background: none;
  border:     none;
  color:      var(--text-muted);
  cursor:     pointer;
  font-size:  16px;
  padding:    2px 6px;
  border-radius: var(--radius);
  transition: color var(--trans), background var(--trans);
  line-height: 1;
}
.modal-close:hover { color: var(--text); background: var(--btn-neutral-bg); }

.modal-body {
  padding:    20px;
  overflow-y: auto;
  flex:       1;
}

.modal-footer {
  display:    flex;
  gap:        8px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.hidden { display: none !important; }

/* ═══════════════════════════════════════
   FORMS
═══════════════════════════════════════ */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-group:last-child { margin-bottom: 0; }

label {
  font-size:   12px;
  font-weight: 500;
  color:       var(--text-muted);
}

.label-row {
  display:     flex;
  align-items: center;
  gap:         7px;
  cursor:      pointer;
  font-size:   13px;
  color:       var(--text);
}

input[type="text"],
input[type="password"],
textarea {
  background:    var(--bg-input);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  color:         var(--text);
  font-size:     13px;
  padding:       8px 10px;
  width:         100%;
  font-family:   inherit;
  transition:    border-color var(--trans);
}
input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
  outline:      none;
  border-color: var(--border-focus);
  box-shadow:   0 0 0 3px rgba(88,166,255,.12);
}

input[type="checkbox"] {
  width:  15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

textarea { resize: vertical; font-family: 'SF Mono', Consolas, monospace; font-size: 12px; }

/* ═══════════════════════════════════════
   LOG VIEWER
═══════════════════════════════════════ */
.log-viewer {
  background:  #0a0c10;
  color:       #b3c3d8;
  font-family: 'SF Mono', 'Cascadia Code', Consolas, monospace;
  font-size:   12px;
  line-height: 1.6;
  padding:     14px 16px;
  overflow-y:  auto;
  height:      calc(80vh - 80px);
  max-height:  600px;
  white-space: pre-wrap;
  word-break:  break-all;
}

.log-line { display: block; }
.log-line.err  { color: #f87171; }
.log-line.sys  { color: #60a5fa; font-style: italic; }
.log-line.warn { color: #fbbf24; }

/* ═══════════════════════════════════════
   ALERTS / TOASTS
═══════════════════════════════════════ */
.alert {
  border-radius: var(--radius);
  padding:       10px 14px;
  font-size:     13px;
  margin-bottom: 14px;
}
.alert-error   { background: rgba(248,81,73,.12); border: 1px solid rgba(248,81,73,.3); color: var(--red); }
.alert-success { background: rgba(63,185,80,.12);  border: 1px solid rgba(63,185,80,.3);  color: var(--green); }

.toast-container {
  position:   fixed;
  bottom:     24px;
  right:      24px;
  z-index:    300;
  display:    flex;
  flex-direction: column;
  gap:        8px;
  pointer-events: none;
}

.toast {
  background:    var(--bg-card-2);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       10px 16px;
  font-size:     13px;
  box-shadow:    var(--shadow-md);
  max-width:     340px;
  animation:     toast-in .2s ease;
  pointer-events: all;
}

@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.toast.success { border-left: 3px solid var(--green); color: var(--green); }
.toast.error   { border-left: 3px solid var(--red);   color: var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }

/* ═══════════════════════════════════════
   LOGIN PAGE
═══════════════════════════════════════ */
.login-body {
  display:         flex;
  align-items:     center;
  justify-content: center;
  min-height:      100vh;
  background:      var(--bg);
}

.login-card {
  background:    var(--bg-card);
  border:        1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:       36px 32px;
  width:         100%;
  max-width:     360px;
  box-shadow:    var(--shadow-md);
}

.login-logo {
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  gap:             12px;
  margin-bottom:   28px;
  color:           var(--accent);
}

.login-title {
  font-size:   20px;
  font-weight: 700;
  color:       var(--text);
}

/* ═══════════════════════════════════════
   MISC
═══════════════════════════════════════ */
.text-muted { color: var(--text-muted); }

hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* Scrollbar */
::-webkit-scrollbar               { width: 6px; height: 6px; }
::-webkit-scrollbar-track         { background: transparent; }
::-webkit-scrollbar-thumb         { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover   { background: var(--border-focus); }
