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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --accent: #ff6200;
  --accent-hover: #ff7c2a;
  --text: #e2e4f0;
  --text-dim: #8b8fa8;
  --green: #4caf7d;
  --red: #e05c6b;
  --yellow: #f0b429;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
}

/* Layout */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  height: 60px;
}

header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

nav { display: flex; gap: 4px; }

.tab-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); background: var(--surface2); }
.tab-btn.active { color: var(--accent); background: rgba(255,98,0,0.12); }

main { max-width: 900px; margin: 0 auto; padding: 32px 24px; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Section header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.section-header h2 { font-size: 20px; font-weight: 600; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: rgba(224,92,107,0.15); color: var(--red); border: 1px solid rgba(224,92,107,0.3); }
.btn-danger:hover { background: rgba(224,92,107,0.25); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Sub cards (Mobile) */
.sub-card { display: none; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 12px;
  border-bottom: 1px solid rgba(46,50,80,0.5);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,98,0,0.04); }

/* Service badge */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}
.badge-claude   { background: rgba(255,98,0,0.15);  color: #ff7c2a; }
.badge-googleone{ background: rgba(66,133,244,0.15); color: #7bb2ff; }
.badge-openai   { background: rgba(76,175,125,0.15); color: var(--green); }
.badge-zai      { background: rgba(108,99,255,0.15); color: #a39fff; }
.badge-other    { background: rgba(139,143,168,0.15); color: var(--text-dim); }

/* Reset countdown */
.reset-soon { color: var(--yellow); font-size: 13px; }
.reset-today { color: var(--green); font-size: 13px; font-weight: 600; }

/* Empty state */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-dim);
}
.empty p { margin-top: 8px; font-size: 14px; }
.empty div[style*="font-size:32px"] { color: var(--accent); }

/* Form */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-dim);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); }
.form-group select option { background: var(--surface2); }

/* Detail Panel */
#detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px rgba(0,0,0,0.5);
  transform: translateX(100%);
  transition: transform 0.2s ease-out;
  z-index: 101;
  display: flex;
  flex-direction: column;
}
#detail-panel.open {
  transform: translateX(0);
}
.detail-header {
  padding: 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.detail-header h2 { font-size: 18px; font-weight: 600; margin: 0; }
.detail-content {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
}
.detail-field { margin-bottom: 20px; }
.detail-label {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.detail-footer {
  padding: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
}
.detail-footer .btn { flex: 1; justify-content: center; }

#detail-backdrop { z-index: 100; }

/* Modal */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 105;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 480px;
  max-width: 95vw;
  box-shadow: var(--shadow);
}
.modal h2 { font-size: 17px; font-weight: 600; margin-bottom: 20px; }
.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* Notifications section */
.notif-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.notif-row input[type="text"] {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
}
.notif-row input:focus { border-color: var(--accent); }

.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.chat-item:last-child { border-bottom: none; }
.chat-id { font-family: monospace; font-size: 13px; color: var(--text-dim); }

/* Status indicator */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}
.status-ok   { background: var(--green); }
.status-off  { background: var(--text-dim); }

/* Usage Status */
.usage-bar-container-inline {
  background: var(--surface2);
  border-radius: 4px;
  height: 6px;
  width: 100%;
  max-width: 150px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.usage-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}
.usage-bar.danger {
  background: var(--red);
}
.badge-blocked {
  background: rgba(224,92,107,0.15);
  color: var(--red);
  border: 1px solid rgba(224,92,107,0.3);
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
}

/* Log */
.log-item {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.log-item:last-child { border-bottom: none; }
.log-time { color: var(--text-dim); font-size: 12px; white-space: nowrap; min-width: 120px; }
.log-channel {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  height: fit-content;
}
.log-channel-telegram { background: rgba(41,182,246,0.15); color: #29b6f6; }
.log-channel-webpush  { background: rgba(108,99,255,0.15); color: #a39fff; }
.log-msg { color: var(--text); }

/* Push button state */
#push-btn.subscribed { background: rgba(224,92,107,0.15); color: var(--red); border: 1px solid rgba(224,92,107,0.3); }
#push-btn.subscribed:hover { background: rgba(224,92,107,0.25); }

/* Alerts */
.alert {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 12px;
}
.alert-info { background: rgba(255,98,0,0.1); border: 1px solid rgba(255,98,0,0.3); color: var(--accent); }
.alert-warn { background: rgba(240,180,41,0.1); border: 1px solid rgba(240,180,41,0.3); color: var(--yellow); }

/* Responsive */
@media (max-width: 600px) {
  #detail-panel { width: 100%; border-left: none; }
  header { gap: 16px; }
  nav { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab-btn { padding: 8px 10px; white-space: nowrap; }
  main { padding: 20px 16px; }

  .section-header { flex-direction: column; align-items: stretch; gap: 12px; }
  #add-sub-btn { width: 100%; justify-content: center; padding: 12px; font-size: 16px; }
  td, th { padding: 10px 8px; }

  table { display: none; }
  .card.table-wrap { background: transparent; border: none; padding: 0; margin-bottom: 0; }

  .sub-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    position: relative;
  }
  .sub-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
  }
  .sub-card-title {
    font-size: 15px;
    font-weight: 600;
  }
  .sub-card-notes {
    font-size: 13px;
    color: var(--text-dim);
    margin-top: 2px;
  }
  .sub-card-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 12px;
  }
  .sub-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
  }
}
