/* ===== RESET & BASE ===== */
*{box-sizing:border-box}
body{margin:0;font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;background:#f0f4f8;color:#111827}

/* ===== LAYOUT ===== */
.layout{min-height:100vh;display:flex;flex-direction:column}
.main{flex:1;padding:1.25rem;max-width:1200px;margin:0 auto;width:100%}
.footer{padding:.75rem 1rem;font-size:.8rem;text-align:center;color:#9ca3af;border-top:1px solid #e5e7eb;background:#fff}

/* ===== NAVBAR ===== */
.nav{display:flex;align-items:center;justify-content:space-between;padding:.65rem 1.5rem;background:#fff;border-bottom:1px solid #e5e7eb;position:sticky;top:0;z-index:100;box-shadow:0 1px 3px #0001}
.nav-brand{font-weight:700;font-size:1rem;color:#111827;display:flex;align-items:center;gap:.4rem}
.nav ul{list-style:none;display:flex;gap:.25rem;padding:0;margin:0}
.nav a{text-decoration:none;color:#4b5563;padding:.35rem .7rem;border-radius:.5rem;font-size:.875rem;transition:background .15s,color .15s}
.nav a:hover{background:#f3f4f6}
.nav a.active{background:#2563eb;color:#fff}
.nav-logout{font-size:.85rem;color:#b91c1c;padding:.35rem .7rem;border-radius:.5rem;text-decoration:none}
.nav-logout:hover{background:#fee2e2}

/* ===== CARDS ===== */
.card{background:#fff;border-radius:.875rem;padding:1.25rem;box-shadow:0 1px 3px #0f172a12,0 1px 2px #0f172a0a;margin-bottom:1rem;overflow:hidden}
.logincard{background:#fff;border-radius:.875rem;padding:1.5rem;box-shadow:0 4px 24px #0f172a18;min-width:360px}

/* ===== STATS ROW ===== */
.stats-row{display:grid;grid-template-columns:repeat(4,1fr);gap:.75rem;margin-bottom:1rem}
.stat-card{background:#fff;border-radius:.875rem;padding:1rem 1.25rem;box-shadow:0 1px 3px #0f172a12;display:flex;align-items:center;gap:.875rem}
.stat-icon{width:42px;height:42px;border-radius:.625rem;display:flex;align-items:center;justify-content:center;font-size:1.25rem;flex-shrink:0}
.stat-value{font-size:1.5rem;font-weight:700;line-height:1.2}
.stat-label{font-size:.75rem;color:#6b7280;margin-top:.1rem}

/* ===== FORMS ===== */
.form-row{display:flex;flex-direction:column;margin-bottom:.75rem}
.form-row label{font-size:.8rem;font-weight:500;color:#4b5563;margin-bottom:.3rem}
input[type="text"],input[type="time"],input[type="date"],input[type="file"],select,textarea{
  padding:.45rem .65rem;border-radius:.5rem;border:1px solid #d1d5db;font:inherit;
  background:#fff;transition:border-color .15s,box-shadow .15s;color:#111827}
input[type="text"]:focus,input[type="time"]:focus,input[type="date"]:focus,select:focus,textarea:focus{
  border-color:#2563eb;box-shadow:0 0 0 3px #2563eb20;outline:none}
textarea{min-height:140px}
input[type="password"]{padding:.5rem .75rem;border:1px solid #d1d5db;border-radius:.5rem;font-size:1rem;background:#fff;color:#111827;outline:none;transition:border-color .2s,box-shadow .2s;width:100%}
input[type="password"]:focus{border-color:#2563eb;box-shadow:0 0 0 3px #2563eb20}

/* ===== BUTTONS ===== */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:.3rem;padding:.45rem .875rem;border-radius:.6rem;border:none;font-size:.875rem;font-weight:500;cursor:pointer;transition:opacity .15s,transform .1s;text-decoration:none}
.btn:active{transform:scale(.97)}
.btn-primary{background:#2563eb;color:#fff}
.btn-primary:hover{background:#1d4ed8}
.btn-secondary{background:#f3f4f6;color:#374151;border:1px solid #e5e7eb}
.btn-secondary:hover{background:#e5e7eb}
.btn-danger{background:#dc2626;color:#fff}
.btn-danger:hover{background:#b91c1c}
.btn-sm{padding:.3rem .6rem;font-size:.8rem}

/* ===== TOGGLE ===== */
.toggle{position:relative;width:42px;height:22px;display:inline-block;vertical-align:middle}
.toggle input{opacity:0;width:0;height:0}
.toggle span{position:absolute;cursor:pointer;inset:0;background-color:#d1d5db;border-radius:999px;transition:.2s}
.toggle span::before{content:"";position:absolute;height:18px;width:18px;left:2px;top:2px;background:#fff;border-radius:999px;transition:.2s;box-shadow:0 1px 3px #0002}
.toggle input:checked + span{background-color:#22c55e}
.toggle input:checked + span::before{transform:translateX(20px)}

/* ===== TABLE ===== */
.table{width:100%;border-collapse:collapse;font-size:.85rem}
.table th,.table td{padding:.55rem .6rem;border-bottom:1px solid #f3f4f6;vertical-align:middle}
.table th{text-align:left;font-size:.75rem;font-weight:600;color:#6b7280;text-transform:uppercase;letter-spacing:.025em;background:#fafafa}
.table tbody tr:hover{background:#f9fafb}
.table-actions{display:flex;gap:.35rem;white-space:nowrap}

/* ===== BADGES ===== */
.time-badge{display:inline-flex;align-items:center;padding:.2rem .5rem;border-radius:.375rem;font-size:.8rem;font-weight:600;font-variant-numeric:tabular-nums}
.time-badge-1{background:#dbeafe;color:#1d4ed8}
.time-badge-2{background:#fce7f3;color:#9d174d}
.status-badge{display:inline-flex;align-items:center;gap:.25rem;padding:.2rem .5rem;border-radius:.375rem;font-size:.75rem;font-weight:500}
.status-ok{background:#dcfce7;color:#166534}
.status-error{background:#fee2e2;color:#991b1b}

/* ===== AFF LINK ===== */
.aff-link{color:#2563eb;text-decoration:none;display:inline-block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:.8rem}
.aff-link:hover{text-decoration:underline}

/* ===== ALERT ===== */
.alert-error{font-size:.85rem;color:#b91c1c;background:#fee2e2;border-radius:.5rem;padding:.5rem .75rem;margin-bottom:.75rem}

/* ===== EDITOR ===== */
.editor-toolbar{display:flex;flex-wrap:wrap;gap:.25rem;align-items:center;margin-bottom:.35rem}
.btn-xs{padding:.2rem .4rem;font-size:.75rem}
.editor-hint{font-size:.75rem;color:#6b7280;margin-left:.25rem}
.editor-area{min-height:180px;padding:.6rem .7rem;border-radius:.6rem;border:1px solid #d1d5db;font:inherit;background:#fafafa;white-space:pre-wrap;outline:none}
.editor-area:focus{border-color:#2563eb;box-shadow:0 0 0 2px #2563eb20}

/* ===== TELEGRAM PREVIEW ===== */
.tg-preview{border-radius:.9rem;border:1px solid #e5e7eb;background:linear-gradient(180deg,#f9fafb,#fff);padding:.75rem .8rem;font-size:.9rem}
.tg-preview-header{display:flex;gap:.6rem;align-items:center;margin-bottom:.5rem}
.tg-avatar{width:32px;height:32px;border-radius:999px;background:#2563eb;color:#fff;display:flex;align-items:center;justify-content:center;font-weight:600;font-size:.9rem}
.tg-header-text{display:flex;flex-direction:column}
.tg-header-title{font-weight:600;color:#111827}
.tg-header-sub{font-size:.75rem;color:#6b7280}
.tg-preview-body{border-radius:.8rem;background:#fff;border:1px solid #e5e7eb;padding:.6rem .7rem .5rem}
.tg-preview-media{margin-bottom:.5rem}
.tg-preview-media img,.tg-preview-media video{max-width:70%;border-radius:.75rem;display:block}
.tg-preview-text{white-space:pre-wrap;color:#111827;font-size:.9rem}
.tg-preview-text b,.tg-preview-text strong{font-weight:600}
.tg-preview-text i,.tg-preview-text em{font-style:italic}
.tg-preview-text u{text-decoration:underline}
.tg-preview-buttons{margin-top:.6rem}
.tg-btn-row{display:flex;flex-wrap:nowrap;gap:.35rem;margin-bottom:.35rem}
.tg-btn{flex:1;text-align:center;padding:.35rem .4rem;border-radius:.6rem;background:#e5e7eb;font-size:.8rem;color:#111827;cursor:default}

/* ===== CHANNELS ===== */
.channels-wrapper{display:flex;flex-direction:column;gap:.5rem}
.channel-row{display:flex;flex-wrap:wrap;gap:.5rem}
.channel-row input[type="text"]{flex:1 1 150px}
.channel-add{margin-top:.5rem}

/* ===== LOGS ===== */
.logs-status-ok{color:#16a34a;font-weight:600}
.logs-status-error{color:#dc2626;font-weight:600}

/* ===== RESPONSIVE ===== */
@media (max-width:900px){
  .stats-row{grid-template-columns:repeat(2,1fr)}
  .card{min-width:0}
}
@media (max-width:640px){
  .nav ul{display:none}
  .main{padding:.75rem}
  .table{font-size:.8rem}
  .stats-row{grid-template-columns:1fr 1fr}
}

/* ===== PAGINATION ===== */
.pagination{display:flex;align-items:center;gap:.3rem;flex-wrap:wrap;margin-top:.75rem;font-size:.85rem}
.page-btn{display:inline-flex;align-items:center;justify-content:center;min-width:2rem;height:2rem;padding:0 .5rem;border-radius:.5rem;background:#f3f4f6;color:#374151;text-decoration:none;border:1px solid #e5e7eb;transition:background .15s}
.page-btn:hover{background:#e5e7eb}
.page-active{background:#2563eb !important;color:#fff !important;border-color:#2563eb;font-weight:600}
.page-disabled{color:#d1d5db;cursor:default;pointer-events:none}
.page-ellipsis{color:#9ca3af;padding:0 .2rem}
.page-info{margin-left:.5rem;color:#6b7280;font-size:.8rem}
