/* frontend/admin/admin.css */
/* ========= COLOR SYSTEM ========= */
:root {
  --bg-0: #111417;
  --bg-1: #181c20;
  --bg-2: #1f2429;
  --fg-0: #e8eaed;
  --fg-1: #c3c7cb;
  --accent: #00bfa6;
  --error: #ff6b6b;
  --radius: 8px;
  --transition: 0.25s;
  font-family: system-ui, sans-serif;
}

/* ========= GLOBAL ========= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  display: grid;
  grid-template-columns: 220px 1fr;
  height: 100vh;
  background: var(--bg-1);
  color: var(--fg-0);
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
  transition: color var(--transition);
}

button,
input,
textarea,
select {
  font: inherit;
  border-radius: var(--radius);
  border: 1px solid transparent;
}

button:hover {
  cursor: pointer;
  opacity: 0.9;
}

/* ========= SIDEBAR ========= */
aside {
  background: var(--bg-0);
  border-right: 1px solid var(--bg-2);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  height: 100vh;
  overflow: hidden;
  min-height: 0;
}

aside .aside-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

aside header {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 2rem;
}

.nav-toggle {
  display: none;
  border: 1px solid var(--bg-2);
  background: var(--bg-2);
  color: var(--fg-0);
  padding: 0.45rem 0.7rem;
  font-size: 0.9rem;
}

aside nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  padding-right: 0.2rem;
}

aside nav a {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  color: var(--fg-1);
  white-space: nowrap;
}

aside nav a.active,
aside nav a:hover {
  background: var(--accent);
  color: #000;
}

aside .aside-footer {
  flex: 0 0 auto;
}

.lang-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.lang-btn {
  border: 1px solid var(--bg-2);
  background: var(--bg-2);
  color: var(--fg-0);
  padding: 0.5rem 0.7rem;
}

.lang-btn.active {
  background: var(--accent);
  color: #000;
}

/* ========= MAIN VIEW ========= */
main#view {
  overflow-y: auto;
  padding: 2rem;
  background: var(--bg-1);
  min-height: 0;
}

/* ========= COMPONENTS ========= */
.card {
  background: var(--bg-2);
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--bg-0);
  margin-bottom: 1.5rem;
}

.card h2 {
  margin: 0 0 1rem 0;
  font-size: 1.2rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.75rem 0.5rem;
  text-align: left;
}

tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.03);
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.4rem 0.9rem;
  background: var(--accent);
  color: #000;
  border: none;
}

.btn.secondary {
  background: var(--bg-0);
  color: var(--fg-0);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn.delete {
  background: var(--error);
  color: #fff;
}

input[type="text"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  background: var(--bg-0);
  color: var(--fg-0);
  border: 1px solid var(--bg-2);
  margin-bottom: 0.75rem;
}

input::placeholder,
textarea::placeholder {
  color: rgba(195, 199, 203, 0.7);
  opacity: 1;
}

/* Keep admin inputs readable when browser auto-fills saved values */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--fg-0);
  -webkit-box-shadow: 0 0 0px 1000px var(--bg-0) inset;
  box-shadow: 0 0 0px 1000px var(--bg-0) inset;
  transition: background-color 9999s ease-in-out 0s;
}

html[dir="rtl"] aside {
  border-right: none;
  border-left: 1px solid var(--bg-2);
}

html[dir="rtl"] th,
html[dir="rtl"] td,
html[dir="rtl"] input,
html[dir="rtl"] textarea,
html[dir="rtl"] label,
html[dir="rtl"] p,
html[dir="rtl"] h2,
html[dir="rtl"] h3,
html[dir="rtl"] h4,
html[dir="rtl"] li,
html[dir="rtl"] div {
  text-align: right;
}

html[dir="rtl"] .actions {
  justify-content: flex-end;
}

@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  aside {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 0.75rem;
    border-right: none;
    border-bottom: 1px solid var(--bg-2);
    background: rgba(17, 20, 23, 0.98);
    backdrop-filter: blur(8px);
    height: auto;
  }
  aside header {
    margin: 0;
    font-size: 1rem;
  }
  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
  }
  aside nav {
    display: none;
    margin-top: 0.75rem;
    background: var(--bg-1);
    border: 1px solid var(--bg-2);
    border-radius: 10px;
    padding: 0.4rem;
    max-height: 58vh;
    overflow-y: auto;
  }
  aside nav a {
    display: block;
    width: 100%;
    font-size: 0.95rem;
    padding: 0.62rem 0.72rem;
  }
  .lang-switch {
    grid-template-columns: 1fr 1fr;
  }
  body.nav-open aside nav {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
  }
  body.nav-open {
    overflow: hidden;
  }
  main#view {
    padding: 1rem;
  }
  .card {
    padding: 1rem;
    margin-bottom: 1rem;
  }
  .card h2 {
    font-size: 1.05rem;
  }
  .actions {
    width: 100%;
  }
  .actions .btn,
  .btn {
    width: 100%;
    text-align: center;
  }
  label {
    display: block;
    margin-bottom: 0.5rem;
  }
  pre {
    font-size: 0.82rem;
    white-space: pre-wrap;
    word-break: break-word;
  }
  ol {
    padding-left: 1rem;
    margin-left: 0.2rem;
  }
}

/* 2-column grid inside .card when .grid-2 class present */
.card.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

/* Chart canvas should fill its column */
.card canvas {
  width: 100% !important;
  max-height: 320px;
}

/* Responsive: stack columns on narrow screens */
@media (max-width: 768px) {
  .card.grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  main#view {
    padding: 0.75rem;
  }
  .card {
    padding: 0.85rem;
    border-radius: 10px;
  }
  input[type="text"],
  input[type="password"],
  textarea {
    padding: 0.6rem;
    font-size: 16px;
  }
}


/* subtle card shadow */
.card {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.25);
}

/* striped tables used by analytics */
table.striped tbody tr:nth-child(odd) {
  background: rgba(255, 255, 255, 0.02);
}

/* chart container tweaks */
.chart-wrap {
  position: relative;
  padding-bottom: 1rem;
}

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

.crm-card {
  background: var(--bg-1);
  border: 1px solid var(--bg-0);
  border-radius: var(--radius);
  padding: 1rem;
}

.crm-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.muted {
  color: var(--fg-1);
  font-size: 0.9rem;
}

.meta-steps {
  margin: 0.85rem 0 0;
  color: var(--fg-1);
  line-height: 1.55;
}

.meta-tabs {
  display: flex;
  gap: 0.5rem;
  margin: 0 0 1rem;
  flex-wrap: wrap;
}

.meta-tab {
  border: 1px solid var(--bg-2);
  background: var(--bg-0);
  color: var(--fg-0);
  padding: 0.55rem 0.9rem;
}

.meta-tab.active {
  background: var(--accent);
  color: #000;
}

.meta-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.meta-channel-card h3 {
  margin: 0 0 0.3rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.connected {
  background: rgba(0, 191, 166, 0.16);
  color: #7ff5df;
}

.status-pill.pending {
  background: rgba(255, 201, 71, 0.15);
  color: #ffd978;
}

.status-pill.idle {
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg-1);
}

.meta-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem 1rem;
}

.meta-form-grid label {
  color: var(--fg-1);
  font-size: 0.9rem;
}

.meta-form-grid input,
.meta-form-grid select {
  margin-top: 0.35rem;
  margin-bottom: 0;
}

.meta-callback {
  background: var(--bg-1);
  border: 1px solid var(--bg-0);
  border-radius: var(--radius);
  color: var(--fg-1);
  margin: 1rem 0;
  padding: 0.75rem;
  overflow-wrap: anywhere;
}

.meta-callback code {
  color: var(--fg-0);
}

.meta-health {
  display: grid;
  gap: 0.35rem;
  margin: 0 0 1rem;
  color: var(--fg-1);
  font-size: 0.9rem;
}

.meta-health .meta-error {
  color: #ffd0d0;
}

.meta-advanced {
  background: var(--bg-1);
  border: 1px solid var(--bg-0);
  border-radius: var(--radius);
  margin: 1rem 0;
  padding: 0.75rem;
}

.meta-advanced summary {
  cursor: pointer;
  font-weight: 700;
}

.meta-option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem 1rem;
  margin-top: 0.8rem;
  color: var(--fg-1);
}

.meta-option-grid label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.meta-option-grid input {
  width: auto;
  margin: 0;
}

@media (max-width: 768px) {
  .meta-form-grid {
    grid-template-columns: 1fr;
  }
  .meta-card-head {
    flex-direction: column;
  }
  .meta-tabs {
    display: grid;
    grid-template-columns: 1fr;
  }
  .meta-option-grid {
    grid-template-columns: 1fr;
  }
}
