/* ==========================================================================
   IQM Frontend Dashboard - Fully Responsive CSS (Optimized)
   ========================================================================== */

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

body {
    background: #f1f5f9;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    padding: 0 8px;
}

/* Main App Wrapper */
.iqm-fe-app-container {
    max-width: 1400px;
    margin: 20px auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #1e293b;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
    overflow: hidden;
}

/* ── Authentication Section ────────────────────────────────────── */
.iqm-fe-auth-box {
    max-width: 440px;
    width: 100%;
    margin: 40px auto;
    padding: 28px 20px;
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05);
}

.iqm-fe-auth-header {
    text-align: center;
    margin-bottom: 20px;
}

.iqm-fe-auth-header h2 {
    font-size: 22px;
    color: #0f172a;
    margin: 0;
}

.iqm-fe-auth-tabs {
    display: flex;
    border-bottom: 2px solid #f1f5f9;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 2px;
}

.iqm-fe-tab-btn {
    flex: 1 1 auto;
    padding: 10px 6px;
    border: none;
    background: none;
    cursor: pointer;
    font-weight: 600;
    color: #64748b;
    font-size: 14px;
    transition: color 0.2s ease;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    text-align: center;
}

.iqm-fe-tab-btn.active {
    color: #2563eb;
    border-bottom: 2px solid #2563eb;
}

.iqm-fe-auth-form {
    display: none;
}

.iqm-fe-auth-form.active {
    display: block;
}

/* ── Layout Grid ───────────────────────────────────────────────── */
.iqm-fe-layout {
    display: flex;
    min-height: 700px;
    width: 100%;
}

/* Sidebar (desktop) */
.iqm-fe-sidebar {
    width: 260px;
    background: #0f172a;
    color: #ffffff;
    padding: 24px 16px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.iqm-fe-brand {
    padding: 0 12px 24px;
    border-bottom: 1px solid #1e293b;
    margin-bottom: 16px;
}

.iqm-fe-brand h3 {
    margin: 0;
    font-size: 18px;
    color: #ffffff;
}

.iqm-fe-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.iqm-fe-nav a {
    padding: 12px 16px;
    text-decoration: none;
    color: #94a3b8;
    font-weight: 500;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.iqm-fe-nav a:hover {
    background: #1e293b;
    color: #f8fafc;
}

.iqm-fe-nav a.active {
    background: #2563eb;
    color: #ffffff;
    font-weight: 600;
}

/* Main Content */
.iqm-fe-main {
    flex: 1;
    padding: 28px 24px;
    background: #f8fafc;
    min-width: 0;
}

.iqm-fe-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
}

.iqm-fe-header h2 {
    margin: 0;
    font-size: 22px;
    color: #0f172a;
}

/* Overview cards */
.iqm-fe-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.iqm-fe-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    padding: 18px 16px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.iqm-fe-card.highlight {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.iqm-fe-card .title {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 6px;
    font-weight: 500;
}

.iqm-fe-card .value {
    font-size: 24px;
    font-weight: 700;
    color: #0f172a;
}

/* Tables */
.iqm-fe-table-header {
    margin-bottom: 16px;
}

.iqm-fe-search-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.iqm-fe-search-form input,
.iqm-fe-search-form select {
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    font-size: 14px;
    min-width: 140px;
    flex: 1 1 auto;
}

.iqm-fe-table-responsive {
    width: 100%;
    overflow-x: auto;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    margin-bottom: 20px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.iqm-fe-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

.iqm-fe-table th,
.iqm-fe-table td {
    padding: 12px 14px;
    border-bottom: 1px solid #f1f5f9;
    text-align: left;
    font-size: 14px;
    vertical-align: middle;
}

.iqm-fe-table th {
    background: #f1f5f9;
    font-weight: 600;
    color: #475569;
    white-space: nowrap;
}

/* Line items table (fixed columns) */
#iqm-line-items-table {
    width: 100%;
    table-layout: fixed;
}

#iqm-line-items-table th:nth-child(1) {
    width: 22%;
}

#iqm-line-items-table th:nth-child(2) {
    width: 22%;
}

#iqm-line-items-table th:nth-child(3) {
    width: 8%;
}

#iqm-line-items-table th:nth-child(4) {
    width: 12%;
}

#iqm-line-items-table th:nth-child(5) {
    width: 12%;
}

#iqm-line-items-table th:nth-child(6) {
    width: 12%;
}

#iqm-line-items-table th:nth-child(7) {
    width: 8%;
}

.iqm-line-item-row input {
    width: 100%;
    padding: 8px 6px;
    font-size: 14px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    min-width: 50px;
}

.iqm-remove-row {
    background: #fee2e2;
    color: #dc2626;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

/* Status badges */
.iqm-fe-status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: capitalize;
}

.iqm-fe-status.paid {
    background: #dcfce7;
    color: #15803d;
}

.iqm-fe-status.draft {
    background: #f1f5f9;
    color: #475569;
}

.iqm-fe-status.overdue {
    background: #fee2e2;
    color: #b91c1c;
}

/* Forms */
.iqm-fe-form-grid {
    display: grid;
    grid-template-columns:1fr 2.2fr;
    gap: 24px;
}

.iqm-fe-form-col h3 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 16px;
    color: #0f172a;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 8px;
}

.iqm-fe-field {
    margin-bottom: 16px;
}

.iqm-fe-field label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 13px;
    color: #334155;
}

.iqm-fe-field input,
.iqm-fe-field textarea,
.iqm-fe-field select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    box-sizing: border-box;
}

.iqm-fe-field textarea {
    resize: vertical;
    min-height: 80px;
}

/* Totals summary */
.iqm-fe-totals {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    padding: 16px;
    border-radius: 8px;
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end;
}

.iqm-fe-totals div {
    display: flex;
    justify-content: space-between;
    width: 260px;
    font-size: 14px;
}

/* Buttons */
.iqm-fe-btn {
    padding: 12px 20px;
    border: none;
    background: #0f172a;
    color: #ffffff;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    min-height: 42px;
    gap: 6px;
}

.iqm-fe-btn:hover {
    background: #1e293b;
    color: #fff;
}

.iqm-fe-btn-primary {
    background: #2563eb;
}

.iqm-fe-btn-primary:hover {
    background: #1d4ed8;
}

.iqm-fe-btn-secondary {
    background: #64748b;
}

.iqm-fe-btn-outline {
    background: transparent;
    border: 1px solid #cbd5e1;
    color: #334155;
}

.iqm-fe-btn-outline:hover {
    background: #f1f5f9;
}

.iqm-fe-btn-full {
    width: 100%;
    text-align: center;
}

.iqm-btn-link {
    color: #2563eb;
    text-decoration: none;
    margin-right: 8px;
    font-weight: 500;
}

.iqm-btn-danger {
    color: #dc2626;
    text-decoration: none;
    font-weight: 500;
}

.iqm-fe-alert {
    padding: 14px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 14px;
}

.iqm-fe-alert-success {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.iqm-fe-alert-danger {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* ── Utilities ──────────────────────────────────────────────────── */
.iqm-fe-user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.iqm-fe-logout {
    margin-left: auto;
}

.iqm-fe-field-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 0;
}

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

/* ── Tablet & Small Desktop (max-width: 1024px) ──────────────── */
@media screen and (max-width: 1024px) {
    .iqm-fe-app-container {
        margin: 10px auto;
        border-radius: 10px;
    }

    .iqm-fe-sidebar {
        width: 220px;
        padding: 20px 14px;
    }

    .iqm-fe-main {
        padding: 24px 20px;
    }

    .iqm-fe-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 14px;
    }

    .iqm-fe-form-grid {
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }
}

/* ── Tablet Portrait (max-width: 768px) ───────────────────────── */
@media screen and (max-width: 768px) {
    body {
        padding: 0 4px;
    }

    .iqm-fe-app-container {
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        width: 100%;
    }

    .iqm-fe-layout {
        flex-direction: column;
        min-height: auto;
    }

    /* Sidebar becomes horizontal navigation */
    .iqm-fe-sidebar {
        width: 100%;
        padding: 10px 12px;
        flex-direction: column;
        align-items: stretch;
        position: sticky;
        top: 0;
        z-index: 100;
        background: #0f172a;
        border-radius: 0;
    }

    .iqm-fe-brand {
        padding: 4px 0 8px 0;
        border-bottom: none;
        margin-bottom: 0;
    }

    .iqm-fe-brand h3 {
        font-size: 16px;
    }

    .iqm-fe-nav {
        flex-direction: row;
        overflow-x: auto;
        white-space: nowrap;
		flex-wrap: wrap;
        padding: 4px 0;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 4px;
    }

    .iqm-fe-nav::-webkit-scrollbar {
        display: none;
    }

    .iqm-fe-nav a {
        flex-shrink: 0;
        padding: 8px 12px;
        font-size: 13px;
        border-radius: 6px;
        white-space: nowrap;
        gap: 6px;
    }

    .iqm-fe-nav a i {
        font-size: 14px;
    }

    .iqm-fe-main {
        padding: 16px 14px;
        width: 100%;
        background: #f8fafc;
    }

    .iqm-fe-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 20px;
    }

    .iqm-fe-header h2 {
        font-size: 20px;
    }

    .iqm-fe-logout {
        margin-left: 0;
        width: 100%;
    }

    .iqm-fe-logout .iqm-fe-btn {
        width: 100%;
        justify-content: center;
    }

    /* Cards - 2 columns on tablet */
    .iqm-fe-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .iqm-fe-card {
        padding: 14px 12px;
    }

    .iqm-fe-card .value {
        font-size: 20px;
    }

    /* Forms become single column */
    .iqm-fe-form-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .iqm-fe-totals div {
        width: 100%;
    }

    /* Table adjustments */
    .iqm-fe-table-responsive {
        border-radius: 6px;
    }

    .iqm-fe-table th,
    .iqm-fe-table td {
        padding: 10px 12px;
        font-size: 13px;
    }

    .iqm-fe-table td.iqm-fe-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 4px 8px;
        align-items: center;
    }

    /* Search form */
    .iqm-fe-search-form {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
    }

    .iqm-fe-search-form input,
    .iqm-fe-search-form select {
        min-width: 120px;
        flex: 1 1 calc(50% - 6px);
        padding: 8px 10px;
        font-size: 13px;
    }

    .iqm-fe-search-form button {
        flex: 1 1 100%;
        min-height: 38px;
        padding: 8px 16px;
    }

    /* Auth box */
    .iqm-fe-auth-box {
        margin: 20px auto;
        padding: 20px 16px;
        width: 100%;
        border-radius: 8px;
    }

    .iqm-fe-auth-header h2 {
        font-size: 20px;
    }

    .iqm-fe-tab-btn {
        font-size: 13px;
        padding: 8px 4px;
    }
}

/* ── Mobile (max-width: 480px) ────────────────────────────────── */
@media screen and (max-width: 480px) {
    body {
        padding: 0 2px;
    }
	
		#iqm-line-items-table thead {
    display: block !important;
    max-width: 100px;
    position: absolute;
    left: 20px;
}
	

    .iqm-fe-app-container {
        margin: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .iqm-fe-sidebar {
        padding: 8px 10px;
    }

    .iqm-fe-brand h3 {
        font-size: 14px;
    }

    .iqm-fe-nav a {
        padding: 6px 10px;
        font-size: 12px;
        gap: 4px;
    }

    .iqm-fe-nav a i {
        font-size: 12px;
    }

    .iqm-fe-main {
        padding: 12px 10px;
    }

    .iqm-fe-header h2 {
        font-size: 18px;
    }

    .iqm-fe-header .iqm-fe-btn {
        font-size: 13px;
        padding: 8px 14px;
        min-height: 36px;
    }

    /* Cards - 2 columns on small mobile */
    .iqm-fe-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        margin-bottom: 16px;
    }

    .iqm-fe-card {
        padding: 10px 8px;
        border-radius: 6px;
    }

    .iqm-fe-card .title {
        font-size: 11px;
        margin-bottom: 4px;
    }

    .iqm-fe-card .value {
        font-size: 16px;
    }

    /* Search form - full width */
    .iqm-fe-search-form {
        flex-direction: column;
        width: 100%;
        gap: 6px;
    }

    .iqm-fe-search-form input,
    .iqm-fe-search-form select {
        width: 100%;
        min-width: unset;
        flex: none;
        font-size: 14px;
        padding: 8px 10px;
    }

    .iqm-fe-search-form button {
        width: 100%;
        flex: none;
        min-height: 38px;
        font-size: 13px;
    }

    /* Table - card style on mobile */
    .iqm-fe-table-responsive {
        border-radius: 4px;
        border: none;
        background: transparent;
    }

    .iqm-fe-table,
    .iqm-fe-table thead,
    .iqm-fe-table tbody,
    .iqm-fe-table th,
    .iqm-fe-table td,
    .iqm-fe-table tr {
        display: block;
        width: 100% !important;
    }

    .iqm-fe-table thead {
        display: none;
    }

    .iqm-fe-table tr {
        background: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 6px;
        margin-bottom: 10px;
        padding: 10px 12px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    }

    .iqm-fe-table td {
        padding: 4px 0;
        border-bottom: none;
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        font-size: 13px;
    }

    .iqm-fe-table td:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }

    .iqm-fe-table td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 11px;
        color: #64748b;
        margin-right: 10px;
        flex: 0 0 80px;
    }

    .iqm-fe-table td.iqm-fe-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 4px 8px;
        justify-content: flex-start;
        padding-top: 6px;
        margin-top: 4px;
        border-top: 1px solid #f1f5f9;
    }

    .iqm-fe-table td.iqm-fe-actions::before {
        content: attr(data-label);
        flex: 0 0 80px;
        font-weight: 600;
        font-size: 11px;
        color: #64748b;
    }

    .iqm-fe-table td .iqm-btn-link,
    .iqm-fe-table td .iqm-btn-danger {
        font-size: 12px;
        padding: 4px 6px;
    }

    /* Line items - card style on mobile */
    #iqm-line-items-table,
    #iqm-line-items-table thead,
    #iqm-line-items-table tbody,
    #iqm-line-items-table th,
    #iqm-line-items-table td,
    #iqm-line-items-table tr {
        display: block;
        width: 100% !important;
    }

  

    #iqm-line-items-table tr {
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 6px;
        margin-bottom: 10px;
        padding: 10px 12px;
    }

    #iqm-line-items-table td {
        padding: 4px 0;
        border-bottom: none;
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    #iqm-line-items-table td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 11px;
        color: #64748b;
        margin-right: 8px;
        flex: 0 0 70px;
    }

    #iqm-line-items-table td input {
        flex: 1;
        min-width: 80px;
        padding: 6px 8px;
        font-size: 14px;
    }

    #iqm-line-items-table td:last-child {
        justify-content: flex-end;
        padding-top: 6px;
        margin-top: 4px;
        border-top: 1px solid #f1f5f9;
    }

    #iqm-line-items-table td:last-child::before {
        content: none;
    }

    .iqm-remove-row {
        width: 30px;
        height: 30px;
        font-size: 14px;
    }

    /* Forms */
    .iqm-fe-field input,
    .iqm-fe-field textarea,
    .iqm-fe-field select {
        font-size: 16px;
        /* Prevent iOS zoom */
        padding: 10px 12px;
    }

    .iqm-fe-field label {
        font-size: 12px;
    }

    /* Buttons - full width on mobile */
    .iqm-fe-btn {
        min-height: 44px;
        padding: 10px 16px;
        width: 100%;
        font-size: 14px;
    }

    .iqm-fe-btn-full {
        width: 100%;
    }

    .iqm-fe-btn-outline {
        width: 100%;
    }

    /* Totals */
    .iqm-fe-totals {
        padding: 12px;
        align-items: stretch;
    }

    .iqm-fe-totals div {
        width: 100%;
        font-size: 13px;
        padding: 4px 0;
    }

    /* Auth */
    .iqm-fe-auth-box {
        margin: 12px auto;
        padding: 16px 12px;
        border-radius: 6px;
    }

    .iqm-fe-auth-header h2 {
        font-size: 18px;
    }

    .iqm-fe-auth-tabs {
        gap: 0;
        margin-bottom: 16px;
    }

    .iqm-fe-tab-btn {
        font-size: 12px;
        padding: 6px 4px;
    }
}



/* ── Extra Small (max-width: 360px) ───────────────────────────── */
@media screen and (max-width: 360px) {
    .iqm-fe-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    .iqm-fe-card {
        padding: 8px 6px;
    }

    .iqm-fe-card .title {
        font-size: 10px;
    }

    .iqm-fe-card .value {
        font-size: 14px;
    }

    .iqm-fe-nav a {
        padding: 4px 8px;
        font-size: 11px;
        gap: 3px;
    }

    .iqm-fe-nav a i {
        font-size: 10px;
    }

    .iqm-fe-main {
        padding: 8px 6px;
    }

    .iqm-fe-table td {
        font-size: 12px;
        padding: 3px 0;
    }

    .iqm-fe-table td::before {
        font-size: 10px;
        flex: 0 0 60px;
    }

    #iqm-line-items-table td::before {
        font-size: 10px;
        flex: 0 0 60px;
    }

    #iqm-line-items-table td input {
        font-size: 13px;
        min-width: 60px;
        padding: 4px 6px;
    }
}