/* base.css: the editor's settings and its small parts, used by every page of the editor (the sign-in page too).
   Settings first: every colour, size and timing of the editor is a variable here, and the other stylesheets
   (shell.css, diagram.css, assistant.css, sql.css) only use them. The code box reads its colours from these lines
   too (theme.js), so a colour it reads is written #rrggbb.
   Then the parts every screen is made of, each designed for all its states: buttons, fields, list rows, menus and
   the small questions that float at a row, tooltips, the toast, scrollbars, the focus ring.
   Where things stand on the screen is shell.css's job, not this file's.

   Contents, in order (search for a heading to jump to it):
     ---------- settings: change the look here ----------
     ---------- the font ----------
     ---------- the page ----------
     ---------- buttons ----------
     ---------- fields ----------
     ---------- rows ----------
     ---------- menus and popovers ----------
     ---------- tooltips ----------
     ---------- the toast ----------
     ---------- the spinner ----------
     ---------- scrollbars ----------
     ---------- touch ----------
     ---------- less motion ---------- */

/* ---------- settings: change the look here ---------- */

:root {
    /* Colours. The apps' ui.css uses the same names for the same things. */
    --ink: #1d1d1f;              /* text */
    --ink-2: #6e6e73;            /* secondary text, icons, labels */
    --ink-3: #a1a1a6;            /* faint text: file extensions, line numbers, empty states */
    --paper: #ffffff;            /* the code and everything that floats */
    --side: #f5f5f7;             /* the side panels, the tab strip, the sign-in page */
    --wash: #f0f0f2;             /* fields and quiet fills */
    --field-side: rgba(0, 0, 0, .05);  /* a field on --side (the left panel's search): a little darker than it */
    --hover: rgba(0, 0, 0, .045);    /* behind a row or button under the pointer */
    --pressed: rgba(0, 0, 0, .08);   /* behind a pressed button, and the selected row */
    --line: #e3e3e6;             /* hairlines between things */
    --line-strong: #d2d2d7;      /* a hairline that must show on --side */
    --blue: #0a66d8;             /* the one accent: the main button, a shown panel, matches, links */
    --blue-wash: #e6effc;        /* light --blue: the selection in the code, a match, the row with keyboard focus */
    --on-accent: #fff;           /* text and icons on --blue, --red and the dark tooltip and toast */
    --on-accent-faint: rgba(255, 255, 255, .7);  /* quieter text there: a menu item's keys */
    --ring: rgba(10, 102, 216, .28);   /* the focus ring: --blue, faint */
    --selection: #c4dbf6;              /* selected text in a field: --blue, light */
    --red: #c62828;              /* errors, Delete */
    --red-wash: #fdeaea;
    --green: #1a7f37;            /* an added file (A) */
    --green-wash: #e6f4ea;
    --amber: #9a6700;            /* a changed file (M) */
    --amber-wash: #fff4d6;
    --tip: rgba(29, 29, 31, .92);      /* behind a tooltip and the toast: --ink, nearly solid */
    --scrim: rgba(0, 0, 0, .28);       /* over the page behind the phone's drawer */
    --thumb: rgba(0, 0, 0, .18);       /* a scrollbar */
    --thumb-hover: rgba(0, 0, 0, .32);

    /* The code's colours (Xcode's light theme). theme.js builds the code box's theme from these. */
    --code-current-line: #f7f7f8;   /* behind the line the cursor is on: barely there */
    --code-comment: #707f8c;
    --code-string: #c41a16;
    --code-keyword: #9b2393;
    --code-number: #1c00cf;
    --code-variable: #0f68a0;       /* PHP's $names */
    --code-function: #326d74;
    --code-tag: #9b2393;            /* <div>, and PHP's <?php ?> */
    --code-attribute: #815f03;      /* class="", and CSS properties */
    --code-constant: #5c2699;       /* true, null, NAMES_IN_CAPITALS */
    --code-find: #fde49c;           /* the match Find is on */
    --code-find-other: #fff4d6;     /* Find's other matches */

    /* Text */
    --text: 13px;                /* the interface */
    --text-small: 12px;          /* the status line, labels over fields */
    --text-tiny: 11px;           /* change letters, counts */
    --text-code: 13px;           /* the code */
    --leading-code: 20px;        /* the code's line height */
    --font: "Plex Arabic", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
    --font-code: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", "Plex Arabic", monospace;

    /* Corners */
    --radius: 6px;               /* buttons, fields, rows */
    --radius-large: 10px;        /* menus, popovers, the palette */

    /* Sizes */
    --bar: 44px;                 /* the top bar */
    --strip: 36px;               /* the tab strip, and every panel's header (always the same height) */
    --row: 26px;                 /* a row in a list: the tree, search results, menus */
    --status: 26px;              /* the status line */
    --button: 28px;              /* an icon button, a field, the main button */
    --gutter: 8px;               /* between a list's rows and the panel's edges */
    --indent: 14px;              /* one level deeper in the tree */
    --left: 260px;               /* the left panel's starting width (resized: 200 to 420) */
    --right: 400px;              /* the right panel's starting width (resized: 320 to 680) */
    --drawer: min(86vw, 340px);  /* the left panel on a phone, a drawer */
    --palette: 560px;            /* Go to file */
    --shadow-float: 0 0 0 .5px rgba(0, 0, 0, .14), 0 10px 30px rgba(0, 0, 0, .14);   /* only on what floats */

    /* Motion */
    --fast: 120ms;               /* a chevron turning, a menu appearing */
    --slow: 220ms;               /* a panel sliding */
    --ease: cubic-bezier(.2, .8, .2, 1);
}

/* ---------- the font ----------
   IBM Plex Sans Arabic, shipped with the editor, for Arabic letters only (unicode-range): Latin text stays in the
   system font, and Arabic never falls back to whatever the computer happens to have. */

@font-face {
    font-family: "Plex Arabic";
    src: url("../fonts/IBMPlexSansArabic-Regular.ttf") format("truetype");
    font-weight: 400;
    font-display: swap;
    unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}

@font-face {
    font-family: "Plex Arabic";
    src: url("../fonts/IBMPlexSansArabic-Bold.ttf") format("truetype");
    font-weight: 700;
    font-display: swap;
    unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}

/* ---------- the page ---------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: var(--text);
    line-height: 1.4;
    color: var(--ink);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
    letter-spacing: inherit;
}

a {
    color: var(--blue);
    text-decoration: none;
}

[hidden] {
    display: none !important;
}

/* One focus ring for everything reached by the keyboard; the browser's own outline never shows. */
:focus {
    outline: none;
}

:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ring);
}

/* Selected text, in fields and on the page: a light --blue, as the system draws it */
::selection {
    background: var(--selection);
}

/* Numbers that line up: line numbers, counts, Ln and Col */
.tabular {
    font-variant-numeric: tabular-nums;
}

/* Words read aloud by a screen reader, not shown */
.unseen {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Every icon comes from icons.js: 16 by 16, drawn in the text's colour. Written svg.icon: Monaco has elements
   of its own called "icon". */
svg.icon {
    display: block;
    flex: none;
    width: 16px;
    height: 16px;
}

/* ---------- buttons ----------
   Three kinds. An icon button (28 square). A quiet text button (26 high). The main button (blue), at most one on a
   surface. All three: the pointer over it darkens it a little, pressing it more, and a disabled one fades. */

.icon-button,
.text-button,
.button-main {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    margin: 0;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
    white-space: nowrap;
    transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}

.icon-button {
    position: relative;
    width: var(--button);
    height: var(--button);
    padding: 0;
    color: var(--ink-2);
}

.text-button {
    height: 26px;
    padding: 0 10px;
    gap: 4px;
    color: var(--ink-2);
}

.icon-button:hover,
.text-button:hover {
    background: var(--hover);
    color: var(--ink);
}

.icon-button:active,
.text-button:active,
.icon-button[aria-expanded="true"],
.text-button[aria-expanded="true"] {
    background: var(--pressed);
    color: var(--ink);
}

/* On: a shown panel, the active pane */
.icon-button.on,
.icon-button[aria-pressed="true"],
.text-button[aria-pressed="true"] {
    color: var(--blue);
}

.button-main {
    height: var(--button);
    padding: 0 14px;
    background: var(--blue);
    color: var(--on-accent);
    font-weight: 500;
}

.button-main:hover {
    background: color-mix(in srgb, var(--blue) 90%, #000);
}

.button-main:active {
    background: color-mix(in srgb, var(--blue) 80%, #000);
}

/* A button that does something that cannot be taken back: Delete, Revert all */
.text-button.danger {
    color: var(--red);
}

.text-button.danger:hover {
    background: var(--red-wash);
    color: var(--red);
}

.button-main.danger {
    background: var(--red);
}

.button-main.danger:hover {
    background: color-mix(in srgb, var(--red) 90%, #000);
}

.icon-button:disabled,
.text-button:disabled,
.button-main:disabled {
    opacity: .4;
    pointer-events: none;
}

/* ---------- fields ----------
   28 high, a quiet fill and no border; focused, the fill turns white and the ring shows.
   .text-field is one field on its own; .field is a label above its field (the sign-in page).
   The parts' class names are a little longer than they could be (text-button, text-field, list-empty…) because
   Monaco's popups use the short ones (button, input, empty) for elements of their own. */

.text-field,
label.field input {
    display: block;
    width: 100%;
    height: var(--button);
    margin: 0;
    padding: 0 9px;
    border: 0;
    border-radius: var(--radius);
    background: var(--wash);
    color: var(--ink);
    transition: background-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}

.text-field::placeholder,
label.field input::placeholder {
    color: var(--ink-3);
    opacity: 1;
}

.text-field:focus,
label.field input:focus {
    background: var(--paper);
    box-shadow: 0 0 0 3px var(--ring);
}

/* The browser's own decorations on a search field and a password field: none */
.text-field::-webkit-search-decoration,
.text-field::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}

label.field {
    display: block;
}

.field-label {
    display: block;
    margin-bottom: 5px;
    font-size: var(--text-small);
    color: var(--ink-2);
}

/* ---------- rows ----------
   A row in a list (the tree, search results, changes): --row high, rounded, inside an 8px gutter. The selected
   row is darker; the row the keyboard is on, while its list has the focus, is light blue. A list takes the focus
   as a whole (tabindex on the list) and moves its light-blue row with the arrow keys, so no ring is drawn
   around it. */

.list {
    padding: 4px 0 var(--gutter);
}

.list:focus-visible {
    box-shadow: none;
}

/* The words in a row, whatever their size, stand on one baseline; icons and buttons are centred */
.row {
    display: flex;
    align-items: baseline;
    height: var(--row);
    line-height: var(--row);
    margin: 0 var(--gutter);
    padding: 0 8px;
    border-radius: var(--radius);
    color: var(--ink);
    white-space: nowrap;
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
}

.row > .icon,
.row > button,
.row > input {
    align-self: center;
}

.row:hover {
    background: var(--hover);
}

.row.selected {
    background: var(--pressed);
}

.list:focus .row.current {
    background: var(--blue-wash);
}

/* A row's words: cut with … when the panel is narrow */
.row-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* The letter at a changed file's right edge: M changed, A added, D deleted */
.change-letter {
    flex: none;
    width: 14px;
    margin-left: auto;
    font-size: var(--text-tiny);
    font-weight: 500;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.change-letter-M {
    color: var(--amber);
}

.change-letter-A {
    color: var(--green);
}

.change-letter-D {
    color: var(--red);
}

/* A list with nothing in it: one or two faint words in the middle (No results, No changes) */
.list-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 120px;
    padding: 24px;
    color: var(--ink-3);
    text-align: center;
    user-select: none;
    -webkit-user-select: none;
}

/* What went wrong instead of a list (Not a valid pattern) */
.list-empty.error {
    color: var(--red);
}

/* ---------- menus and popovers ----------
   Both float over the page on --paper with the one shadow. A menu is a list of commands, each with its shortcut
   at the right; a popover asks one short question at the row it is about (Delete vendor.php? Cancel / Delete).
   They appear with a short fade and grow from .98; Escape, a click elsewhere or leaving the window closes them
   (menu.js). */

.menu,
.popover {
    position: fixed;
    z-index: 50;
    background: var(--paper);
    border-radius: var(--radius-large);
    box-shadow: var(--shadow-float);
    animation: float-in var(--fast) var(--ease);
}

.menu {
    min-width: 180px;
    max-width: 320px;
    padding: 4px;
}

@keyframes float-in {
    from {
        opacity: 0;
        transform: scale(.98);
    }
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    height: var(--row);
    margin: 0;
    padding: 0 10px;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink);
    text-align: left;
    white-space: nowrap;
    cursor: default;
}

.menu-item:hover,
.menu-item:focus-visible {
    background: var(--blue);
    color: var(--on-accent);
    box-shadow: none;
}

.menu-item.danger {
    color: var(--red);
}

.menu-item.danger:hover,
.menu-item.danger:focus-visible {
    background: var(--red);
    color: var(--on-accent);
}

.menu-item:disabled {
    color: var(--ink-3);
    background: transparent;
}

/* The chosen one of several (a model): a check before it; the others keep the room so the words line up */
.menu-check {
    width: 16px;
    color: inherit;
}

.menu-keys {
    margin-left: auto;
    padding-left: 24px;
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
}

.menu-item:hover .menu-keys,
.menu-item:focus-visible .menu-keys {
    color: var(--on-accent-faint);
}

/* Words in a menu that are not a command: the signed-in name */
.menu-note {
    padding: 4px 10px 6px;
    color: var(--ink-2);
    font-size: var(--text-small);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu-line {
    height: 1px;
    margin: 4px 10px;
    background: var(--line);
}

.popover {
    width: max-content;
    max-width: min(320px, calc(100vw - 24px));
    padding: 12px;
}

.popover-words {
    margin: 0 2px 12px;
    color: var(--ink);
    overflow-wrap: anywhere;
}

.popover-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

/* A choice set apart from the others, at the left: Don't save */
.popover-buttons .apart {
    margin-right: auto;
}

/* A refusal said where it happened (Already exists): a small note under the field or row */
.refusal {
    position: fixed;
    z-index: 50;
    max-width: 280px;
    padding: 5px 9px;
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: var(--shadow-float);
    color: var(--red);
    font-size: var(--text-small);
    line-height: 16px;
    animation: float-in var(--fast) var(--ease);
}

/* ---------- tooltips ----------
   Our own, never the browser's (no title attributes): after half a second under the pointer, the control's word
   and its shortcut in a fainter white (menu.js). */

.tip {
    position: fixed;
    z-index: 60;
    display: flex;
    gap: 6px;
    padding: 4px 7px;
    border-radius: 5px;
    background: var(--tip);
    color: var(--on-accent);
    font-size: 11.5px;
    line-height: 15px;
    white-space: nowrap;
    pointer-events: none;
    animation: tip-in var(--fast) var(--ease);
}

@keyframes tip-in {
    from {
        opacity: 0;
    }
}

.tip-keys {
    color: rgba(255, 255, 255, .55);
    font-variant-numeric: tabular-nums;
}

/* ---------- the toast ----------
   One at a time, at the bottom of the code column, gone after five seconds; an optional word to take the last
   action back (Undo). */

.toast {
    position: absolute;
    z-index: 40;
    left: 50%;
    bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: calc(100% - 32px);
    min-height: 34px;
    padding: 0 6px 0 14px;
    border-radius: 8px;
    background: var(--tip);
    color: var(--on-accent);
    box-shadow: var(--shadow-float);
    transform: translateX(-50%);
    animation: toast-in var(--slow) var(--ease);
}

.toast:not(:has(.toast-action)) {
    padding-right: 14px;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translate(-50%, 6px);
    }
}

.toast-words {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toast-action {
    height: 24px;
    padding: 0 8px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #8ab8ff;
    font-weight: 500;
}

.toast-action:hover {
    background: rgba(255, 255, 255, .12);
}

/* ---------- the spinner ----------
   Something is on its way (an answer, a query): a small turning ring, the same wherever it is used. */

.spinner {
    display: inline-block;
    flex: none;
    width: 12px;
    height: 12px;
    border: 1.5px solid var(--line-strong);
    border-top-color: var(--ink-2);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

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

/* ---------- scrollbars ----------
   10px, a rounded thumb with a 2px clear edge, no track. */

* {
    scrollbar-width: thin;
    scrollbar-color: var(--thumb) transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track,
::-webkit-scrollbar-corner {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    border: 2px solid transparent;
    border-radius: 5px;
    background: var(--thumb) padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--thumb-hover) padding-box;
}

/* Where a scrollbar is defined the WebKit way, the standard properties would replace it in Chromium */
@supports selector(::-webkit-scrollbar) {
    * {
        scrollbar-width: auto;
        scrollbar-color: auto;
    }
}

/* ---------- touch ----------
   A finger needs more room than a pointer: rows 40px, icon buttons 36px; and fields at 16px, or iOS zooms in. */

@media (pointer: coarse) {
    :root {
        --row: 40px;
        --button: 36px;
    }

    .text-button {
        height: 36px;
    }

    .text-field,
    label.field input {
        height: 40px;
        font-size: 16px;
    }

    .menu-item {
        height: 40px;
    }

    .menu-keys {
        display: none;
    }
}

/* ---------- less motion ----------
   Asked for by the computer's settings: nothing moves, things simply appear. */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        transition-duration: 1ms !important;
    }

    /* an endless turn at 1ms would flicker: the ring stands still instead */
    .spinner {
        animation: none !important;
    }
}
