/* =========================================
   LAYLINK PRO - DASHBOARD CSS
   Extends style.css design system
   ========================================= */

/* Dashboard: override body padding */
body.dash-body {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

.dash-layout {
    display: flex;
    min-height: 100vh;
}

/* === SIDEBAR === */
.dash-sidebar {
    width: 240px;
    background: var(--slate-900, #0F172A);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.dash-sidebar.closed {
    transform: translateX(-100%);
}



.dash-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
}

.dash-brand img {
    width: 26px;
    height: 26px;
}

.dash-brand-text {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: #fff;
}

.dash-brand-text .pro {
    color: var(--primary);
}

.dash-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    margin-left: 6px;
    background: rgba(34, 197, 94, 0.12);
    color: #4ade80;
}

/* Sidebar Nav */
.dash-nav {
    padding: 10px 8px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dash-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-btn);
    color: #94a3b8;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.dash-nav-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #e2e8f0;
}

.dash-nav-item.active {
    background: var(--primary);
    color: white;
    font-weight: 600;
}

body.dark .dash-nav-item.active {
    color: #121218;
}

.dash-nav-item i {
    width: 18px;
    text-align: center;
    font-size: 13px;
}

/* Sidebar Footer */
.dash-sidebar-foot {
    padding: 10px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.dash-page-link {
    display: block;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 6px;
    margin-bottom: 8px;
}

.dash-page-link-label {
    font-size: 10px;
    color: #64748b;
    margin-bottom: 2px;
}

.dash-page-link a {
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    word-break: break-all;
}

.dash-page-link a:hover {
    text-decoration: underline;
}

.dash-user-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 4px;
}

.dash-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #475569;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #e2e8f0;
    flex-shrink: 0;
}

.dash-user-meta {
    flex: 1;
    min-width: 0;
}

.dash-user-meta .name {
    font-size: 12px;
    font-weight: 600;
    color: #e2e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dash-user-meta .email {
    font-size: 10px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dash-logout {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    margin-top: 6px;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    width: 100%;
    font-family: inherit;
}

.dash-logout:hover {
    background: rgba(239, 68, 68, 0.08);
    color: #f87171;
}

/* === MAIN CONTENT === */
.dash-main {
    flex: 1;
    margin-left: 240px;
    background: var(--bg-page);
    min-height: 100vh;
    transition: margin-left 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.dash-main.expanded {
    margin-left: 0;
}

.dash-content {
    max-width: 860px;
    margin: 0 auto;
    padding: 24px 20px;
}

.dash-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.02em;
}

.dash-subtitle {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-bottom: 20px;
}

/* Stats */
.dash-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.dash-stat {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-card);
    padding: 16px;
    box-shadow: var(--shadow-card);
    display: flex;
    align-items: center;
    gap: 12px;
}

.dash-stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.dash-stat-icon.i-link {
    background: rgba(99, 102, 241, 0.08);
    color: #6366f1;
}

.dash-stat-icon.i-today {
    background: rgba(34, 197, 94, 0.08);
    color: #22c55e;
}

.dash-stat-icon.i-plan {
    background: rgba(249, 115, 22, 0.08);
    color: #f97316;
}

.dash-stat .label {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-bottom: 2px;
    text-transform: none;
    letter-spacing: 0;
}

.dash-stat .value {
    font-size: 20px;
    font-weight: 700;
}

/* Section Card — reuse .card from style.css */
.dash-card {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius-card);
    padding: 20px;
    box-shadow: var(--shadow-card);
    margin-bottom: 16px;
}

.dash-card h3 {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 14px;
}

/* Form groups */
.dash-fg {
    margin-bottom: 14px;
}

.dash-fg label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.dash-fg input[type="text"],
.dash-fg input[type="email"],
.dash-fg input[type="tel"],
.dash-fg textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-input);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.dash-fg input:focus,
.dash-fg textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.dash-fg input[readonly] {
    opacity: 0.5;
    cursor: not-allowed;
}

.dash-fg .hint {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 3px;
}

.dash-fg textarea {
    min-height: 72px;
    resize: vertical;
}

/* Alert inline */
.dash-alert {
    padding: 9px 12px;
    border-radius: var(--radius-input);
    font-size: 13px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dash-alert.warn {
    background: rgba(249, 115, 22, 0.08);
    color: #ea580c;
    border: 1px solid rgba(249, 115, 22, 0.12);
}

body.dark .dash-alert.warn {
    background: rgba(251, 191, 36, 0.08);
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.12);
}

.dash-alert.info {
    background: rgba(99, 102, 241, 0.06);
    color: #4f46e5;
    border: 1px solid rgba(99, 102, 241, 0.10);
}

body.dark .dash-alert.info {
    background: rgba(165, 180, 252, 0.08);
    color: #a5b4fc;
    border-color: rgba(165, 180, 252, 0.12);
}

.dash-alert.ok {
    background: rgba(34, 197, 94, 0.06);
    color: #16a34a;
    border: 1px solid rgba(34, 197, 94, 0.10);
}

body.dark .dash-alert.ok {
    background: rgba(74, 222, 128, 0.08);
    color: #4ade80;
    border-color: rgba(74, 222, 128, 0.12);
}

/* Link history */
.dash-link-row {
    padding: 12px 0;
    border-bottom: 1px solid var(--divider);
    animation: slideUp 0.3s ease both;
}

.dash-link-row:last-child {
    border-bottom: none;
}

.dash-link-orig {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.dash-link-aff {
    font-size: 13px;
    color: var(--primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.dash-link-aff:hover {
    text-decoration: underline;
}

.dash-link-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}

.dash-link-date {
    font-size: 10px;
    color: var(--text-tertiary);
}

.dash-link-actions {
    display: flex;
    gap: 2px;
}

.dash-link-actions button {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.15s;
}

.dash-link-actions button:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.dash-link-actions .del:hover {
    background: rgba(239, 68, 68, 0.08);
    color: #ef4444;
}

/* Create link input */
.dash-create-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.dash-create-row input {
    flex: 1;
    padding: 10px 12px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-input);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    box-sizing: border-box;
}

.dash-create-row input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Empty state */
.dash-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-tertiary);
    font-size: 13px;
}

/* Section toggle */
.dash-section {
    display: none;
}

.dash-section.active {
    display: block;
}

/* Toast */
.dash-toast {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(-60px);
    background: var(--text-primary);
    color: var(--bg-card);
    padding: 8px 18px;
    border-radius: 100px;
    font-size: 13px;
    font-weight: 600;
    z-index: 9999;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    white-space: nowrap;
}

.dash-toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ============================================
   MOBILE TOP BAR (visible only on mobile)
   ============================================ */
.dash-mobile-topbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    height: 52px;
    background: var(--bg-header, #fff);
    border-bottom: 1px solid var(--border-card);
    align-items: center;
    padding: 0 12px;
    gap: 10px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
}

.dash-mobile-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.dash-mobile-brand img {
    width: 24px;
    height: 24px;
}

.dash-mobile-brand .pro {
    color: var(--primary);
}

.dash-mobile-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-btn);
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.dash-mobile-btn:active {
    background: var(--primary-light);
    color: var(--primary);
}

.dash-mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 99;
    backdrop-filter: blur(4px);
}

/* ============================================
   DESKTOP SIDEBAR COLLAPSE BUTTON
   ============================================ */
.dash-sidebar-header {
    height: var(--header-height);
    padding: 0 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dash-collapse-btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: #94a3b8;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}

.dash-collapse-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
}

.dash-sidebar.closed .dash-collapse-btn i {
    transform: rotate(180deg);
}

/* ============================================
   MOBILE RESPONSIVE (≤768px)
   ============================================ */
@media (max-width: 768px) {
    .dash-mobile-topbar {
        display: flex;
    }

    .dash-sidebar {
        transform: translateX(-100%);
        width: 280px;
    }

    .dash-sidebar.open {
        transform: translateX(0);
    }

    .dash-sidebar.closed {
        transform: translateX(-100%);
    }

    .dash-collapse-btn {
        display: none;
    }

    .dash-main {
        margin-left: 0 !important;
    }

    .dash-content {
        padding: 64px 14px 24px;
    }

    .dash-mobile-overlay.open {
        display: block;
    }

    /* Stats: stack to 1 column on small phones */
    .dash-stats {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .dash-stat {
        padding: 14px;
    }

    /* Cards: smaller padding */
    .dash-card {
        padding: 16px;
    }

    /* Form inputs: larger touch targets */
    .dash-fg input[type="text"],
    .dash-fg input[type="email"],
    .dash-fg input[type="tel"],
    .dash-fg textarea {
        padding: 12px;
        font-size: 16px;
        /* Prevent iOS zoom on focus */
    }

    /* Buttons: larger touch targets */
    .btn {
        padding: 12px 18px;
        font-size: 14px;
    }

    /* Title sizes */
    .dash-title {
        font-size: 18px;
    }

    /* History link rows */
    .dash-link-row {
        padding: 14px 0;
    }

    .dash-link-actions button {
        width: 34px;
        height: 34px;
        font-size: 14px;
    }

    /* Create link row: stack on very small screens */
    .dash-create-row input {
        padding: 12px;
        font-size: 16px;
    }

    /* Toast: move below mobile topbar */
    .dash-toast {
        top: 58px;
    }

    /* Admin table: improve readability */
    #sec-admin .dash-stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    #sec-admin .dash-stat .value {
        font-size: 16px;
    }

    /* Sidebar mobile footer */
    .dash-sidebar-foot {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
}

/* Very small phones (≤400px) */
@media (max-width: 400px) {
    .dash-content {
        padding: 60px 10px 20px;
    }

    .dash-create-row {
        flex-direction: column;
    }

    .dash-create-row input,
    .dash-create-row .btn {
        width: 100%;
    }

    #sec-admin .dash-stats {
        grid-template-columns: 1fr;
    }
}