/* SM-Tool – Professional Social Media Manager */

:root {
    --dark: #1B2A4A;
    --blue: #2563EB;
    --blue-hover: #1d4ed8;
    --green: #12B76A;
    --red: #F04438;
    --yellow: #F79009;
    --orange: #F97316;
    --purple: #A855F7;
    --bg: #F9FAFB;
    --bg2: #FFFFFF;
    --text: #101828;
    --text2: #667085;
    --border: #E4E7EC;
    --linkedin: #0A66C2;
    --facebook: #1877F2;
    --instagram: #E1306C;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: var(--text); background: var(--bg); }

/* --- Layout ------------------------------------------------- */

.app-container { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
    width: 260px; background: var(--dark); color: white;
    display: flex; flex-direction: column; padding: 24px 16px;
    border-right: 1px solid rgba(255,255,255,0.1);
    overflow-y: auto; flex-shrink: 0;
}
.sidebar-logo { font-size: 18px; font-weight: 700; margin-bottom: 32px; padding: 12px 8px; border-bottom: 1px solid rgba(255,255,255,0.1); letter-spacing: 0.5px; }
.nav-section { margin-bottom: 24px; }
.nav-section-title { font-size: 11px; font-weight: 600; color: rgba(255,255,255,0.4); text-transform: uppercase; letter-spacing: 0.8px; padding: 12px 16px 8px; }
.nav-items { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    padding: 10px 16px; border-radius: 6px; cursor: pointer; transition: all 0.15s;
    font-size: 13px; font-weight: 500; border: none; background: none;
    color: rgba(255,255,255,0.65); text-align: left;
    display: flex; justify-content: space-between; align-items: center;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.9); }
.nav-item.active { background: var(--blue); color: white; }
.nav-badge { background: var(--red); color: white; font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: 600; }
.sidebar-footer { padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.1); margin-top: auto; font-size: 12px; color: rgba(255,255,255,0.5); }
.sidebar-user { padding: 8px 0; word-break: break-word; color: rgba(255,255,255,0.7); }

.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.header { background: var(--bg2); border-bottom: 1px solid var(--border); padding: 20px 32px; font-size: 20px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 10px; }
.content { flex: 1; overflow-y: auto; padding: 32px; }

.section { display: none; }
.section.active { display: block; }

/* --- Stats -------------------------------------------------- */

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 20px; }
.stat-label { font-size: 12px; color: var(--text2); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 8px; }

/* --- Tables ------------------------------------------------- */

table { width: 100%; border-collapse: collapse; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-top: 16px; }
th { background: var(--bg); padding: 10px 16px; text-align: left; font-size: 11px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); }
td { padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr:hover { background: var(--bg); }

/* --- Buttons ------------------------------------------------ */

button, .btn {
    font-family: inherit; padding: 8px 16px; border: 1px solid var(--border);
    border-radius: 6px; background: var(--bg2); cursor: pointer;
    font-size: 13px; font-weight: 500; transition: all 0.15s; color: var(--text);
}
button:hover, .btn:hover { border-color: var(--blue); color: var(--blue); }
button.primary, .btn-primary { background: var(--blue); color: white; border: none; }
button.primary:hover, .btn-primary:hover { background: var(--blue-hover); color: white; }
button.danger { color: var(--red); }
button.danger:hover { border-color: var(--red); }
button.success { background: var(--green); color: white; border: none; }
button.success:hover { background: #0e9a59; color: white; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Modal -------------------------------------------------- */

.modal { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; }
.modal.open { display: flex; }
.modal-content { background: var(--bg2); border-radius: 10px; padding: 32px; max-width: 700px; width: 90%; max-height: 85vh; overflow-y: auto; }
.modal-header { font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.modal-body { margin-bottom: 20px; }
.modal-footer { display: flex; gap: 12px; justify-content: flex-end; }

/* --- Lightbox ----------------------------------------------- */

.lightbox { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.9); z-index: 2000; align-items: center; justify-content: center; cursor: zoom-out; padding: 40px; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,0.5); cursor: default; }
.lightbox-close { position: fixed; top: 20px; right: 28px; background: rgba(255,255,255,0.1); color: white; border: none; border-radius: 50%; width: 44px; height: 44px; font-size: 28px; line-height: 1; cursor: pointer; opacity: 0; transition: opacity 0.2s, background 0.2s; z-index: 2001; }
.lightbox:hover .lightbox-close { opacity: 1; }
.lightbox-close:hover { background: rgba(255,255,255,0.25); color: white; }

/* --- Forms -------------------------------------------------- */

.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; color: var(--text); text-transform: uppercase; letter-spacing: 0.3px; }
input, select, textarea { font-family: inherit; width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; color: var(--text); background: var(--bg2); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,0.08); }

.filter-bar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-bar input, .filter-bar select { flex: 1; min-width: 150px; }

/* --- Top Posts Cards ---------------------------------------- */

.top-post-card { transition: transform 0.1s ease, box-shadow 0.1s ease; }
.top-post-card:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.08); border-color: var(--primary); }

/* --- Badges ------------------------------------------------- */

.badge { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge.green { background: rgba(18,183,106,0.1); color: var(--green); }
.badge.red { background: rgba(240,68,56,0.1); color: var(--red); }
.badge.yellow { background: rgba(247,144,9,0.1); color: var(--yellow); }
.badge.blue { background: rgba(37,99,235,0.1); color: var(--blue); }
.badge.gray { background: rgba(102,112,133,0.1); color: var(--text2); }
.badge.purple { background: rgba(168,85,247,0.1); color: var(--purple); }

/* --- Toast -------------------------------------------------- */

.toast { position: fixed; bottom: 24px; right: 24px; background: var(--text); color: white; padding: 12px 20px; border-radius: 6px; font-size: 13px; z-index: 2000; animation: slideIn 0.2s ease; }
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes slideIn { from { transform: translateX(100px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* --- Channel Chips ------------------------------------------ */

.channel-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; color: white; white-space: nowrap; }
.channel-chip.linkedin { background: var(--linkedin); }
.channel-chip.facebook { background: var(--facebook); }
.channel-chip.instagram { background: var(--instagram); }
.channel-chips { display: flex; gap: 4px; flex-wrap: wrap; }

/* --- Post Grid ---------------------------------------------- */

.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.post-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; transition: box-shadow 0.15s; cursor: pointer; }
.post-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.post-card-img { width: 100%; height: 160px; object-fit: cover; background: var(--bg); display: flex; align-items: center; justify-content: center; color: var(--text2); font-size: 14px; }
.post-card-img img { width: 100%; height: 100%; object-fit: cover; }
.post-card-body { padding: 16px; }
.post-card-title { font-size: 14px; font-weight: 600; margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.post-card-text { font-size: 12px; color: var(--text2); margin-bottom: 10px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.post-card-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 12px; color: var(--text2); }
.post-card-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.post-card-actions button { font-size: 11px; padding: 4px 10px; }

/* --- Image Upload ------------------------------------------- */

.image-upload-zone { border: 2px dashed var(--border); border-radius: 8px; padding: 32px; text-align: center; cursor: pointer; transition: all 0.15s; background: var(--bg); }
.image-upload-zone:hover, .image-upload-zone.dragover { border-color: var(--blue); background: rgba(37,99,235,0.02); }
.image-upload-zone p { color: var(--text2); font-size: 13px; margin-top: 8px; }
.image-preview { position: relative; display: inline-block; margin-top: 12px; }
.image-preview img { max-height: 200px; max-width: 100%; border-radius: 6px; }
.image-preview .remove-btn { position: absolute; top: 4px; right: 4px; background: var(--red); color: white; border: none; border-radius: 50%; width: 24px; height: 24px; font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }

/* Multi-Image-Galerie im Editor (Cover ist Position 1, Reihenfolge per Drag&Drop) */
.image-gallery { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.gallery-item { position: relative; width: 120px; height: 120px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); background: var(--bg); cursor: grab; flex-shrink: 0; }
.gallery-item:active { cursor: grabbing; }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.gallery-item.drag-over { outline: 2px dashed var(--blue); outline-offset: -2px; }
.gallery-item .remove-btn { position: absolute; top: 4px; right: 4px; background: var(--red); color: white; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; line-height: 1; }
.gallery-item .position-badge { position: absolute; bottom: 4px; right: 4px; background: rgba(0,0,0,0.65); color: white; font-size: 11px; padding: 2px 6px; border-radius: 10px; font-weight: 600; }
.gallery-item .cover-badge { position: absolute; top: 4px; left: 4px; background: var(--blue); color: white; font-size: 10px; padding: 2px 6px; border-radius: 10px; font-weight: 600; letter-spacing: 0.3px; text-transform: uppercase; }
.gallery-item .crop-btn { position: absolute; bottom: 4px; left: 4px; background: rgba(0,0,0,0.6); color: white; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; line-height: 1; }
.gallery-item .crop-btn:hover { background: var(--blue); }

/* Crop-Modal */
.crop-ratio-btn { padding: 6px 12px; font-size: 13px; }
.crop-ratio-btn.active { background: var(--blue); color: white; border-color: var(--blue); }

.char-counter { text-align: right; font-size: 11px; color: var(--text2); margin-top: 4px; }
.char-counter.warn { color: var(--yellow); }
.char-counter.over { color: var(--red); font-weight: 600; }

/* --- Channel Selection -------------------------------------- */

.channel-check { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border: 2px solid var(--border); border-radius: 6px; cursor: pointer; transition: all 0.15s; font-size: 13px; font-weight: 500; }
.channel-check:has(input:checked) { border-color: var(--blue); background: rgba(37,99,235,0.04); }
.channel-check input { margin: 0; }

/* --- Schedule ----------------------------------------------- */

.schedule-options { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.schedule-option { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; }
.schedule-option input[type=radio] { margin: 0; }

/* --- Platform Tabs ------------------------------------------ */

.platform-tab { padding: 8px 16px; border: none; background: none; border-bottom: 2px solid transparent; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text2); transition: all 0.15s; }
.platform-tab.active { color: var(--text); border-bottom-color: var(--blue); }
.platform-tab:hover { color: var(--text); }

/* --- Calendar ----------------------------------------------- */

.calendar-nav { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.calendar-nav .month-label { font-size: 16px; font-weight: 700; min-width: 200px; text-align: center; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.calendar-header { background: var(--bg); padding: 10px; text-align: center; font-size: 11px; font-weight: 600; color: var(--text2); text-transform: uppercase; }
.calendar-day { background: var(--bg2); padding: 8px; min-height: 100px; position: relative; }
.calendar-day.other { background: var(--bg); opacity: 0.4; }
.calendar-day.today { background: rgba(37,99,235,0.03); }
.calendar-day .day-num { font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 4px; }
.calendar-day.today .day-num { color: var(--blue); font-weight: 700; }
.calendar-post { font-size: 10px; padding: 2px 6px; border-radius: 3px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; color: white; }
.calendar-post.draft { background: var(--text2); }
.calendar-post.scheduled { background: var(--blue); }
.calendar-post.sent { background: var(--green); }
.calendar-post.error, .calendar-post.failed { background: var(--red); }
.calendar-post.sending { background: var(--yellow); }

/* --- Channel Cards ------------------------------------------ */

.channel-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; display: flex; align-items: center; gap: 16px; margin-bottom: 10px; }
.channel-card .platform-icon { font-size: 14px; font-weight: 700; width: 42px; height: 42px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: white; flex-shrink: 0; }
.channel-card .platform-icon.linkedin { background: var(--linkedin); }
.channel-card .platform-icon.facebook { background: var(--facebook); }
.channel-card .platform-icon.instagram { background: var(--instagram); }
.channel-card .channel-info { flex: 1; }
.channel-card .channel-name { font-weight: 600; font-size: 14px; }
.channel-card .channel-detail { font-size: 12px; color: var(--text2); margin-top: 4px; }
.channel-card .channel-actions { display: flex; gap: 8px; }
.channel-card .channel-actions button { font-size: 11px; padding: 4px 10px; }

.connect-btns { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.connect-btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px; border-radius: 6px; font-size: 13px; font-weight: 600; color: white; border: none; cursor: pointer; transition: opacity 0.15s; }
.connect-btn:hover { opacity: 0.9; color: white; }
.connect-btn.linkedin { background: var(--linkedin); }
.connect-btn.meta { background: var(--facebook); }

/* --- Empty State -------------------------------------------- */

.empty-state { text-align: center; padding: 48px 20px; color: var(--text2); }
.empty-state .icon { font-size: 32px; margin-bottom: 12px; font-weight: 300; }
.empty-state p { font-size: 14px; margin-bottom: 16px; }

/* --- Login -------------------------------------------------- */

.login-container { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; background: var(--bg); }
.login-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 40px; max-width: 400px; width: 100%; }
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card .subtitle { color: var(--text2); font-size: 13px; margin-bottom: 24px; }
.login-card .error-msg { background: rgba(240,68,56,0.08); color: var(--red); padding: 10px 12px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; display: none; }

/* --- User Table --------------------------------------------- */

.user-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; display: flex; align-items: center; gap: 16px; margin-bottom: 10px; }
.user-card .user-info { flex: 1; }
.user-card .user-name { font-weight: 600; font-size: 14px; }
.user-card .user-detail { font-size: 12px; color: var(--text2); margin-top: 2px; }
.user-card .user-actions { display: flex; gap: 8px; }
.user-card .user-actions button { font-size: 11px; padding: 4px 10px; }

/* --- Hamburger / Mobile ------------------------------------- */

.hamburger { display: none; background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px 8px; color: var(--text); }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 98; }

@media (max-width: 768px) {
    .hamburger { display: block; }
    .sidebar { position: fixed; left: -280px; top: 0; bottom: 0; width: 260px; z-index: 99; transition: left .2s ease; }
    .sidebar.open { left: 0; }
    .sidebar-overlay.open { display: block; }
    .header { font-size: 16px; padding: 12px 16px; }
    .content { padding: 16px; }
    .post-grid { grid-template-columns: 1fr; }
    .calendar-grid { font-size: 10px; }
    .calendar-day { min-height: 60px; padding: 4px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-card { padding: 12px; }
    .stat-value { font-size: 22px; }
    .filter-bar { flex-direction: column; }
    .filter-bar input, .filter-bar select { min-width: 100%; }
    table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .channel-card { flex-direction: column; text-align: center; gap: 10px; }
    .channel-card .channel-actions { justify-content: center; }
    .user-card { flex-direction: column; text-align: center; gap: 10px; }
    .user-card .user-actions { justify-content: center; }
    .connect-btns { justify-content: center; }
    .modal-content { width: 95%; padding: 20px; margin: 10px; }
    .schedule-options { flex-direction: column; gap: 8px; }
    .post-card-actions { justify-content: center; }
    .login-card { padding: 24px; }
}

/* PWA standalone mode: safe area insets */
@supports (padding: env(safe-area-inset-top)) {
    .header { padding-top: max(12px, env(safe-area-inset-top)); }
    .sidebar { padding-top: max(24px, env(safe-area-inset-top)); }
    .content { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
}

/* Small phones */
@media (max-width: 380px) {
    .stats-grid { grid-template-columns: 1fr; }
    .header { font-size: 14px; padding: 10px 12px; }
    .content { padding: 12px; }
    .calendar-header { padding: 6px; font-size: 10px; }
    .calendar-day { min-height: 48px; }
}

/* --- Sections Layout ---------------------------------------- */

h3 { font-size: 14px; font-weight: 700; margin: 20px 0 10px 0; text-transform: uppercase; letter-spacing: 0.3px; color: var(--text2); }

/* --- 2FA Setup ---------------------------------------------- */

.totp-secret { font-family: 'SF Mono', 'Consolas', monospace; font-size: 16px; letter-spacing: 2px; background: var(--bg); padding: 12px 16px; border-radius: 6px; border: 1px solid var(--border); text-align: center; margin: 12px 0; }

/* --- Location Selector ------------------------------------------ */

.location-select {
    width: 100%; padding: 8px 10px; border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px; background: rgba(255,255,255,0.08); color: white;
    font-size: 13px; font-weight: 500; cursor: pointer; outline: none;
    appearance: auto;
}
.location-select:focus { border-color: var(--blue); }
.location-select option { background: var(--dark); color: white; }

.header-location {
    font-size: 13px; font-weight: 500; color: var(--blue);
    margin-left: auto; padding: 4px 12px;
    background: rgba(37,99,235,0.08); border-radius: 4px;
}
.header-location:empty { display: none; }

/* --- Location Badge --------------------------------------------- */

.location-badge {
    display: inline-block; padding: 2px 8px; border-radius: 4px;
    font-size: 11px; font-weight: 600;
    background: rgba(37,99,235,0.08); color: var(--blue);
    white-space: nowrap;
}

/* --- Location Group --------------------------------------------- */

.location-group { margin-bottom: 24px; }
.location-group-title {
    font-size: 13px; font-weight: 700; color: var(--text);
    padding: 8px 0; margin-bottom: 8px;
    border-bottom: 2px solid var(--blue);
    display: flex; align-items: center; gap: 8px;
}
.location-group-title .count {
    font-size: 11px; font-weight: 500; color: var(--text2);
}

/* --- Location Checkboxes (User Management) ---------------------- */

.location-checks { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.location-check {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 12px; font-weight: 500; cursor: pointer; transition: all 0.15s;
}
.location-check:has(input:checked) { border-color: var(--blue); background: rgba(37,99,235,0.04); }
.location-check input { margin: 0; }
