/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #f5f7fa; color: #1a1a2e; line-height: 1.5; }
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* Sidebar */
.sidebar { width: 240px; background: #1a1a2e; color: #e2e8f0; display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; }
.sidebar-brand { padding: 20px; font-size: 18px; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-nav { flex: 1; padding: 12px 0; }
.sidebar-nav a { display: flex; align-items: center; padding: 10px 20px; color: #94a3b8; transition: background .15s, color .15s; }
.sidebar-nav a:hover, .sidebar-nav a.active { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar-nav a .icon { margin-right: 10px; font-size: 18px; width: 24px; text-align: center; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.1); font-size: 13px; color: #64748b; }
.sidebar-footer a { color: #94a3b8; }

/* Main content */
.main { margin-left: 240px; flex: 1; padding: 24px 32px; min-width: 0; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.page-header h1 { font-size: 24px; font-weight: 600; }

/* ===== Cards ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card { background: #fff; border-radius: 10px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.card-label { font-size: 13px; color: #64748b; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.card-value { font-size: 28px; font-weight: 700; color: #1a1a2e; }
.card-sub { font-size: 13px; color: #94a3b8; margin-top: 4px; }

/* ===== Tables ===== */
.table-wrapper { background: #fff; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.08); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid #e2e8f0; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: #64748b; background: #f8fafc; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ===== Search bar ===== */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input { flex: 1; padding: 8px 14px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; }
.search-bar input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.1); }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; padding: 8px 16px; border-radius: 6px; font-size: 14px; font-weight: 500; border: none; cursor: pointer; transition: background .15s; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; text-decoration: none; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; text-decoration: none; }
.btn-success { background: #22c55e; color: #fff; }
.btn-success:hover { background: #16a34a; text-decoration: none; }
.btn-outline { background: transparent; border: 1px solid #d1d5db; color: #374151; }
.btn-outline:hover { background: #f3f4f6; text-decoration: none; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* ===== Badges ===== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 9999px; font-size: 12px; font-weight: 500; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-blue { background: #dbeafe; color: #1e40af; }

/* ===== Profile ===== */
.profile-card { background: #fff; border-radius: 10px; padding: 24px; box-shadow: 0 1px 3px rgba(0,0,0,.08); margin-bottom: 24px; }
.profile-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.profile-name { font-size: 22px; font-weight: 600; }
.profile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.profile-field label { display: block; font-size: 12px; text-transform: uppercase; color: #64748b; margin-bottom: 2px; }
.profile-field .value { font-size: 15px; }

/* Tags */
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 9999px; font-size: 13px; background: #e0e7ff; color: #3730a3; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; color: #374151; }
.form-group input, .form-group textarea, .form-group select { width: 100%; padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; }
.form-group textarea { resize: vertical; min-height: 80px; }
.form-inline { display: flex; gap: 8px; align-items: flex-end; }

/* ===== Chat view ===== */
.chat { display: flex; flex-direction: column; gap: 12px; padding: 16px; background: #f8fafc; border-radius: 10px; }
.chat-msg { max-width: 75%; padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.6; word-wrap: break-word; }
.chat-msg.user { align-self: flex-start; background: #e2e8f0; color: #1a1a2e; border-bottom-left-radius: 4px; }
.chat-msg.assistant { align-self: flex-end; background: #2563eb; color: #fff; border-bottom-right-radius: 4px; }
.chat-msg .meta { font-size: 11px; margin-top: 4px; opacity: .6; }

/* ===== Pagination ===== */
.pagination { display: flex; gap: 4px; justify-content: center; padding: 16px; }
.pagination a, .pagination span { padding: 6px 12px; border-radius: 6px; font-size: 14px; }
.pagination a { background: #fff; border: 1px solid #d1d5db; color: #374151; }
.pagination a:hover { background: #f3f4f6; text-decoration: none; }
.pagination .current { background: #2563eb; color: #fff; }

/* ===== Login page ===== */
.login-wrapper { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: #f5f7fa; }
.login-box { background: #fff; padding: 40px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,.1); width: 100%; max-width: 400px; }
.login-box h1 { text-align: center; margin-bottom: 24px; font-size: 22px; }
.login-box .error { background: #fee2e2; color: #991b1b; padding: 8px 12px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }

/* ===== Broadcast layout ===== */
.broadcast-layout { display: flex; gap: 24px; align-items: flex-start; }
.broadcast-form-col { flex: 1; min-width: 0; }
.broadcast-preview-col { width: 400px; flex-shrink: 0; }
.preview-body { font-size: 14px; line-height: 1.6; word-wrap: break-word; }
.preview-body p { margin-bottom: 8px; }
.preview-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.segment-fieldset { border: 1px solid #d1d5db; border-radius: 8px; padding: 16px; }
.segment-fieldset legend { font-size: 13px; font-weight: 500; color: #374151; padding: 0 6px; }
.radio-label { display: block; padding: 4px 0; font-size: 14px; cursor: pointer; }
.radio-label input { margin-right: 6px; }

/* ===== Progress bar ===== */
.progress-bar-container { background: #e2e8f0; border-radius: 9999px; height: 20px; overflow: hidden; }
.progress-bar { background: #2563eb; height: 100%; border-radius: 9999px; transition: width .5s ease; min-width: 0; }

/* ===== Alert ===== */
.alert { padding: 10px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }

/* ===== Settings page ===== */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 24px; }
.settings-section-title { font-size: 18px; font-weight: 600; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid #e2e8f0; }
.range-group { display: flex; align-items: center; gap: 12px; }
.range-group input[type="range"] { flex: 1; }
.range-value { font-weight: 600; min-width: 32px; text-align: center; }

/* ===== Button Builder ===== */
.button-builder { border: 1px solid #e2e8f0; border-radius: 8px; padding: 16px; background: #f8fafc; }
.button-rows { margin-bottom: 12px; }

.btn-row { background: #fff; border: 1px solid #d1d5db; border-radius: 8px; padding: 12px; margin-bottom: 10px; transition: box-shadow .15s; }
.btn-row:hover { box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.btn-row-dragging { opacity: 0.5; }
.btn-row-dragover { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.2); }

.btn-row-header { display: flex; align-items: center; margin-bottom: 10px; gap: 8px; }
.btn-row-handle { cursor: grab; font-size: 16px; color: #94a3b8; user-select: none; padding: 2px 4px; }
.btn-row-handle:hover { color: #64748b; }
.btn-row-label { font-size: 12px; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: .5px; flex: 1; }
.btn-row-delete { background: none; border: none; color: #94a3b8; font-size: 20px; cursor: pointer; padding: 0 4px; line-height: 1; }
.btn-row-delete:hover { color: #ef4444; }

.btn-row-buttons { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }

.btn-item { display: flex; align-items: center; gap: 8px; }
.btn-item-fields { display: flex; gap: 8px; flex: 1; }
.btn-item-fields input { flex: 1; padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px; }
.btn-item-fields input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.1); }
.btn-text-input { max-width: 200px; }
.btn-item-delete { background: none; border: none; color: #94a3b8; font-size: 18px; cursor: pointer; padding: 0 2px; line-height: 1; }
.btn-item-delete:hover { color: #ef4444; }

.btn-add-in-row { background: none; border: 1px dashed #cbd5e1; border-radius: 6px; color: #64748b; font-size: 12px; padding: 4px 12px; cursor: pointer; transition: all .15s; }
.btn-add-in-row:hover { border-color: #2563eb; color: #2563eb; background: rgba(37,99,235,.04); }

/* ===== Preview Telegram Buttons ===== */
.preview-buttons-container { margin-top: 12px; }
.preview-btn-row { display: flex; gap: 4px; margin-bottom: 4px; }
.preview-tg-btn { flex: 1; text-align: center; padding: 8px 12px; background: #e7edf4; color: #2563eb; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; text-decoration: none; transition: background .15s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-tg-btn:hover { background: #dbe4f0; text-decoration: none; }

/* ===== Utilities ===== */
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: #64748b; }
.text-sm { font-size: 13px; }
.flex-gap { display: flex; gap: 8px; }
