/* ============================================================
   VOWA — Main Stylesheet
   ============================================================ */

/* ---- CSS Variables ---- */
:root {
    --primary:        #25D366;
    --primary-dark:   #128C7E;
    --primary-light:  #DCF8C6;
    --primary-hover:  #1ebe59;

    --sidebar-bg:     #111827;
    --sidebar-hover:  #1f2937;
    --sidebar-active: #25D366;
    --sidebar-text:   #9ca3af;
    --sidebar-text-active: #ffffff;
    --sidebar-width:  240px;

    --topbar-height:  60px;
    --topbar-bg:      #ffffff;
    --topbar-border:  #e5e7eb;

    --body-bg:        #f3f4f6;
    --card-bg:        #ffffff;
    --card-shadow:    0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
    --card-shadow-hover: 0 4px 12px rgba(0,0,0,0.12);
    --card-radius:    12px;

    --text-primary:   #111827;
    --text-secondary: #6b7280;
    --text-muted:     #9ca3af;

    --border:         #e5e7eb;
    --border-focus:   #25D366;

    --input-bg:       #f9fafb;
    --input-radius:   8px;

    --danger:         #ef4444;
    --danger-light:   #fee2e2;
    --warning:        #f59e0b;
    --warning-light:  #fef3c7;
    --success:        #22c55e;
    --success-light:  #dcfce7;
    --info:           #3b82f6;
    --info-light:     #dbeafe;

    --btn-radius:     8px;
    --transition:     all 0.2s ease;

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--body-bg);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

img { max-width: 100%; display: block; }

ul, ol { list-style: none; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ============================================================
   LAYOUT
   ============================================================ */

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s ease;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    min-height: var(--topbar-height);
}

.sidebar-brand-icon {
    width: 36px; height: 36px;
    background: var(--primary);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-brand-name {
    font-size: 18px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.3px;
}

.sidebar-brand-sub {
    font-size: 10px;
    color: var(--sidebar-text);
    font-weight: 400;
    display: block;
    margin-top: -2px;
}

.sidebar-nav {
    padding: 16px 12px;
    flex: 1;
}

.sidebar-section {
    margin-bottom: 24px;
}

.sidebar-section-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--sidebar-text);
    padding: 0 8px;
    margin-bottom: 6px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--sidebar-text);
    font-size: 13.5px;
    font-weight: 500;
    transition: var(--transition);
    margin-bottom: 2px;
}

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: #e5e7eb;
}

.sidebar-link.active {
    background: var(--primary);
    color: var(--sidebar-text-active);
}

.sidebar-link .icon {
    width: 18px;
    text-align: center;
    font-size: 15px;
    flex-shrink: 0;
}

.sidebar-link .badge-pill {
    margin-left: auto;
    background: rgba(255,255,255,0.15);
    color: inherit;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 20px;
}

.sidebar-link.active .badge-pill {
    background: rgba(255,255,255,0.25);
}

#inbox-unread-badge {
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 18px;
    text-align: center;
}

.sidebar-footer {
    padding: 12px 12px 14px;
    border-top: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    gap: 4px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--sidebar-text);
    cursor: pointer;
    transition: var(--transition);
    flex: 1;
    min-width: 0;
    text-decoration: none;
}

.sidebar-user:hover { background: var(--sidebar-hover); }

.sidebar-user-avatar {
    width: 32px; height: 32px;
    background: var(--primary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: white;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #e5e7eb; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11px; color: var(--sidebar-text); }

.sidebar-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    color: var(--sidebar-text);
    font-size: 16px;
    flex-shrink: 0;
    text-decoration: none;
    transition: var(--transition);
}
.sidebar-logout-btn:hover {
    background: rgba(239,68,68,0.15);
    color: #fca5a5;
}

/* ---- Topbar ---- */
.topbar {
    height: var(--topbar-height);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    z-index: 99;
    gap: 12px;
}

.topbar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 18px;
}

.topbar-toggle:hover { background: var(--body-bg); }

.topbar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-btn {
    width: 36px; height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    font-size: 16px;
    transition: var(--transition);
    text-decoration: none;
}

.topbar-btn:hover {
    background: var(--body-bg);
    color: var(--text-primary);
    border-color: var(--border);
}

/* ---- Main Content ---- */
.main-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    padding: 24px;
    min-height: calc(100vh - var(--topbar-height));
    flex: 1;
}

/* ============================================================
   COMPONENTS
   ============================================================ */

/* ---- Cards ---- */
.card {
    background: var(--card-bg);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.card-body { padding: 20px; }

.card-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: #fafafa;
}

/* ---- Stat Cards ---- */
.stat-card {
    background: var(--card-bg);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
}

.stat-card:hover {
    box-shadow: var(--card-shadow-hover);
    transform: translateY(-1px);
}

.stat-icon {
    width: 52px; height: 52px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.stat-icon.green  { background: var(--success-light); color: var(--success); }
.stat-icon.blue   { background: var(--info-light);    color: var(--info); }
.stat-icon.yellow { background: var(--warning-light); color: var(--warning); }
.stat-icon.red    { background: var(--danger-light);  color: var(--danger); }

.stat-info { flex: 1; }

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    margin-top: 2px;
}

.stat-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 3px;
}

/* ---- Grid ---- */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--btn-radius);
    font-size: 13.5px;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn-lg { padding: 11px 24px; font-size: 15px; }

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: white;
}

.btn-secondary {
    background: white;
    color: var(--text-primary);
    border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--body-bg);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    border-color: #dc2626;
    color: white;
}

.btn-warning {
    background: var(--warning);
    color: white;
    border-color: var(--warning);
}
.btn-warning:hover:not(:disabled) {
    background: #d97706;
    border-color: #d97706;
    color: white;
}

.btn-info {
    background: var(--info);
    color: white;
    border-color: var(--info);
}
.btn-info:hover:not(:disabled) {
    background: #2563eb;
    border-color: #2563eb;
    color: white;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
    background: var(--body-bg);
    color: var(--text-primary);
}

/* ---- Forms ---- */
.form-group { margin-bottom: 18px; }

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--input-radius);
    font-size: 13.5px;
    font-family: var(--font);
    color: var(--text-primary);
    background: var(--input-bg);
    transition: var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(37,211,102,0.12);
    background: white;
}

.form-control::placeholder { color: var(--text-muted); }

.form-control:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

textarea.form-control { resize: vertical; min-height: 100px; }

select.form-control {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236b7280'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 36px;
}

.form-text {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 5px;
}

.form-error {
    font-size: 12px;
    color: var(--danger);
    margin-top: 5px;
}

.input-group {
    display: flex;
    gap: 0;
}

.input-group .form-control {
    border-radius: var(--input-radius) 0 0 var(--input-radius);
    flex: 1;
}

.input-group .btn {
    border-radius: 0 var(--input-radius) var(--input-radius) 0;
}

.input-group-text {
    padding: 9px 12px;
    background: var(--body-bg);
    border: 1px solid var(--border);
    border-right: none;
    border-radius: var(--input-radius) 0 0 var(--input-radius);
    color: var(--text-secondary);
    font-size: 13.5px;
    white-space: nowrap;
}

.input-group .input-group-text + .form-control {
    border-radius: 0 var(--input-radius) var(--input-radius) 0;
}

/* ---- Badges ---- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
}

.badge-success  { background: var(--success-light);  color: #16a34a; }
.badge-danger   { background: var(--danger-light);   color: #dc2626; }
.badge-warning  { background: var(--warning-light);  color: #d97706; }
.badge-info     { background: var(--info-light);     color: #2563eb; }
.badge-secondary { background: #f3f4f6; color: #6b7280; }

/* ---- Alerts ---- */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13.5px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

.alert-success { background: var(--success-light); color: #166534; border-color: #bbf7d0; }
.alert-danger  { background: var(--danger-light);  color: #991b1b; border-color: #fecaca; }
.alert-warning { background: var(--warning-light); color: #92400e; border-color: #fde68a; }
.alert-info    { background: var(--info-light);    color: #1e40af; border-color: #bfdbfe; }

/* ---- Tables ---- */
.table-wrapper { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

thead th {
    padding: 10px 16px;
    text-align: left;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    background: #f9fafb;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover { background: #f9fafb; }

/* ---- Pagination ---- */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
}

.page-btn {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: white;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.page-btn:hover { background: var(--body-bg); color: var(--text-primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: white; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-state-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.empty-state-text {
    font-size: 13.5px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

/* ---- Loading Spinner ---- */
.spinner {
    display: inline-block;
    width: 20px; height: 20px;
    border: 2.5px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
}

.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Modals ---- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: white;
    border-radius: var(--card-radius);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.96);
    transition: transform 0.2s ease;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.modal-overlay.open .modal { transform: scale(1); }

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 16px; font-weight: 600; }

.modal-close {
    width: 32px; height: 32px;
    border-radius: 6px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
    font-size: 18px;
    transition: var(--transition);
}

.modal-close:hover { background: var(--body-bg); color: var(--text-primary); }

.modal-body { padding: 20px; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 8px;
}

/* ---- Device Cards ---- */
.device-card {
    background: var(--card-bg);
    border-radius: var(--card-radius);
    border: 2px solid var(--border);
    padding: 24px;
    text-align: center;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.device-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: var(--border);
    transition: var(--transition);
}

.device-card.connected::before { background: var(--success); }
.device-card.connecting::before { background: var(--warning); }
.device-card.disconnected::before { background: var(--border); }

.device-card:hover { box-shadow: var(--card-shadow-hover); border-color: #d1d5db; }

.device-icon {
    width: 64px; height: 64px;
    background: #f3f4f6;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
    font-size: 28px;
}

.device-card.connected .device-icon { background: var(--success-light); }

.device-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.device-phone {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.device-status { margin-bottom: 16px; }

.device-actions { display: flex; gap: 8px; justify-content: center; }

/* ---- QR Code ---- */
.qr-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 32px;
}

.qr-image {
    width: 240px; height: 240px;
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    background: white;
}

.qr-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.pulse-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--warning);
    animation: pulse 1.5s ease-in-out infinite;
}

.pulse-dot.green { background: var(--success); }

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

/* ---- Page Header ---- */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}

.page-header-left  { flex: 1; }
.page-header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.page-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ---- Breadcrumb ---- */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.breadcrumb a { color: var(--text-secondary); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { color: var(--border); }
.breadcrumb .current { color: var(--text-primary); font-weight: 500; }

/* ---- Tabs ---- */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 24px;
    gap: 0;
}

.tab-link {
    padding: 10px 18px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
}

.tab-link:hover { color: var(--text-primary); }
.tab-link.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---- Progress Bar ---- */
.progress {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* ---- Utilities ---- */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-20 { gap: 20px; }

.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }

.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-info { color: var(--info); }
.text-sm { font-size: 12.5px; }
.text-xs { font-size: 11.5px; }
.font-mono { font-family: 'Courier New', monospace; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.w-full { width: 100%; }
.hidden { display: none !important; }

.divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

/* ============================================================
   AUTH PAGES
   ============================================================ */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1a1a2e 50%, #0d1117 100%);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.auth-page::before {
    content: '';
    position: absolute;
    width: 600px; height: 600px;
    border-radius: 50%;
    background: rgba(37,211,102,0.06);
    top: -200px; right: -200px;
}

.auth-page::after {
    content: '';
    position: absolute;
    width: 400px; height: 400px;
    border-radius: 50%;
    background: rgba(18,140,126,0.05);
    bottom: -150px; left: -150px;
}

.auth-card {
    background: white;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 80px rgba(0,0,0,0.4);
    position: relative;
    z-index: 1;
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 28px;
}

.auth-logo-icon {
    width: 48px; height: 48px;
    background: var(--primary);
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
    color: white;
}

.auth-logo-text { text-align: left; }

.auth-logo-name {
    font-size: 24px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.auth-logo-sub {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
}

.auth-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.auth-subtitle {
    font-size: 13.5px;
    color: var(--text-secondary);
    margin-bottom: 28px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    :root { --sidebar-width: 240px; }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .topbar {
        left: 0;
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
    }

    .topbar-toggle { display: flex; }

    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }

    .page-header {
        flex-direction: column;
    }

    .auth-card {
        padding: 28px 24px;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 99;
        display: none;
    }

    .sidebar-overlay.open { display: block; }
}

@media (max-width: 480px) {
    .modal { margin: 10px; max-width: calc(100% - 20px); }
    .card-body { padding: 16px; }
}

/* ---- Toggle Switch ---- */
.toggle-wrap {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.toggle-track {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-track input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #d1d5db;
    border-radius: 24px;
    transition: background 0.2s;
    cursor: pointer;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-track input:checked + .toggle-slider { background: var(--primary); }
.toggle-track input:checked + .toggle-slider::before { transform: translateX(20px); }
.toggle-track input:disabled + .toggle-slider { opacity: 0.5; cursor: not-allowed; }

/* ---- Webhook Log status dots ---- */
.wh-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.wh-dot.success { background: var(--success); }
.wh-dot.failed  { background: var(--danger); }
.wh-dot.timeout { background: var(--warning); }

/* ---- Copy input group ---- */
.copy-group {
    display: flex;
    gap: 0;
}
.copy-group .form-control {
    border-radius: var(--input-radius) 0 0 var(--input-radius);
    flex: 1;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    letter-spacing: 0.3px;
    background: var(--body-bg);
}
.copy-group .btn {
    border-radius: 0;
    border-left: none;
    flex-shrink: 0;
}
.copy-group .btn:last-child {
    border-radius: 0 var(--input-radius) var(--input-radius) 0;
}

/* ---- Toast Notifications ---- */
.toast-container {
    position: fixed;
    bottom: 24px; right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 360px;
}

.toast {
    background: white;
    border-radius: 10px;
    padding: 12px 16px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    display: flex;
    align-items: flex-start;
    gap: 10px;
    border-left: 4px solid var(--primary);
    animation: slideInRight 0.3s ease;
    font-size: 13.5px;
}

.toast.toast-success { border-left-color: var(--success); }
.toast.toast-danger  { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }
.toast.toast-info    { border-left-color: var(--info); }

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast-message { flex: 1; line-height: 1.4; }
.toast-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 16px;
    flex-shrink: 0;
    padding: 0;
    transition: var(--transition);
}
.toast-close:hover { color: var(--text-primary); }

/* ============================================================
   INBOX — WhatsApp-style chat
   ============================================================ */

/* Remove page padding when on inbox */
.page-inbox .main-content {
    padding: 0;
    overflow: hidden;
}

.inbox-layout {
    display: flex;
    height: calc(100vh - var(--topbar-height) - 48px);
    min-height: 400px;
    border-radius: var(--card-radius);
    border: 1px solid var(--border);
    box-shadow: var(--card-shadow);
    overflow: hidden;
    background: #fff;
}

.page-inbox .inbox-layout {
    height: calc(100vh - var(--topbar-height));
    border-radius: 0;
    border: none;
    box-shadow: none;
}

/* ---- Left pane ---- */
.inbox-sidebar {
    width: 320px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
}

.inbox-sidebar-header {
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: #fff;
}

.inbox-sidebar-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.inbox-search-wrap {
    position: relative;
}

.inbox-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    pointer-events: none;
    display: flex;
}

.inbox-search-input {
    width: 100%;
    height: 34px;
    padding: 0 10px 0 32px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--body-bg);
    font-size: 13px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s;
}

.inbox-search-input:focus {
    border-color: var(--primary);
    background: #fff;
}

.inbox-contact-list {
    flex: 1;
    overflow-y: auto;
}

/* Contact items */
.inbox-contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.1s;
    user-select: none;
}

.inbox-contact-item:hover  { background: #f5f6f6; }
.inbox-contact-item.active { background: #f0fdf4; border-right: 3px solid var(--primary); }

.inbox-contact-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    letter-spacing: 0.5px;
}

.inbox-contact-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.inbox-contact-row1,
.inbox-contact-row2 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.inbox-contact-name {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.inbox-contact-time {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.inbox-contact-preview {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.conv-tick {
    font-size: 11px;
    color: var(--text-muted);
    margin-right: 2px;
}

.inbox-unread-badge {
    background: var(--primary);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Inbox filter tabs */
.inbox-filter-tabs {
    display: flex;
    padding: 8px 10px;
    gap: 6px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}
.inbox-filter-tab {
    flex: 1;
    background: #f0f0f0;
    border: 1px solid transparent;
    border-radius: 20px;
    padding: 5px 8px;
    font-size: 0.78rem;
    font-weight: 500;
    color: #4b5563;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
    white-space: nowrap;
    text-align: center;
}
.inbox-filter-tab:hover  { background: #e0e0e0; color: #111827; }
.inbox-filter-tab.active { background: #25D366; color: #fff; border-color: #25D366; font-weight: 600; }

/* Group badge in conversation list */
.conv-group-badge {
    display: inline-block;
    background: rgba(37,211,102,0.12);
    color: #0e7c42;
    border: 1px solid rgba(37,211,102,0.3);
    border-radius: 8px;
    padding: 0 5px;
    font-size: 10px;
    font-weight: 600;
    margin-left: 4px;
    vertical-align: middle;
}

/* Sender name label inside group incoming bubbles — color set per-person via inline style */
.bubble-sender {
    font-size: 0.72rem;
    font-weight: 700;
    margin-bottom: 2px;
}

.inbox-empty-hint {
    padding: 40px 20px;
    text-align: center;
}

.inbox-list-loading,
.inbox-list-error {
    padding: 32px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

/* ---- Right pane ---- */
.inbox-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #efeae2;
}

/* Subtle chat background pattern */
.inbox-chat {
    background-color: #efeae2;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4c9b8' fill-opacity='0.25'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.inbox-chat-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.inbox-empty-content {
    background: rgba(255,255,255,0.85);
    border-radius: 16px;
    padding: 32px 40px;
    text-align: center;
    max-width: 300px;
}

.inbox-empty-icon  { display: flex; justify-content: center; margin-bottom: 16px; opacity: 0.85; }
.inbox-empty-title { font-size: 16px; font-weight: 700; color: var(--text-primary); margin-bottom: 8px; }
.inbox-empty-sub   { font-size: 12.5px; color: var(--text-secondary); line-height: 1.6; }

/* Chat view */
.inbox-chat-view {
    display: none; /* shown by JS via display:flex */
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.inbox-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    background: #f0f2f5;
    border-bottom: 1px solid #d9dbdf;
    flex-shrink: 0;
}

.inbox-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.inbox-chat-info  { flex: 1; min-width: 0; }
.inbox-chat-name  { font-size: 15px; font-weight: 700; color: #111827; line-height: 1.3; }
.inbox-chat-phone { font-size: 12px; color: #6b7280; }
.inbox-chat-online {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11.5px;
    color: #25D366;
    font-weight: 500;
}
.inbox-chat-online::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    background: #25D366;
    border-radius: 50%;
}
.inbox-chat-actions { flex-shrink: 0; }

/* Messages scrollable */
.inbox-messages-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.inbox-msgs-loading {
    display: flex;
    justify-content: center;
    padding: 24px;
}

.inbox-no-msgs {
    text-align: center;
    color: var(--text-muted);
    font-size: 12.5px;
    padding: 24px 0;
    background: rgba(255,255,255,0.7);
    border-radius: 8px;
    margin: 8px 0;
}

/* Date separator */
.chat-date-sep {
    display: flex;
    justify-content: center;
    margin: 10px 0 6px;
}

.chat-date-sep span {
    background: rgba(255,255,255,0.85);
    color: #667781;
    font-size: 11.5px;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Chat rows */
.chat-row {
    display: flex;
    margin-bottom: 2px;
}

.chat-row.in  { justify-content: flex-start; }
.chat-row.out { justify-content: flex-end; }

/* Bubbles */
.chat-bubble {
    max-width: 65%;
    min-width: 80px;
    padding: 6px 10px 4px 10px;
    border-radius: 12px;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.13);
    position: relative;
}

.chat-row.in  + .chat-row.in  .chat-bubble.in  { border-top-left-radius: 4px; }
.chat-row.out + .chat-row.out .chat-bubble.out { border-top-right-radius: 4px; }

.chat-bubble.in {
    background: #ffffff;
    border-radius: 0 12px 12px 12px;
    color: #111827;
}

.chat-bubble.out {
    background: #dcf8c6;
    border-radius: 12px 0 12px 12px;
    color: #111827;
}

/* Bubble pointer (WhatsApp-style notch) */
.chat-row.in .chat-bubble.in::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 8px 8px 0;
    border-color: transparent #ffffff transparent transparent;
}

.chat-row.out .chat-bubble.out::before {
    content: '';
    position: absolute;
    top: 0;
    right: -8px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 8px 8px 0 0;
    border-color: #dcf8c6 transparent transparent transparent;
}

/* Hide notch on consecutive same-direction bubbles */
.chat-row.in  + .chat-row.in  .chat-bubble.in::before,
.chat-row.out + .chat-row.out .chat-bubble.out::before {
    display: none;
}

.bubble-text {
    font-size: 13.5px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    padding-bottom: 2px;
}

.bubble-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 3px;
    font-size: 10.5px;
    color: #667781;
    margin-top: 1px;
    white-space: nowrap;
}

.bubble-tick {
    color: #53bdeb;
    font-size: 11px;
    letter-spacing: -2px;
}

/* Bubble entrance animation */
@keyframes bubble-pop {
    from { transform: scale(0.92); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

.chat-row.bubble-in .chat-bubble {
    animation: bubble-pop 0.15s ease-out forwards;
}

/* Reply area */
.inbox-reply-area {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 10px 16px 12px;
    background: #f0f2f5;
    border-top: 1px solid #d9dbdf;
    flex-shrink: 0;
}

.inbox-reply-input {
    flex: 1;
    resize: none;
    min-height: 40px;
    max-height: 120px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.5;
    border-radius: 20px;
    padding: 9px 16px;
    border: 1px solid transparent;
    background: #fff;
    outline: none;
    font-family: var(--font);
    color: var(--text-primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: box-shadow 0.15s;
}

.inbox-reply-input:focus {
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.inbox-reply-input::placeholder { color: #aaa; }

.inbox-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
}

.inbox-send-btn:hover   { background: var(--primary-dark); }
.inbox-send-btn:active  { transform: scale(0.93); }
.inbox-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Spinner */
.inbox-spinner {
    width: 22px;
    height: 22px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 680px) {
    .inbox-sidebar { width: 260px; }
}

@media (max-width: 520px) {
    .inbox-layout,
    .page-inbox .inbox-layout {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - var(--topbar-height));
        border-radius: 0;
        border: none;
    }
    .inbox-sidebar {
        width: 100%;
        height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .inbox-chat { height: 60vh; }
}

/* ============================================================
   NOTIFICATION BELL
   Dropdown memakai position:fixed via JS untuk escape stacking
   context topbar. HTML menggunakan inline styles agar bulletproof.
   ============================================================ */

/* Tombol bell hover */
#notif-btn:hover { background: #f3f4f6 !important; }

/* Dropdown — animasi masuk */
#notif-dropdown[style*="block"] {
    animation: notifFadeDown 0.15s ease;
}

@keyframes notifFadeDown {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Mobile: dropdown full width */
@media (max-width: 480px) {
    #notif-dropdown {
        width: calc(100vw - 16px) !important;
        right: 8px !important;
    }
}

/* ============================================================
   DASHBOARD SPECIFIC
   ============================================================ */

/* Chart + sidebar mini-cards grid */
.dashboard-chart-grid {
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 20px;
    margin-bottom: 24px;
}

/* ============================================================
   MOBILE RESPONSIVE IMPROVEMENTS
   ============================================================ */

@media (max-width: 768px) {
    /* Dashboard chart grid stacks on mobile */
    .dashboard-chart-grid {
        grid-template-columns: 1fr !important;
    }

    /* page-header action buttons wrap gracefully */
    .page-header {
        gap: 12px;
    }

    .page-header .flex {
        flex-wrap: wrap;
    }

    /* max-width containers become full width */
    [style*="max-width: 860px"],
    [style*="max-width:860px"] {
        max-width: 100% !important;
    }

    /* Topbar title truncates on small screen */
    .topbar-title {
        font-size: 14px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 150px;
    }

    /* stat-card smaller on mobile */
    .stat-value { font-size: 22px; }

    /* table action buttons stack */
    .table td[style*="white-space:nowrap"],
    .table td[style*="white-space: nowrap"] {
        white-space: normal !important;
    }
}

@media (max-width: 480px) {
    /* Topbar title even shorter */
    .topbar-title {
        max-width: 100px;
    }

    /* Hide setting btn on topbar (still accessible via sidebar) */
    .topbar-actions .topbar-btn:first-of-type {
        display: none;
    }
}
