/* ==========================================================================
   Click-to-Dial CRM — Mobile-first stylesheet
   Target: 390px (iPhone standard) and up. No heavy frameworks.
   ========================================================================== */

/* ----- CSS Custom Properties (Design Tokens) ----- */
:root {
    --color-primary: #1a73e8;
    --color-primary-dark: #1557b0;
    --color-primary-light: #e8f0fe;
    --color-bg: #f8f9fa;
    --color-white: #ffffff;
    --color-text: #202124;
    --color-text-secondary: #5f6368;
    --color-border: #dadce0;
    --color-success: #1e8e3e;
    --color-success-bg: #e6f4ea;
    --color-error: #d93025;
    --color-error-bg: #fce8e6;
    --color-warning: #f9ab00;
    --color-warning-bg: #fef7e0;
    --color-info: #1a73e8;
    --color-info-bg: #e8f0fe;
    --bar-height: 56px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12);
    --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.15);
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
}

/* ----- Reset & Base ----- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%; /* prevent iOS text inflation */
}

body {
    font-family: var(--font-stack);
    font-size: 15px;
    line-height: 1.5;
    color: var(--color-text);
    background-color: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior-y: contain;
}

/* iOS form normalization */
input,
select,
textarea,
button {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    font-family: inherit;
    font-size: inherit;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

img {
    max-width: 100%;
    display: block;
}

/* ==========================================================================
   TOP BAR — fixed, 56px, white with bottom shadow
   ========================================================================== */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--bar-height);
    background: var(--color-white);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
}

.top-bar__left {
    display: flex;
    align-items: center;
    min-width: 0; /* allow text truncation */
}

.top-bar__campaign {
    font-weight: 600;
    font-size: 16px;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.top-bar__right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.top-bar__user {
    font-size: 13px;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.top-bar__logout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--color-text-secondary);
    transition: background 0.2s;
}

.top-bar__logout:hover,
.top-bar__logout:active {
    background: var(--color-bg);
    color: var(--color-error);
}

/* ==========================================================================
   BOTTOM NAVIGATION — fixed, 56px, equal-width items
   ========================================================================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bar-height);
    background: var(--color-white);
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.1);
    display: flex;
    z-index: 1000;
    /* safe area inset for notched phones */
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--color-text-secondary);
    font-size: 11px;
    text-decoration: none;
    transition: color 0.2s;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav__item:active {
    background: var(--color-bg);
}

.bottom-nav__icon {
    width: 22px;
    height: 22px;
}

/* Active state: blue icon + label + top indicator line */
.bottom-nav__item--active {
    color: var(--color-primary);
}

.bottom-nav__item--active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 3px;
    background: var(--color-primary);
    border-radius: 0 0 3px 3px;
}

/* ==========================================================================
   MAIN CONTENT AREA — padded for fixed bars
   ========================================================================== */
.content {
    padding-top: calc(var(--bar-height) + 12px);
    padding-bottom: calc(var(--bar-height) + 12px);
    padding-left: 12px;
    padding-right: 12px;
    min-height: 100vh;
    /* 100dvh for modern browsers that support dynamic viewport */
    min-height: 100dvh;
}

/* ==========================================================================
   FLASH MESSAGES — fixed top, slide-down, auto-dismiss
   ========================================================================== */
.flash-container {
    position: fixed;
    top: var(--bar-height);
    left: 0;
    right: 0;
    z-index: 1100; /* above top bar shadow */
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 12px;
}

.flash {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    animation: flash-slide-down 0.3s ease-out;
    box-shadow: var(--shadow-md);
}

/* Category-based colors */
.flash--success {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.flash--error {
    background: var(--color-error-bg);
    color: var(--color-error);
}

.flash--warning {
    background: var(--color-warning-bg);
    color: #e37400;
}

.flash--info {
    background: var(--color-info-bg);
    color: var(--color-info);
}

/* Fallback for uncategorized messages */
.flash--message {
    background: var(--color-info-bg);
    color: var(--color-info);
}

.flash__text {
    flex: 1;
    margin-right: 8px;
}

.flash__close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    padding: 8px 12px;
    margin: -8px -12px -8px 0;
    line-height: 1;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.flash__close:hover {
    opacity: 1;
}

/* Fade-out class added by JS before removal */
.flash--fade-out {
    animation: flash-fade-out 0.4s ease-in forwards;
}

@keyframes flash-slide-down {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes flash-fade-out {
    to {
        opacity: 0;
        transform: translateY(-12px);
    }
}

/* ==========================================================================
   CARD COMPONENT
   ========================================================================== */
.card {
    background: var(--color-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 16px;
    margin-bottom: 12px;
}

.card__title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--color-text);
}

.card__subtitle {
    font-size: 13px;
    color: var(--color-text-secondary);
    margin-bottom: 12px;
}

/* ==========================================================================
   FORM ELEMENTS — touch-friendly sizing
   ========================================================================== */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    height: 48px; /* touch-friendly */
    padding: 0 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-white);
    color: var(--color-text);
    font-size: 15px;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.form-textarea {
    height: auto;
    min-height: 96px;
    padding: 12px 14px;
    resize: vertical;
}

.form-select {
    /* caret icon via CSS for select dropdown */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235f6368' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15);
}

.form-input::placeholder {
    color: var(--color-text-secondary);
    opacity: 0.7;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 48px;
    padding: 0 24px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
    gap: 8px;
}

.btn:active {
    transform: scale(0.97);
}

/* Full-width variant */
.btn--block {
    width: 100%;
}

/* Primary: solid blue */
.btn--primary {
    background: var(--color-primary);
    color: var(--color-white);
}

.btn--primary:hover {
    background: var(--color-primary-dark);
}

/* Secondary: outlined */
.btn--secondary {
    background: var(--color-white);
    color: var(--color-primary);
    border: 1px solid var(--color-border);
}

.btn--secondary:hover {
    background: var(--color-primary-light);
}

/* Danger: red for destructive actions */
.btn--danger {
    background: var(--color-error);
    color: var(--color-white);
}

.btn--danger:hover {
    background: #c5221f;
}

/* Success: green for positive actions */
.btn--success {
    background: var(--color-success);
    color: var(--color-white);
}

.btn--success:hover {
    background: #167b34;
}

/* Small button variant */
.btn--sm {
    height: 36px;
    padding: 0 16px;
    font-size: 13px;
}

/* Disabled state */
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* ==========================================================================
   TABLE — full width, horizontal scroll on mobile, sticky first column
   ========================================================================== */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    background: var(--color-white);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}

.table th,
.table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.table th {
    background: var(--color-bg);
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 1;
}

/* Sticky first column for horizontal scroll */
.table th:first-child,
.table td:first-child {
    position: sticky;
    left: 0;
    background: var(--color-white);
    z-index: 2;
}

.table th:first-child {
    background: var(--color-bg);
    z-index: 3; /* above both sticky row and column */
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover td {
    background: var(--color-primary-light);
}

/* ==========================================================================
   STAT CARDS GRID — 2 columns on mobile
   ========================================================================== */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--color-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 16px;
    text-align: center;
}

.stat-card__value {
    font-size: 28px;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1.2;
}

.stat-card__label {
    font-size: 12px;
    color: var(--color-text-secondary);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Full-width stat card spanning both columns */
.stat-card--wide {
    grid-column: 1 / -1;
}

/* ==========================================================================
   BADGES — status indicators, disposition colors
   ========================================================================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
}

/* Disposition / status badge colors */
.badge--sale,
.badge--success {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.badge--pending,
.badge--warning {
    background: var(--color-warning-bg);
    color: #e37400;
}

.badge--callback,
.badge--info {
    background: var(--color-info-bg);
    color: var(--color-info);
}

.badge--dnc,
.badge--error,
.badge--danger {
    background: var(--color-error-bg);
    color: var(--color-error);
}

.badge--neutral {
    background: #e8eaed;
    color: var(--color-text-secondary);
}

/* Pulsing dot for "pending sale" or "callback due" */
.badge--pulse::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    margin-right: 6px;
    animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ==========================================================================
   LOADING SPINNER
   ========================================================================== */
.spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner--sm {
    width: 18px;
    height: 18px;
    border-width: 2px;
}

.spinner--center {
    display: block;
    margin: 40px auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Full-page loading overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

/* ==========================================================================
   DISPOSITION COLORS — for call outcome indicators
   ========================================================================== */
.disposition--sale { color: var(--color-success); }
.disposition--callback { color: var(--color-primary); }
.disposition--not-interested { color: var(--color-text-secondary); }
.disposition--dnc { color: var(--color-error); }
.disposition--no-answer { color: var(--color-warning); }
.disposition--voicemail { color: #9334e6; }
.disposition--warm { color: #e8710a; }

/* ==========================================================================
   FOCUS STYLES — visible keyboard focus indicators for accessibility
   ========================================================================== */
.bottom-nav__item:focus-visible,
.btn:focus-visible,
.top-bar__logout:focus-visible,
.flash__close:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Remove default outline only when :focus-visible is supported */
.bottom-nav__item:focus:not(:focus-visible),
.btn:focus:not(:focus-visible),
.top-bar__logout:focus:not(:focus-visible),
.flash__close:focus:not(:focus-visible) {
    outline: none;
}

/* ==========================================================================
   UTILITY CLASSES
   ========================================================================== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--color-text-secondary); }
.text-success { color: var(--color-success); }
.text-error { color: var(--color-error); }
.text-warning { color: #e37400; }
.text-primary { color: var(--color-primary); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }

.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

.hidden { display: none !important; }

/* Truncate long text */
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================================================
   RESPONSIVE — minor adjustments for larger screens
   ========================================================================== */
@media (min-width: 768px) {
    .content {
        max-width: 600px;
        margin: 0 auto;
        padding-left: 16px;
        padding-right: 16px;
    }

    .stat-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1024px) {
    .content {
        max-width: 800px;
    }
}
