* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    font-family: Arial, sans-serif;
    background: #f4f6f8;
    color: #1e293b;
}

body {
    min-height: 100vh;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

#topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 15px 20px;
    background: #0f172a;
    color: white;
}

#topbar h1 {
    margin: 0;
    font-size: 22px;
}

#controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

#controls input,
#controls select,
#controls button,
#formGrid input,
#formGrid textarea,
#formActions button,
#modalTop button,
td button {
    font: inherit;
}

#controls input,
#controls select,
#controls button {
    height: 34px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    padding: 0 10px;
    font-size: 14px;
}

#controls input,
#controls select {
    background: white;
    color: #1e293b;
}

#controls button {
    background: #2563eb;
    color: white;
    border: none;
    cursor: pointer;
}

#controls button:hover {
    background: #1d4ed8;
}

#metrics {
    display: flex;
    gap: 15px;
    padding: 15px 20px;
}

.metric {
    background: white;
    padding: 12px 18px;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    min-width: 120px;
}

.metric span {
    display: block;
    color: #64748b;
    font-size: 12px;
    margin-bottom: 4px;
}

.metric strong {
    font-size: 20px;
}

#tableWrap {
    flex: 1;
    padding: 0 20px 20px;
    overflow: auto;
}

#clientTable {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
}

#clientTable thead {
    background: #f1f5f9;
    position: sticky;
    top: 0;
    z-index: 1;
}

#clientTable th {
    text-align: left;
    font-size: 14px;
    padding: 10px;
    color: #334155;
    white-space: nowrap;
}

#clientTable td {
    padding: 10px;
    font-size: 14px;
    color: #1e293b;
    border-top: 1px solid #e2e8f0;
    vertical-align: top;
}

#clientTable tbody tr:hover {
    background: #f8fafc;
}

.tableMessage {
    text-align: center;
    color: #64748b;
    padding: 24px !important;
}

/* FIX DETAIL ROW COMPLETELY */
.detailRow td {
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
}

/* CARD CONTAINER */
.detailCard {
    margin: 12px 20px;
    padding: 16px;
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

/* TOP ROW (COMPANY + PHONE) */
.detailRowTop {
    display: flex;
    gap: 60px;
    margin-bottom: 16px;
}

/* LABEL */
.detailField span {
    display: block;
    font-size: 11px;
    color: #64748b;
    text-transform: uppercase;
    margin-bottom: 4px;
}

/* VALUE */
.detailField strong {
    font-size: 15px;
    color: #0f172a;
}

/* NOTES */
.detailNotes span {
    font-size: 11px;
    color: #64748b;
    text-transform: uppercase;
}

.detailNotes p {
    margin-top: 6px;
    font-size: 14px;
    line-height: 1.5;
    color: #1e293b;
}

/* REMOVE HOVER EFFECT FROM DETAIL ROW */
.detailRow:hover {
    background: transparent !important;
}

.statusActive {
    color: #16a34a;
    font-weight: bold;
}

.statusSoon {
    color: #ea580c;
    font-weight: bold;
}

.statusOverdue {
    color: #dc2626;
    font-weight: bold;
}

td button {
    background: #e2e8f0;
    border: none;
    padding: 5px 8px;
    border-radius: 5px;
    cursor: pointer;
    margin-right: 6px;
}

td button:hover {
    background: #cbd5f5;
}

#formModal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

#modalBackdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

#modalBox {
    position: relative;
    z-index: 1000;
    width: 420px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 32px);
    overflow: auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    padding: 20px;
}

#modalTop {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

#modalTop h2 {
    margin: 0;
}

#closeModalBtn {
    background: #e5e7eb;
    color: #111827;
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
}

#formGrid {
    display: grid;
    gap: 10px;
}

#formGrid input,
#formGrid textarea {
    width: 100%;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background: white;
}

#formGrid textarea {
    min-height: 120px;
    resize: vertical;
}

#formActions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

#saveBtn {
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    cursor: pointer;
}

#cancelBtn {
    background: #e5e7eb;
    color: #111827;
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    cursor: pointer;
}

/* PROFILE PANEL (FIX) */
#profilePanel {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* BACKDROP */
#profileBackdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
}

/* PROFILE BOX */
#profileBox {
    position: relative;
    z-index: 10000;
    width: 600px;
    max-width: 90%;
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.3);
}

/* HEADER */
#profileTop {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

#profileTop h2 {
    margin: 0;
}

/* CONTENT */
#profileBody {
    display: grid;
    gap: 10px;
}

/* ACTION BUTTONS */
#profileActions {
    margin-top: 15px;
    display: flex;
    gap: 10px;
}

#profileActions button {
    background: #2563eb;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
}

#profileActions button:hover {
    background: #1d4ed8;
}

/* mobile */

@media (max-width: 768px) {

    html, body {
        overflow: auto;
    }

    #app {
        height: auto;
    }

    /* TOP BAR STACK */
    #topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    #controls {
        width: 100%;
        flex-wrap: wrap;
    }

    #controls input,
    #controls select,
    #controls button {
        flex: 1 1 48%;
    }

    /* METRICS STACK */
    #metrics {
        flex-direction: column;
    }

    .metric {
        width: 100%;
    }

    /* TABLE SCROLL */
    #tableWrap {
        overflow-x: auto;
    }

    table {
        min-width: 600px;
    }

    /* DETAIL CARD STACK */
    .detailRowTop {
        flex-direction: column;
        gap: 10px;
    }

    /* MODAL FULL SCREEN */
    #modalBox {
        width: 95%;
        height: auto;
        max-height: 90vh;
    }

    /* PROFILE FULL SCREEN */
    #profileBox {
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* PROFILE GRID STACK */
    .profileGrid {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    /* BUTTON STACK */
    #profileActions {
        flex-direction: column;
    }

    #profileActions button {
        width: 100%;
    }
}